4
module Test.QuickCheck,
8
import Test.QuickCheck hiding (check,(==>))
18
constTest :: Bool -> IO ()
19
constTest True = return ()
20
constTest False = error "Failed on constTest"
24
data QFilePath = QFilePath FilePath
27
instance Arbitrary QFilePath where
28
arbitrary = liftM QFilePath arbitrary
29
coarbitrary = undefined
32
instance Arbitrary Char where
33
arbitrary = elements "?|./:\\abcd 123;_"
34
coarbitrary = undefined
38
-- below is mainly stolen from Test.QuickCheck, modified to crash out on failure
40
quickSafe :: Testable a => a -> IO ()
41
quickSafe prop = check quick prop
46
, configMaxFail = 1000
47
, configSize = (+ 3) . (`div` 2)
48
, configEvery = \n args -> let s = show n in s ++ [ '\b' | _ <- s ]
52
check :: Testable a => Config -> a -> IO ()
55
tests config (evaluate a) rnd 0 0 []
58
tests :: Config -> Gen Result -> StdGen -> Int -> Int -> [[String]] -> IO ()
59
tests config gen rnd0 ntest nfail stamps
60
| ntest == configMaxTest config = do done "OK, passed" ntest stamps
61
| nfail == configMaxFail config = do done "Arguments exhausted after" ntest stamps
62
error "More entropy required!"
64
do putStr (configEvery config ntest (arguments result))
67
tests config gen rnd1 ntest (nfail+1) stamps
69
tests config gen rnd1 (ntest+1) nfail (stamp result:stamps)
71
error ( "Falsifiable, after "
74
++ unlines (arguments result)
77
result = generate (configSize config ntest) rnd2 gen
78
(rnd1,rnd2) = split rnd0
80
done :: String -> Int -> [[String]] -> IO ()
81
done mesg ntest stamps =
82
do putStr ( mesg ++ " " ++ show ntest ++ " tests" ++ table )
95
display [x] = " (" ++ x ++ ").\n"
96
display xs = ".\n" ++ unlines (map (++ ".") xs)
98
pairLength xss@(xs:_) = (length xss, xs)
99
entry (n, xs) = percentage n ntest
101
++ concat (intersperse ", " xs)
103
percentage n m = show ((100 * n) `div` m) ++ "%"