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?
相关问题
- Dependencies while implementing Mocking in Junit4
- How to unit test a reactive component where ngCont
- Understanding do notation for simple Reader monad:
- Making Custom Instances of PersistBackend
- Haskell: What is the differrence between `Num [a]
相关文章
- How to replace file-access references for a module
- Is it possible to write pattern-matched functions
- How to mock methods return object with deleted cop
- What is a good way of cleaning up after a unit tes
-
EF6 DbSet
returns null in Moq - Haskell underscore vs. explicit variable
- Top-level expression evaluation at compile time
- Stuck in the State Monad
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 thedetailed-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 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.TestSuite
andDistribution.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 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, notdetailed-1.0
.Although Dwilson's answer is good,
detailed
is currently not well supported. You can intergrateHUnit
withcabal
usingexitcode-stdio-1.0
andTest.Framework
.It will output all successful and failed tests to
stdout
as well as fail building if tests fail. See my gist.