It seems that there's an undocumented interface into QuickCheck that can be used to sort of integrate it with HUnit -- instead of spewing to standard output for all tests, I got it to only toss exceptions when a test failed or exhausted its argument space (see the attached module, based on the QuickCheck code). However, this is still not ideal; I'd really rather be able to actually write HUnit tests within QuickCheck; e.g.,
prop_Foo x = (0 * x) @?= 0 Since QuickCheck requires you to use pure functions and the signature of @?= is (Eq a, Show a) => a -> a -> IO () this doesn't really work. However, I think it would require a lot more work to get this working with QuickCheck, and I suppose if your properties are simple enough it should be easy to trace failures by hand. Daniel
-- | HUnit <-> QuickCheck binding.
module UnitCheck(
unitCheck
)
where
import Data.List
import System.Random
import Test.HUnit
import Test.QuickCheck
-- Execute checks until we have executed enough. All output is suppressed
-- unless the test returns a "false" value.
runCheck :: Config -> Gen Result -> StdGen -> Int -> Int -> [[String]] -> Assertion
runCheck config gen rnd0 ntest nfail stamps
| ntest == configMaxTest config = return ()
| nfail == configMaxFail config = assertFailure $ "Arguments exhausted after " ++ (show ntest) ++ " tests"
| otherwise =
case ok result of
Nothing ->
runCheck config gen rnd1 ntest (nfail + 1) stamps
Just True ->
runCheck config gen rnd1 (ntest + 1) nfail (stamp result : stamps)
Just False ->
assertFailure $ "Property failed after " ++ (show ntest) ++ " tests, with arguments [" ++ (concat $ intersperse "," $ arguments result) ++ "]"
where
result = generate (configSize config ntest) rnd2 gen
(rnd1, rnd2) = split rnd0
unitCheck :: Test.QuickCheck.Testable a => a -> Assertion
unitCheck a = do rnd <- newStdGen
runCheck defaultConfig (evaluate a) rnd 0 0 []
signature.asc
Description: Digital signature

