doctest icon indicating copy to clipboard operation
doctest copied to clipboard

doctest is broken with ghc 8.8.1/cabal 3.0 (?)

Open googleson78 opened this issue 6 years ago • 5 comments

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:

  1. Have cabal 3.0 + ghc 8.8.1
  2. git clone [email protected]:isovector/type-errors.git
  3. git checkout f171628f607d83de18bd96c1d4247674fece6b15 (current master)
  4. 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.

googleson78 avatar Oct 21 '19 18:10 googleson78

For whatever it is worth, I'm also seeing these failures with cabal 3.0 and ghc 8.6.5

travitch avatar Nov 13 '19 07:11 travitch

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.

quasicomputational avatar Nov 25 '19 07:11 quasicomputational

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 avatar Feb 07 '20 00:02 travitch

@travitch, thanks for that. Some more notes:

  • you can put write-ghc-environment-files: always in your project's cabal.project file
  • 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.

simonmichael avatar Mar 07 '20 02:03 simonmichael

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.

TomMD avatar Mar 25 '20 00:03 TomMD