Is there any way to replace the long list of build-specific packages for a test suite with "the same as for the executable, as well as QuickCheck"?
Not that I knew. However, there is a way to mention only one list of package-specific packages by structuring your project for three purposes:
- a library that contains all your code and needs a long list, depending on the assembly.
- executable file, which consists of only one file and depends on the base and library on top.
- A test package that depends on the library on top and the test packages you use.
Perhaps this approach is what indygemma offers, but the bondage file proposed there will not achieve this, as Norman Ramsey notes in a comment. Here are the highlights of what you need in the cab file. For a complete example that works for me, you can look at this cabal file .
name: my-program version: ... library hs-source-dirs: src-lib build-depends: base, containers, ... exposed-modules: My.Program.Main, ... executable my-program hs-source-dirs: src-exec main-is: my-program.hs Build-depends: base, my-program test-suite tests type: exitcode-stdio-1.0 hs-source-dirs: src-test main-is: tests.hs other-modules: ... build-depends: base, my-program, test-framework, ...
Important points:
There are three separate source directories for three purposes. This is necessary to stop ghc from recompiling library files while building other targets.
All application code is in the library. The executable file is only a shell, for example:
import My.Program.Main (realMain) main = realMain
The library provides all the modules needed for testing.
The last point emphasizes the drawback of this approach: you need to expose the internal modules. The main advantage of this approach is that you have less duplication in the cabal file and, more importantly, less duplication in the build process: the library code will be created only once, and then it will be associated with both the executable and the test suite.
Toxaris Aug 19 '13 at 9:19 am 2013-08-19 09:19
source share