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?

- 1,239
- 9
- 18
2 Answers
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.9
interface, 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 the detailed-0.9
interface. 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.9
interface 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 on ghc 3.*
and cabal 1.10
. I changed this to my versions (ghc 4.*
and cabal 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.TestSuite
and Distribution.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:
import qualified Distribution.TestSuite as Cabal
import qualified Distribution.TestSuite.HUnit as CabalHUnit
tests = map (\(x,y) -> CabalHUnit.test x y) [("Login tests", loginTests)]
That's it! You should be able to run cabal configure --enable-tests && cabal build && cabal test
and see your unit tests pass (or fail).
Edit
Edited to clarify that the detailed-0.9
interface is included in cabal-install 0.14.0, not detailed-1.0
.

- 5,230
- 5
- 34
- 42

- 1,239
- 9
- 18
-
The solution doesn't work with HP 2012.2. `cabal --version` shows `0.14.0` and `1.14.0` respectively, but `cabal configure --enable-tests` still says "test types are: exitcode-stdio-1.0, detailed-0.9". So the official `1.14.0` is still without `detailed-1.0`. – nponeccop Sep 01 '12 at 19:31
-
@nponeccop I'm sorry my solution was misleading. I've edited it to be more clear. To be clear, the "detailed-1.0" interface is not out yet, so you'll have to use the "detailed-0.9" interface. I have not encountered anything so far that should be in the 1.0 interface and not the 0.9 interface, but YMMV. – Dwilson Sep 03 '12 at 17:15
-
3To anyone arriving here via Google search: please note that a much simpler solution is to use test type `exitcode-stdio-1.0` instead of `detailed`. Here's a working example that combines `exitcode-stdio-1.0` and `HUnit`: https://gist.github.com/23Skidoo/8019225 – Mikhail Glushenkov Dec 18 '13 at 09:32