Cabal: should the test suite depend on the library?
I’m writing this because I tend to forget the the tradeoffs.
Ok, suppose you are writing a test suite for a library. How to make the modules in your library accessible to the functions in your test suite? You have two options:
- Add the source files of your library to the hs-source-dirs section of the test suite.
- Add the library to the build-depends section of the test suite.
The hs-source-dirs route has two main disadvantages:
- You’ll compile stuff twice.
- You also need to duplicate the dependencies of your library into the build-depends of the test suite.
Adding your library directly to build-depends is not a panacea, either:
- If you want to test internal modules of the library, you’ll have to make them public so the test suite can see them.
- You may want to treat the library sources and the tests as an unified whole, for the purposes of repl-driven development. For example, you might want to have ghcid compiling your library and running tests in the background, being aware of changes in both the library and the tests.
So pick your poison.
Apparently, incoming Cabal version 1.26 will offer a new option to organize stuff called “convenience libraries”.
Some links about the subject: