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

Richard Cobbe cobbe at ccs.neu.edu
Mon Feb 17 01:26:18 UTC 2014


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.



More information about the Haskell-Cafe mailing list