doctest is broken with ghc 8.8.1/cabal 3.0 (?)
There seems to be some difference in behaviour, perhaps what environment is sought for packages?? I honestly have no idea.
I am asking here in case someone is aware of such a (potential) problem.
Repro:
- Have cabal 3.0 + ghc 8.8.1
git clone [email protected]:isovector/type-errors.gitgit checkout f171628f607d83de18bd96c1d4247674fece6b15(current master)cabal v2-test
Output
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
- type-errors-0.2.0.0 (test:test) (first run)
Preprocessing test suite 'test' for type-errors-0.2.0.0..
Building test suite 'test' for type-errors-0.2.0.0..
Running 1 test suites...
Test suite test: RUNNING...
test: <command line>: cannot satisfy -package first-class-families
(use -v for more information)
Test suite test: FAIL
Test suite logged to:
/home/googleson78/git/type-errors/dist-newstyle/build/x86_64-linux/ghc-8.8.1/type-errors-0.2.0.0/t/test/test/type-errors-0.2.0.0-test.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:test from type-errors-0.2.0.0.
For whatever it is worth, I'm also seeing these failures with cabal 3.0 and ghc 8.6.5
Yeah, doctest itself doesn't know about where various build tools put package databases - it punts to GHC, which in turn checks some environment variables. The best solution for now would be asking upstream to use cabal-doctest, which is a hack that does the necessary wiring-up in a build-tool-independent manner; a cabal-install solution is to use cabal v2-exec to invoke doctest, which sets the appropriate environment variables.
A coworker clued me in to my problem: cabal 3.0 no longer creates the GHC environment files by default (cabal 2.0 did). If I build my project with --write-ghc-environment-files=always, my doctests are able to find the packages they import. I ended up putting this in my ~/.cabal/config to set it globally.
@travitch, thanks for that. Some more notes:
- you can put
write-ghc-environment-files: alwaysin your project'scabal.projectfile - cabal 2 won't understand that, but it's just a warning so shouldn't stop it
- cabal 3 will generate the .ghc.environment* file, but the first run of a doctest suite will still fail; the second run will succeed. Hopefully in practice cabal build will generate the file in time for the test suite.
Using ghc environment files is a good way to get further. It results in doctest knowing where to find the packages. We still need doctest to only use the packages of interest for a given build unit or else it has trouble with duplicate modules.
As an example, this problem is observable when you have crypto-api and cryptonite installed then import Crypto.Random.