I’ve been fighting with Cabal for a good portion of a day trying to make its automated testing features work with HUnit. I’ve read the documentation here and here, and I have my Test-Suite section set up like it shows, but whenever I try and build the package using cabal build Cabal says that the only Test-Suite type supported is exitcode-stdio-1.0. What gives?
I’ve been fighting with Cabal for a good portion of a day trying to
Share
Background
So here’s the deal, the documentation on the cabal site is “future documentation,” that is, not all of those features are implemented and released yet. Cabal-install 0.14.0 comes with the
detailed-0.9interface, which is a version behind what’s specified in the docs (detailed-1.0), but I haven’t encountered any problems related to this yet. If you have the Haskell Platform version 2011.4 which comes with cabal-install 0.10.2 you won’t be able to use thedetailed-0.9interface. You’ll need to upgrade to Haskell Platform 2012.2 which comes with cabal-install 0.14.0. You could also just upgrade cabal-install separately, which is what I did because on Fedora 17 the Haskell Platform is only on 2011.4.Installation
In the documentation here you’ll see an example of how to use the
detailed-0.9interface with QuickCheck. It mentions some packages that have interfaces to HUnit, QuickCheck1, and QuickCheck2, but only the package for QuickCheck2 is available on hackage. If you want the packages for the rest of the frameworks you’ll need to use darcs (a VCS) to download them from this location. The command you want to run for the HUnit interface is this:darcs get http://community.haskell.org/~ttuegel/cabal-test-hunit/. You may have to adjust the .cabal file in order to get it to build, specifically it relies onghc 3.*andcabal 1.10. I changed this to my versions (ghc 4.*andcabal 1.14) and it built fine.Testing
Once you have the interface built you need to do some stuff in your test module so Cabal can run it. Specifically you’ll need to import both
Distribution.TestSuiteandDistribution.TestSuite.HUnit. After that you’ll need to convert your HUnit Tests to Cabal Tests, using a function provided in the HUnit interface. Here’s the relevant lines of code:That’s it! You should be able to run
cabal configure --enable-tests && cabal build && cabal testand see your unit tests pass (or fail).Edit
Edited to clarify that the
detailed-0.9interface is included in cabal-install 0.14.0, notdetailed-1.0.