<div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I'm writing a Cabal package, using main=defaultMain<br>
in Setup.hs. It has a library, and I want to also<br>
build a few executables so I can test the library.<br>
How am I supposed to do that? My attempt was to<br>
create 'executable' sections for those tests. However,<br>
I don't know how to include the main library in the<br>
modules used by those tests. I tried to insert my<br>
own package in a 'build-depends' line, but that<br>
didn't work.<br></blockquote></div><br>You might consider looking at the EMGM cabal file in the source.<br><br> <a href="https://svn.cs.uu.nl:12443/viewvc/dgp-haskell/EMGM/">https://svn.cs.uu.nl:12443/viewvc/dgp-haskell/EMGM/</a><br>
<br>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.<br>
<br>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".<br>
<br>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.<br>
<br>Sean<br></div>