[Haskell-cafe] how to write cabal package file for executable with unit tests?

Erik Hesselink hesselink at gmail.com
Mon Feb 17 10:07:07 UTC 2014

Hi Richard,

Where is your Parser module located?

Remember that your code will be compiled twice this way. What is, in
my opinion, a better setup, is put the shared code in a library (like
you had), and then have a shallow executable in the same package that
depends on the library. The test-suite can then also depend on the
library. All three should have distinct source dirs.

Having most functionality in a library is a good design principle
anyway: it makes it easier to re-use it in a different way later, and
makes sure you think about API boundaries and such.



On Mon, Feb 17, 2014 at 2:26 AM, Richard Cobbe <cobbe at ccs.neu.edu> wrote:
> On Mon, Feb 17, 2014 at 12:52:41AM +0200, Roman Cheplyaka wrote:
>> If you don't want a separate library, use the second Erik's suggestion
>> from that thread.
> I tried that, and I seem to still be missing something.
> With
>     Test-Suite sample-tests
>       main-is: RunTests.hs
>       hs-source-dirs: test-src, src
>       other-modules: Ast, Parser, Scanner
>       type: exitcode-stdio-1.0
>       default-language: Haskell2010
>       build-depends: base, array, containers, HUnit
> then "cabal configure --enable-tests && cabal build" results in the
> following error:
>     test-src/RunTests.hs:8:8:
>         Could not find module `Parser'
>         It is a member of the hidden package `ghc-7.6.3'.
>         Perhaps you need to add `ghc' to the build-depends in your .cabal file.
>         Use -v to see a list of the files searched for.
> If I remove "src" from the hs-source-dirs line, then cabal complains that
> it can't find source for Ast.
> If I put "src" back and remove the other-modules line, I get the same
> "Could not find module 'Parser'" error message from above.
>                                  * * * * *
> These seem to be pretty basic questions to me, but they also don't seem to
> be in the Cabal manual anywhere.  Is there somewhere else I should be
> looking?
> Richard
>> * Richard Cobbe <cobbe at ccs.neu.edu> [2014-02-16 17:15:25-0500]
>> > What's the preferred way to write a cabal configuration file for a package
>> > that contains an executable and a test suite?  The only thing I've found
>> > that seems to work is to put a thin wrapper Main.hs into the executable,
>> > put all of the actual code into the library, and then have the test-suite
>> > include the library in its build-depends list.
>> >
>> > This works, but I find it mildly annoying that I have to separate the code
>> > out in this fashion -- especially since the unit tests require me to expose
>> > modules in my library that aren't really part of the library's public
>> > interface.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list