File: TestUtil.hs

package info (click to toggle)
ghc 8.0.1-17
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 55,080 kB
  • ctags: 9,332
  • sloc: haskell: 363,120; ansic: 54,900; sh: 4,782; makefile: 974; perl: 542; asm: 315; python: 306; xml: 154; lisp: 7
file content (39 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# OPTIONS -fno-warn-overlapping-patterns #-}
module Test.TestUtil
    (
    module Test.TestUtil,
    module Test.Framework,
    module Test.Framework.Providers.QuickCheck2
    ) where

import Test.Framework
import Test.Framework.Providers.API
import Test.Framework.Providers.QuickCheck2
import Data.Typeable

data Result = Pass | Fail String deriving Typeable

instance Show Result where
    show Pass = "passed"
    show (Fail s) = "failed: " ++ s

instance TestResultlike () Result where
    testSucceeded Pass = True
    testSucceeded (Fail _) = False

instance Testlike () Result (IO Result) where
    testTypeName _ = "Cases"
    runTest _ ior = do
        r <- ior
        return (Finished r,return ())

ioTest :: String -> IO Result -> Test
ioTest = Test

pureTest :: String -> Result -> Test
pureTest name result = ioTest name (return result)

diff :: (Show a,Eq a) => a -> a -> Result
diff expected found | expected == found = Pass
diff expected found = Fail ("expected " ++ (show expected) ++ " but found " ++ (show found))