[Haskell-cafe] how to write cabal package file for executable with unit tests?
Roman Cheplyaka
roma at ro-che.info
Sun Feb 16 22:52:41 UTC 2014
If you don't want a separate library, use the second Erik's suggestion
from that thread.
* 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.
>
> In more detail:
>
> This is a follow-up to a thread I posted back on Feb 2; you can see it on
> GMane at <http://thread.gmane.org/gmane.comp.lang.haskell.cafe/109374>.
> The original example (tarball attached to the first message in that thread)
> was a package structured as a library with unit tests. After acting on
> Erik's suggestion to put the library and test-suite source in different
> directories, I was able to compile the library without the type error I
> originally mentioned.
>
> However, this isn't really the package structure I want. The package is
> actually intended to produce a standalone executable, not a library. My
> original example used a library for reasons that I don't honestly remember
> -- I think I more or less stumbled upon that structure as something that
> more or less worked, given the difficulty of getting Cabal, test suites,
> Happy, and Alex to all work together well.
>
> So I tried replacing the "Library" section of the cabal file with an
> "Executable" section (sample tarball attached), but then I can't get the
> tests to compile. If I leave sample as a build-depends for the test-suite,
> then "cabal configure --enable-tests" fails with
>
> Preprocessing test suite 'sample-tests' for sample-0.4...
> <command line>: cannot satisfy -package-id sample-0.4-inplace
> (use -v for more information)
>
> If I take sample out of the build-depends list for the test-suite, then
> "cabal configure --enable-tests" works, but "cabal build" fails:
>
> 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.
>
> Either way, "cabal configure && cabal build" works fine; it's only when I
> try to build the test suite that things break down.
>
> Thanks,
>
> Richard
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140217/f36809c4/attachment.sig>
More information about the Haskell-Cafe
mailing list