[Haskell-cafe] Cabal package with library and tests

Sean Leather leather at cs.uu.nl
Wed Oct 15 16:24:57 EDT 2008

> I'm writing a Cabal package, using main=defaultMain
> in Setup.hs. It has a library, and I want to also
> build a few executables so I can test the library.
> How am I supposed to do that? My attempt was to
> create 'executable' sections for those tests. However,
> I don't know how to include the main library in the
> modules used by those tests. I tried to insert my
> own package in a 'build-depends' line, but that
> didn't work.

You might consider looking at the EMGM cabal file in the source.


There are some things in there that support building a 'test' executable for
the library. Specifically, the flag "-ftest" builds the executable and
enables its build-depends. Since the 'test' flag is false by default, those
build-depends are not passed onto users who download EMGM from Hackage.

Note that the way it's done, Cabal will build the library and the executable
separately. From what I understand, there's no easy way to have an
executable depend on a library in the same Cabal config file. So, you're
actually building the library twice. We have a "-fnolib" flag for disabling
the library build to speed things up. To get this, you'd use "-ftest

If you want to support the 'test' argument to Cabal (e.g. "runhaskell
Setup.lhs test" or "cabal test" using cabal-install), you can find that code
in the Setup.lhs file from the source link above.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081015/c1509f72/attachment.htm

More information about the Haskell-Cafe mailing list