Closed gdetrez closed 3 years ago
I'd assumed that adding -idist/build/autogen
is all that is needed. Can you give a minimal example that reproduces the issue?
Here it is foo-0.1.0.0.tar.gz.zip (zipped because github...). If I extract the attached package and then run cabal test
in in, it works fine. (It even works if I omit the -idist/build/autogen
).
But if I try to do cabal install --run-tests foo-0.1.0.0.tar.gz
(I used a sandbox) then it prints the following error:
Test suite bnfc-doctests: RUNNING...
main.hs:2:8:
Could not find module ‘Paths_foo’
Use -v to see a list of the files searched for.
Test suite bnfc-doctests: FAIL
Test suite logged to:
dist/dist-sandbox-160c6e72/test/foo-0.1.0.0-bnfc-doctests.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Error: some packages failed to install:
foo-0.1.0.0 failed during the tests phase. The exception was:
ExitFailure 1
The reason for this is that cabal uses a different directory layout in that case. I'm not sure what the right way is to address this. Possibly report as a cabal
issue...
I have the same problem. My test suite calls
doctest [ "-isrc", "-optP-include", "-optPdist/build/autogen/cabal_macros.h", "src" ]
to make cabal_macros.h
available for the build. This works fine with cabal test
, but stack test
puts the dist
directory at a different location, now, I need to use
"-optP-include", "-optP.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen/cabal_macros.h"
instead to make it work, which is obviously not a viable solution.
@peti The easiest way to fix this with stack
may be to implement a stack doctest
command that calls doctest
with the right arguments.
/cc @mgsloan
@peti also see https://github.com/commercialhaskell/stack/pull/524
Well, right now doctest
is part of my normal hspec
test suite; it's run as part of cabal test
. I suppose that trait would be lost if we depend on specific sub-command to stack
?
Maybe it's possible to modify stack
so that it provides the path to the dist/
directory in an environment variable which the test suite can read?
@peti Yes, exactly, have a look at the related stack issue from my previous comment.
Just saw it! Very nice. Thanks for the pointer!
Does Cabal define HASKELL_DIST_DIR so we can use the same on both? Argh, that's an open issue: haskell/cabal#3483.
I switched from @gdetrez approach to using https://github.com/haskellari/cabal-doctest, which works with both v1- and v2-cabal. Assuming cabal-doctest
is here to stay, this would fix the present issue.
Strictly speaking, cabal-doctest
is a hack, but it has the high virtue of working very well and I do endorse it. The ideal solution will involve upstream changes to Cabal and declarative specification of doctests in the .cabal
file, which will hopefully happen someday. On the basis that this can be made to work today, I'm going to close this issue.
I use doctest in a test-suite, set-up in cabal like this:
I added
-idist/build/autogen
to doctest so I can run the test usingcabal test
without problem but if I create a sdist package and try to install it withcabal install --run-tests
, I get the following issue:I tried adding
Other-modules Paths_BNFC
but it doesn't help. Is there a way to make it work?