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 test integration (GHC 9.4.5) #411

Open
benjaminweb opened this issue Aug 10, 2023 · 7 comments
Open

cabal test integration (GHC 9.4.5) #411

benjaminweb opened this issue Aug 10, 2023 · 7 comments

Comments

@benjaminweb
Copy link

Objective: How to let doctest run with cabal test?
(I've spent considerable time to learn that I need to call cabal repl --with-ghc=doctest.)

Ideal outcome: README of doctest shows example of doctest integration in package.yaml or cabal file.

Steps to reproduce:

  • checkout repo [1].
  • run cabal test
> cabal test
Resolving dependencies...
Build profile: -w ghc-9.4.5 -O1
In order, the following will be built (use -v for more details):
 - dtest-0.1 (lib) (configuration changed)
 - dtest-0.1 (test:doctest) (dependency rebuilt)
Configuring library for dtest-0.1..
Preprocessing library for dtest-0.1..
Building library for dtest-0.1..
Preprocessing test suite 'doctest' for dtest-0.1..
Building test suite 'doctest' for dtest-0.1..
Running 1 test suites...
Test suite doctest: RUNNING...
src/Lib.hs:4: failure in expression `import qualified Data.HashMap.Strict as HM'
expected:
 but got:
          ^
          <no location info>: error:
              Could not find module ‘Data.HashMap.Strict’
              Perhaps you meant
                Data.Map.Strict (from containers-0.6.7)
                Data.IntMap.Strict (from containers-0.6.7)

Examples: 1  Tried: 1  Errors: 0  Failures: 1


Test suite doctest: FAIL
Test suite logged to:
/Users/benjamin/repos/dtest/dist-newstyle/build/aarch64-osx/ghc-9.4.5/dtest-0.1/t/doctest/test/dtest-0.1-doctest.log
0 of 1 test suites (0 of 1 test cases) passed.
Error: cabal: Tests failed for test:doctest from dtest-0.1.

Expected behaviour:

> cabal repl --with-ghc=doctest
Resolving dependencies...
Build profile: -w ghc-9.4.5 -O1
In order, the following will be built (use -v for more details):
 - dtest-0.1 (lib) (configuration changed)
Configuring library for dtest-0.1..
Preprocessing library for dtest-0.1..
Examples: 1  Tried: 1  Errors: 0  Failures: 0

[1] https://github.com/benjaminweb/doctest-cabal-integration
@sol
Copy link
Owner

sol commented Aug 10, 2023

I've spent considerable time to learn that I need to call cabal repl --with-ghc=doctest.

I think it's documented in the README. I'm not sure what else to do here, but I'm open to suggestions.

Ideal outcome: README of doctest shows example of doctest integration in package.yaml or cabal file.

The recommended way to run doctest is via cabal repl, so this is probably not going to happen.

However, as I mentioned before cabal exec cabal test should probably work for your example repo. Did you give it a try?

@benjaminweb
Copy link
Author

benjaminweb commented Aug 10, 2023 via email

@andreasabel
Copy link
Collaborator

@benjaminweb wrote:

Just to confirm: There is no and there will be no cabal integration of doctest?

You can try https://github.com/haskellari/cabal-doctest .

@benjaminweb
Copy link
Author

@sol cabal run cabal test does not work for me. OverloadedStrings for example don't work.
cabal repl --with-ghc=doctest takes 10 secs for 83 rather simple doctests.
How can I speed this up for use with a filewatcher?

@benjaminweb
Copy link
Author

@andreasabel got cabal-test now working (it is fast compared to cabal repl --with-ghc=doctest).
Minimum working example: benjaminweb/doctest-cabal-integration@2d781f7
I've found the README frustrating, though. Adopting the simple-example was the only option that worked.

@andreasabel
Copy link
Collaborator

I've found the README frustrating, though. Adopting the simple-example was the only option that worked.

Yeah, I also just did cut-and-paste to get it working.
However, I didn't like to have a custom Setup.hs that is only needed for tests, possibly complicating installation for the regular users.
Thus, I now follow the cabal repl -w doctest path. This has the drawback that it needs custom CI, while I would love to just write cabal test.

@benjaminweb
Copy link
Author

benjaminweb commented Nov 10, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants