doctest icon indicating copy to clipboard operation
doctest copied to clipboard

cabal repl --enable-multi-repl --with-ghc=doctest fails with "unrecognized option `-unit'"

Open TristanCacqueray opened this issue 2 years ago • 4 comments

The upcoming cabal 3.11 release support loading multiple components (see https://github.com/haskell/cabal/pull/8726). However this does not seems to work when running doctest through ghc replacement. Here is an example failure for a package using two libraries:

$ cabal repl --enable-multi-repl --with-ghc=doctest butler butler-desktop

Resolving dependencies...
Build profile: -w ghc-9.6.2 -O1
In order, the following will be built (use -v for more details):
 - butler-0.1 (interactive) (lib) (first run)
 - butler-0.1 (interactive) (lib:butler-desktop) (configuration changed)
Preprocessing library for butler-0.1...
Configuring library 'butler-desktop' for butler-0.1...
Preprocessing library 'butler-desktop' for butler-0.1...
doctest: unrecognized option `-unit'
Try `doctest --help' for more information.

Could we make this work?

TristanCacqueray avatar Aug 20 '23 16:08 TristanCacqueray

Doctest uses both, the GHC compilation pipeline and GHCi.

  • the GHC compilation pipeline is used for extracting Haddock comments
  • GHCi is used to evaluate examples

If multiple home units are only supported by GHCi, but not by the GHC compilation pipeline, then I think it would be hard to support multiple home units.

Taking a step back, do you think this is crucial? As I understand it, the motivation for multiple home units is to enable :reload to work across multiple units. This is useful for interactive use, but doesn't offer any benefit for Doctest.

@mpickering do you have any input?

sol avatar Sep 07 '23 05:09 sol

It seems like it would be possible to make doctest start a multi unit session if passed -unit arguments. It could be useful if you have doctests in all of your different components.

Multiple home units are supported by the GHC compilation pipeline.

mpickering avatar Sep 07 '23 12:09 mpickering

Thanks @mpickering 🙏

To summarize:

  1. Doctest accepts arbitrary GHC arguments and uses these to:

    (a) initialize a GHC session and extract Haddock comments, and then (b) passes them to GHCi

    Apparently, as of now, doctest fails on --unit while doing (a). If somebody wants to look into this, then the first step would be to figure out what exactly is going on here.

  2. --enable-multi-repl would allow you to run all doctests of a package with a single command. Other than that, i'm not aware of any additional benefits. Iterating through all the units of a package and running Doctest for each unit individually should work equally well.

  3. At least for now, I'm not going to look into this myself, but I'm happy to accept contributions.

sol avatar Sep 08 '23 04:09 sol

possibly related: https://github.com/snoyberg/xml/issues/191 (Setup.hs of that package uses doctest)

jwaldmann avatar Sep 20 '23 10:09 jwaldmann