Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal-3: doctest-discover fails for non-boot libraries #6087

Closed
erikd opened this issue Jun 18, 2019 · 6 comments
Closed

Cabal-3: doctest-discover fails for non-boot libraries #6087

erikd opened this issue Jun 18, 2019 · 6 comments

Comments

@erikd
Copy link
Member

erikd commented Jun 18, 2019

I have a simple cabal file:

name: doctest-depends
version: 0.1
build-type: Simple
cabal-version: >= 1.10

library
  default-language: Haskell2010
  exposed-modules: P
  hs-source-dirs: src
  build-depends: base, base-orphans

test-suite doctest
  main-is: doctest.hs
  type: exitcode-stdio-1.0
  default-language: Haskell2010
  build-depends: base, doctest, base-orphans
  build-tool-depends: doctest-discover:doctest-discover

where the module P.hs defines a doctest

module P where
import Base.Orphans ()
-- >>> square 5
-- 25
-- >>> square 4
-- 16
square ::Int -> Int
square x = x * x

and where doctest.hs consists of:

{-# OPTIONS_GHC -F -pgmF doctest-discover #-}

When running cabal configure --enable-tests && cabal test (using cabal-install v3 from git about a week ago) I get:

Test suite doctest: RUNNING...

cabal-testsuite/PackageTests/Doctest/Depends/src/P.hs:6:1: error:
    Could not find module ‘Base.Orphans’
    Use -v to see a list of the files searched for.
  |
2 | import Base.Orphans ()
  | ^^^^^^^^^^^^^^^^^^^^^^

The above project builds and passes the tests when run with stack.

This is not a problem with doctest-discover because if I remove the base-orphans dependency and remove the Base.Orphans import, the test builds and passes as expected.

It therefore seems that the doctest-discover pre-processor is being executed without access to the package DB.

I would like to get some advice on how to fix this. I am currently looking at Distribution.Simple.Test.ExeV10.runTest and looking to pass the package DB location to the test program there.

@erikd
Copy link
Member Author

erikd commented Jun 19, 2019

This is actually a regression.
Using doctest-discover (cloned from github):

cabal sandbox init
cabal build
cabal install --dependencies-only
cabal test

the tests build and run (with a test failure, but that is irrelevant).

Now with cabal 3.0 (from 2019/06/03):

cabal configure --enable-tests
cabal build
cabal test

results in:

Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - doctest-discover-0.2.0.0 (test:doctests) (ephemeral targets)
Preprocessing test suite 'doctests' for doctest-discover-0.2.0.0..
Building test suite 'doctests' for doctest-discover-0.2.0.0..
Running 1 test suites...
Test suite doctests: RUNNING...

/home/erikd/Git/Haskell/doctest-discover/src/Config.hs:5:1: error:
    Could not find module ‘Data.Aeson’
    Perhaps you meant Data.Version (from base-4.12.0.0)
    Use -v to see a list of the files searched for.
  |
5 | import Data.Aeson ((.:), (.:?), decode, FromJSON(..), Value(..))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Test suite doctests: FAIL
Test suite logged to:
/home/erikd/Git/Haskell/doctest-discover/dist-newstyle/build/x86_64-linux/ghc-8.6.5/doctest-discover-0.2.0.0/t/doctests/test/doctest-discover-0.2.0.0-doctests.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:doctests from doctest-discover-0.2.0.0.

@quasicomputational
Copy link
Contributor

Note that cabal test in 3.0 is the equivalent of cabal v2-test in 2.4. Did cabal v2-test work before? And, conversely, does cabal v1-test work in 3.0?

@erikd
Copy link
Member Author

erikd commented Jun 19, 2019

Also fails on cabal v2-test with cabal 2.4.1.0.

With cabal 3.0, the following works:

cabal v1-sandbox init
cabal v1-install --dependencies-only
cabal v1-configure --enable-tests
cabal v1-test

@junjihashimoto
Copy link

junjihashimoto commented Jul 15, 2019

Maybe this is related.
#4542

So the following command may work.

cabal configure --enable-tests
cabal build --write-ghc-environment-files=always
cabal test --write-ghc-environment-files=always

In my environment, the error is fixed.
hasktorch/ffi-experimental#62

@erikd
Copy link
Member Author

erikd commented Feb 18, 2020

Hmm, -write-ghc-environment-files=always (which i actually added the cabal.project file) fixed this.

@gbaz
Copy link
Collaborator

gbaz commented Sep 17, 2021

closing on that basis.

@gbaz gbaz closed this as completed Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants