278154374b2764a00330a2556a9b0109bf780f78
[packages/filepath.git] / tests / AutoTest.hs
1
2 module AutoTest(
3 module AutoTest,
4 module Test.QuickCheck,
5 module Data.List
6 ) where
7
8 import Test.QuickCheck hiding ((==>))
9 import Data.List
10
11 infixr 0 ==>
12 a ==> b = not a || b
13
14
15 constTest :: Bool -> IO ()
16 constTest True = return ()
17 constTest False = error "Failed on constTest"
18
19
20
21 newtype QFilePath = QFilePath FilePath
22 deriving Show
23
24 instance Arbitrary QFilePath where
25 arbitrary = fmap (QFilePath . map fromQChar) arbitrary
26 shrink (QFilePath x) = map QFilePath $ shrink x
27
28 newtype QChar = QChar {fromQChar :: Char}
29
30 instance Arbitrary QChar where
31 arbitrary = fmap QChar $ elements "?./:\\a ;_"
32
33
34
35 quickSafe :: Testable a => a -> IO ()
36 quickSafe prop = do
37 res <- quickCheckWithResult stdArgs{chatty=False, maxSuccess=10000} prop
38 case res of
39 Success{} -> return ()
40 -- Output is already escaped. Do not call show on it, but print as-is.
41 _ -> error $ show res{output=""} ++ "\n" ++ (output res)