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

Weird test failure due to type error with GHC 9.2.1 #326

Closed
sjakobi opened this issue Nov 22, 2021 · 5 comments
Closed

Weird test failure due to type error with GHC 9.2.1 #326

sjakobi opened this issue Nov 22, 2021 · 5 comments

Comments

@sjakobi
Copy link

sjakobi commented Nov 22, 2021

bsb-http-chunked:test:doctests fails with a weird type error that I can't reproduce with older GHC versions or cabal repl.

Please see sjakobi/bsb-http-chunked#38.

@sol
Copy link
Owner

sol commented Nov 22, 2021

@sjakobi invoking doctest via cabal repl works for me:

$ cabal install doctest --overwrite-policy=always && cabal build && cabal repl --build-depends=QuickCheck --build-depends=template-haskell --with-ghc=doctest
Examples: 5  Tried: 5  Errors: 0  Failures: 0

Starting with doctest-0.20.0 that's how I recommend to use doctest with cabal-v2.

@sol
Copy link
Owner

sol commented Nov 22, 2021

As I describe here sjakobi/bsb-http-chunked#38 (comment), if I invoke ghci the same way as doctest is invoked, I get the same error. So as far as I can tell, this is not a bug (by design, doctest tries to mimic ghci).

I'm closing this, but please don't be shy to open a new issue if you think there is something that we can do in doctest to improve the situation.

@sol sol closed this as completed Nov 22, 2021
@sjakobi
Copy link
Author

sjakobi commented Dec 17, 2021

So as Ryan explains in https://gitlab.haskell.org/ghc/ghc/-/issues/20833#note_398289, the problem seems to be that the doctests invoked via cabal test end up using the default GHC2021 language variant, which leads to the type error in bsb-http-chunked.

To me that seems like a bug somewhere in cabal test or doctest. It's good that the workaround with cabal repl exists, but I hope that doctests will eventually be properly supported in cabal test again.

EDIT: For reference: haskell/cabal#4500 contains some discussion on better doctest support in cabal.

@sol
Copy link
Owner

sol commented Dec 19, 2021

To me that seems like a bug somewhere in cabal test or doctest.

@sjakobi I'm not convinced that this is the case. doctest behaves the same as ghci, which is by design.

cabal test on the other hand merely runs your tests/Doctests.hs. I don't think it is in a position to influence how doctest is invoked.

What I assume is that you just need to pass -XHaskell2010 to doctest. Specifically, change tests/Doctests.hs to:

import Test.DocTest

main :: IO ()
main = doctest ["-isrc", "-XHaskell2010", "Data/ByteString/Builder/HTTP/Chunked.hs"]

(untested)

I still think that with doctest-0.20.0 the most reliabl way to use doctest is via cabal repl. Because this delegates the handling of all the details to cabal. So specifically this should work:

cabal install doctest --overwrite-policy=always && cabal build && cabal repl --build-depends=QuickCheck --build-depends=template-haskell --with-ghc=doctest

sjakobi added a commit to sjakobi/bsb-http-chunked that referenced this issue Dec 19, 2021
sjakobi added a commit to sjakobi/bsb-http-chunked that referenced this issue Dec 19, 2021
@sjakobi
Copy link
Author

sjakobi commented Dec 19, 2021

What I assume is that you just need to pass -XHaskell2010 to doctest.

Thank you, @sol! I had totally forgotten to check how these doctests are invoked.

I still think that with doctest-0.20.0 the most reliabl way to use doctest is via cabal repl.

This is good to know, but I'd really to prefer to be able to run the tests with just cabal test. The main problems I see with the cabal repl command is that I'd need to communicate this with contributors, and I'd also need to customize the CI configs which I usually just generate with haskell-ci.

I'd love to have good support for doctests built into cabal though. Maybe this cabal repl command or something like it can be built into cabal as a part of a new type: doctest test type?!

sjakobi added a commit to sjakobi/bsb-http-chunked that referenced this issue Dec 19, 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

2 participants