hstest

Runs tests via QuickCheck1 and HUnit; like quickCheck-script but uses GHC api http://bitbucket.org/dave4420/hstest/wiki/Home

Latest on Hackage:0.0.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by Dave Hinton
Maintained by Dave Hinton

hstest looks through all Haskell source files in the current directory (by default), runs all properties via QuickCheck 1 (properties must have a name that starts prop_), and runs all tests via HUnit (tests must have a name that starts test_).

For example, suppose you have this Haskell source file called mysort.hs:

mySort xs = ... -- a function you wish to test (definition elided)

prop_lengthStaysTheSame xs = length xs == length (mySort xs)
prop_sumStaysTheSame xs = sum xs == sum (mySort xs)
prop_lowestElementAtStart, prop_highestElementAtEnd :: [Int] -> Bool
prop_lowestElementAtStart xs = not (null xs) ==> minimum xs == head (mySort xs)
prop_highestElementAtEnd xs = not (null xs) ==> maximum xs == last (mySort xs)

Then to check all these tests, you run

$ hstest
Failed prop_highestElementAtEnd:
 *  [-3,2,-2]
mysort.hs: Failed 1 property, passed 3 properties

Oops! Fix mySort and try again:

$ hstest
mysort.hs: Passed 4 properties
comments powered byDisqus