<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&#39;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 &#39;executable&#39; sections for those tests. However,<br>
I don&#39;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 &#39;build-depends&#39; line, but that<br>
didn&#39;t work.<br></blockquote></div><br>You might consider looking at the EMGM cabal file in the source.<br><br>&nbsp; <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 &#39;test&#39; executable for the library. Specifically, the flag &quot;-ftest&quot; builds the executable and enables its build-depends. Since the &#39;test&#39; 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&#39;s done, Cabal will build the library and the executable separately. From what I understand, there&#39;s no easy way to have an executable depend on a library in the same Cabal config file. So, you&#39;re actually building the library twice. We have a &quot;-fnolib&quot; flag for disabling the library build to speed things up. To get this, you&#39;d use &quot;-ftest -fnolib&quot;.<br>
<br>If you want to support the &#39;test&#39; argument to Cabal (e.g. &quot;runhaskell Setup.lhs test&quot; or &quot;cabal test&quot; using cabal-install), you can find that code in the Setup.lhs file from the source link above.<br>
<br>Sean<br></div>