2

Is there any way (using stack) to generate Haddock documentation for the test modules?

The command:

stack haddock

will generate documentation for the library modules. I've tried to change some command line options using haddock-arguments without any success.

Even if stack doesn't support this, I'm open to other options.

Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
  • This is definitely entirely a `stack` issue. Haddock isn't supposed to know anything about your project structure (or which modules are test vs. library). – Alec Sep 11 '18 at 20:50

1 Answers1

2

stack exec -- haddock test/**/*.hs -odocs -h

I tested with stack 1.7.1 and haddock 2.20.0.

It's not clear what platform you are on; that will work on zsh on linux. The principle should work on other platforms. It runs haddock on all the .hs files in the test directory and puts the html output (-h) in the docs directory (which it creates, if necessary). It seems to overwrite whatever is in there.

You may wish to raise a feature request on the stack issue tracker, too. It's a good suggestion! And the resulting command would include the correct dependency links, without you having to supply them yourself.

Finally, Cabal, with its new-build options, can apparently do this (I haven't tested it). The haddock-tests: True option would go in the cabal.project file.

David Baynard
  • 236
  • 1
  • 6
  • Thanks David. I have the same versions of `stack` and `haddock` but the solution you proposed didn't work in my case. I get errors about packages not being available, and not finding link destinations for `IO`, `String`, `Int`, etc. Running haddock in this way (without being aware of the project structure) is likely to generate some crippled documentation. However I could try with `cabal` so thanks for the tip! – Damian Nadales Sep 22 '18 at 07:40
  • Unfortunately you do have to supply the interface files if you want the links to work. It's odd that packages aren't available, though. Do the tests build? – David Baynard Sep 22 '18 at 21:41
  • I see that the docs are placed in the `docs` folder despite of the errors. Even the current state of affairs regarding stack and haddock interaction is fair from optimal when it comes to test packages, the solution you provided can be used as a workaround. – Damian Nadales Sep 24 '18 at 08:04
  • 1
    https://github.com/commercialhaskell/stack/issues/729 is tracking this issue. There's another solution there, too involving cabal and stack together, though it may not still work. – David Baynard Sep 24 '18 at 16:53