
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. https://svn.cs.uu.nl:12443/viewvc/dgp-haskell/EMGM/ 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 -fnolib". 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. Sean