sol / doctest

An implementation of Python's doctest for Haskell
https://hackage.haskell.org/package/doctest
MIT License
373 stars 73 forks source link

Can't find module Paths_BNFC when using --run-tests #127

Closed gdetrez closed 3 years ago

gdetrez commented 8 years ago

I use doctest in a test-suite, set-up in cabal like this:

Test-suite bnfc-doctests
    type:           exitcode-stdio-1.0
    ghc-options:    -threaded
    main-is:        doctests.hs
    build-depends:  base, doctest >= 0.8
    HS-source-dirs: test src

I added -idist/build/autogen to doctest so I can run the test using cabal test without problem but if I create a sdist package and try to install it with cabal install --run-tests, I get the following issue:

src/Main.hs:46:8:
    Could not find module ‘Paths_BNFC’
    Use -v to see a list of the files searched for.

I tried adding Other-modules Paths_BNFC but it doesn't help. Is there a way to make it work?

sol commented 8 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?

gdetrez commented 8 years ago

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
sol commented 8 years ago

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...

peti commented 8 years ago

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.

sol commented 8 years ago

@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

sol commented 8 years ago

@peti also see https://github.com/commercialhaskell/stack/pull/524

peti commented 8 years ago

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?

sol commented 8 years ago

@peti Yes, exactly, have a look at the related stack issue from my previous comment.

peti commented 8 years ago

Just saw it! Very nice. Thanks for the pointer!

Blaisorblade commented 8 years ago

Does Cabal define HASKELL_DIST_DIR so we can use the same on both? Argh, that's an open issue: haskell/cabal#3483.

andreasabel commented 3 years ago

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.

quasicomputational commented 3 years ago

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.