|
Packit |
bc3140 |
HUnitTestBase.lhs -- test support and basic tests (Haskell 98 compliant)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> {-# LANGUAGE CPP #-}
|
|
Packit |
bc3140 |
> module HUnitTestBase where
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> import Data.List
|
|
Packit |
bc3140 |
> import Test.HUnit
|
|
Packit |
bc3140 |
> import Test.HUnit.Terminal (terminalAppearance)
|
|
Packit |
bc3140 |
> import System.IO (IOMode(..), openFile, hClose)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> data Report = Start State
|
|
Packit |
bc3140 |
> | Error String State
|
|
Packit |
bc3140 |
> | UnspecifiedError State
|
|
Packit |
bc3140 |
> | Failure String State
|
|
Packit |
bc3140 |
> deriving (Show, Read)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> instance Eq Report where
|
|
Packit |
bc3140 |
> Start s1 == Start s2 = s1 == s2
|
|
Packit |
bc3140 |
> Error m1 s1 == Error m2 s2 = m1 == m2 && s1 == s2
|
|
Packit |
bc3140 |
> Error _ s1 == UnspecifiedError s2 = s1 == s2
|
|
Packit |
bc3140 |
> UnspecifiedError s1 == Error _ s2 = s1 == s2
|
|
Packit |
bc3140 |
> UnspecifiedError s1 == UnspecifiedError s2 = s1 == s2
|
|
Packit |
bc3140 |
> Failure m1 s1 == Failure m2 s2 = m1 == m2 && s1 == s2
|
|
Packit |
bc3140 |
> _ == _ = False
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectReports :: [Report] -> Counts -> Test -> Test
|
|
Packit |
bc3140 |
> expectReports reports1 counts1 t = TestCase $ do
|
|
Packit |
bc3140 |
> (counts2, reports2) <- performTest (\ ss us -> return (Start ss : us))
|
|
Packit |
bc3140 |
> (\_loc m ss us -> return (Error m ss : us))
|
|
Packit |
bc3140 |
> (\_loc m ss us -> return (Failure m ss : us))
|
|
Packit |
bc3140 |
> [] t
|
|
Packit |
bc3140 |
> assertEqual "for the reports from a test," reports1 (reverse reports2)
|
|
Packit |
bc3140 |
> assertEqual "for the counts from a test," counts1 counts2
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> simpleStart :: Report
|
|
Packit |
bc3140 |
> simpleStart = Start (State [] (Counts 1 0 0 0))
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectSuccess :: Test -> Test
|
|
Packit |
bc3140 |
> expectSuccess = expectReports [simpleStart] (Counts 1 1 0 0)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectProblem :: (String -> State -> Report) -> Int -> String -> Test -> Test
|
|
Packit |
bc3140 |
> expectProblem kind err msg =
|
|
Packit |
bc3140 |
> expectReports [simpleStart, kind msg (State [] counts')] counts'
|
|
Packit |
bc3140 |
> where counts' = Counts 1 1 err (1-err)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectError, expectFailure :: String -> Test -> Test
|
|
Packit |
bc3140 |
> expectError = expectProblem Error 1
|
|
Packit |
bc3140 |
> expectFailure = expectProblem Failure 0
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectUnspecifiedError :: Test -> Test
|
|
Packit |
bc3140 |
> expectUnspecifiedError = expectProblem (\ _msg st -> UnspecifiedError st) 1 undefined
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> data Expect = Succ | Err String | UErr | Fail String
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expect :: Expect -> Test -> Test
|
|
Packit |
bc3140 |
> expect Succ t = expectSuccess t
|
|
Packit |
bc3140 |
> expect (Err m) t = expectError m t
|
|
Packit |
bc3140 |
> expect UErr t = expectUnspecifiedError t
|
|
Packit |
bc3140 |
> expect (Fail m) t = expectFailure m t
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> baseTests :: Test
|
|
Packit |
bc3140 |
> baseTests = test [ assertTests,
|
|
Packit |
bc3140 |
> testCaseCountTests,
|
|
Packit |
bc3140 |
> testCasePathsTests,
|
|
Packit |
bc3140 |
> reportTests,
|
|
Packit |
bc3140 |
> textTests,
|
|
Packit |
bc3140 |
> showPathTests,
|
|
Packit |
bc3140 |
> showCountsTests,
|
|
Packit |
bc3140 |
> assertableTests,
|
|
Packit |
bc3140 |
> predicableTests,
|
|
Packit |
bc3140 |
> compareTests,
|
|
Packit |
bc3140 |
> extendedTestTests ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ok :: Test
|
|
Packit |
bc3140 |
> ok = test (assert ())
|
|
Packit |
bc3140 |
> bad :: String -> Test
|
|
Packit |
bc3140 |
> bad m = test (assertFailure m :: Assertion)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> assertTests :: Test
|
|
Packit |
bc3140 |
> assertTests = test [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "null" ~: expectSuccess ok,
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "userError" ~:
|
|
Packit |
bc3140 |
> expectError "user error (error)" (TestCase (ioError (userError "error"))),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "IO error (file missing)" ~:
|
|
Packit |
bc3140 |
> expectUnspecifiedError
|
|
Packit |
bc3140 |
> (test (do _ <- openFile "3g9djs" ReadMode; return ())),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
"error" ~:
|
|
Packit |
bc3140 |
expectError "error" (TestCase (error "error")),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
"tail []" ~:
|
|
Packit |
bc3140 |
expectUnspecifiedError (TestCase (tail [] `seq` return ())),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
-- GHC doesn't currently catch arithmetic exceptions.
|
|
Packit |
bc3140 |
"div by 0" ~:
|
|
Packit |
bc3140 |
expectUnspecifiedError (TestCase ((3 `div` 0) `seq` return ())),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "assertFailure" ~:
|
|
Packit |
bc3140 |
> let msg = "simple assertFailure"
|
|
Packit |
bc3140 |
> in expectFailure msg (test (assertFailure msg :: Assertion)),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "assertString null" ~: expectSuccess (TestCase (assertString "")),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "assertString nonnull" ~:
|
|
Packit |
bc3140 |
> let msg = "assertString nonnull"
|
|
Packit |
bc3140 |
> in expectFailure msg (TestCase (assertString msg)),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> let f v non =
|
|
Packit |
bc3140 |
> show v ++ " with " ++ non ++ "null message" ~:
|
|
Packit |
bc3140 |
> expect (if v then Succ else Fail non) $ test $ assertBool non v
|
|
Packit |
bc3140 |
> in "assertBool" ~: [ f v non | v <- [True, False], non <- ["non", ""] ],
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> let msg = "assertBool True"
|
|
Packit |
bc3140 |
> in msg ~: expectSuccess (test (assertBool msg True)),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> let msg = "assertBool False"
|
|
Packit |
bc3140 |
> in msg ~: expectFailure msg (test (assertBool msg False)),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "assertEqual equal" ~:
|
|
Packit |
bc3140 |
> expectSuccess (test (assertEqual "" (3 :: Integer) (3 :: Integer))),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "assertEqual unequal no msg" ~:
|
|
Packit |
bc3140 |
> expectFailure "expected: 3\n but got: 4"
|
|
Packit |
bc3140 |
> (test (assertEqual "" (3 :: Integer) (4 :: Integer))),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "assertEqual unequal with msg" ~:
|
|
Packit |
bc3140 |
> expectFailure "for x,\nexpected: 3\n but got: 4"
|
|
Packit |
bc3140 |
> (test (assertEqual "for x," (3 :: Integer) (4 :: Integer)))
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> emptyTest0, emptyTest1, emptyTest2 :: Test
|
|
Packit |
bc3140 |
> emptyTest0 = TestList []
|
|
Packit |
bc3140 |
> emptyTest1 = TestLabel "empty" emptyTest0
|
|
Packit |
bc3140 |
> emptyTest2 = TestList [ emptyTest0, emptyTest1, emptyTest0 ]
|
|
Packit |
bc3140 |
> emptyTests :: [Test]
|
|
Packit |
bc3140 |
> emptyTests = [emptyTest0, emptyTest1, emptyTest2]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testCountEmpty :: Test -> Test
|
|
Packit |
bc3140 |
> testCountEmpty t = TestCase (assertEqual "" 0 (testCaseCount t))
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suite0, suite1, suite2, suite3 :: (Integer, Test)
|
|
Packit |
bc3140 |
> suite0 = (0, ok)
|
|
Packit |
bc3140 |
> suite1 = (1, TestList [])
|
|
Packit |
bc3140 |
> suite2 = (2, TestLabel "3" ok)
|
|
Packit |
bc3140 |
> suite3 = (3, suite)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suite :: Test
|
|
Packit |
bc3140 |
> suite =
|
|
Packit |
bc3140 |
> TestLabel "0"
|
|
Packit |
bc3140 |
> (TestList [ TestLabel "1" (bad "1"),
|
|
Packit |
bc3140 |
> TestLabel "2" (TestList [ TestLabel "2.1" ok,
|
|
Packit |
bc3140 |
> ok,
|
|
Packit |
bc3140 |
> TestLabel "2.3" (bad "2") ]),
|
|
Packit |
bc3140 |
> TestLabel "3" (TestLabel "4" (TestLabel "5" (bad "3"))),
|
|
Packit |
bc3140 |
> TestList [ TestList [ TestLabel "6" (bad "4") ] ] ])
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suiteCount :: Int
|
|
Packit |
bc3140 |
> suiteCount = 6
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suitePaths :: [[Node]]
|
|
Packit |
bc3140 |
> suitePaths = [
|
|
Packit |
bc3140 |
> [Label "0", ListItem 0, Label "1"],
|
|
Packit |
bc3140 |
> [Label "0", ListItem 1, Label "2", ListItem 0, Label "2.1"],
|
|
Packit |
bc3140 |
> [Label "0", ListItem 1, Label "2", ListItem 1],
|
|
Packit |
bc3140 |
> [Label "0", ListItem 1, Label "2", ListItem 2, Label "2.3"],
|
|
Packit |
bc3140 |
> [Label "0", ListItem 2, Label "3", Label "4", Label "5"],
|
|
Packit |
bc3140 |
> [Label "0", ListItem 3, ListItem 0, ListItem 0, Label "6"]]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suiteReports :: [Report]
|
|
Packit |
bc3140 |
> suiteReports = [ Start (State (p 0) (Counts 6 0 0 0)),
|
|
Packit |
bc3140 |
> Failure "1" (State (p 0) (Counts 6 1 0 1)),
|
|
Packit |
bc3140 |
> Start (State (p 1) (Counts 6 1 0 1)),
|
|
Packit |
bc3140 |
> Start (State (p 2) (Counts 6 2 0 1)),
|
|
Packit |
bc3140 |
> Start (State (p 3) (Counts 6 3 0 1)),
|
|
Packit |
bc3140 |
> Failure "2" (State (p 3) (Counts 6 4 0 2)),
|
|
Packit |
bc3140 |
> Start (State (p 4) (Counts 6 4 0 2)),
|
|
Packit |
bc3140 |
> Failure "3" (State (p 4) (Counts 6 5 0 3)),
|
|
Packit |
bc3140 |
> Start (State (p 5) (Counts 6 5 0 3)),
|
|
Packit |
bc3140 |
> Failure "4" (State (p 5) (Counts 6 6 0 4))]
|
|
Packit |
bc3140 |
> where p n = reverse (suitePaths !! n)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suiteCounts :: Counts
|
|
Packit |
bc3140 |
> suiteCounts = Counts 6 6 0 4
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suiteOutput :: String
|
|
Packit |
bc3140 |
> suiteOutput = concat [
|
|
Packit |
bc3140 |
> "### Failure in: 0:0:1\n",
|
|
Packit |
bc3140 |
> "1\n",
|
|
Packit |
bc3140 |
> "### Failure in: 0:1:2:2:2.3\n",
|
|
Packit |
bc3140 |
> "2\n",
|
|
Packit |
bc3140 |
> "### Failure in: 0:2:3:4:5\n",
|
|
Packit |
bc3140 |
> "3\n",
|
|
Packit |
bc3140 |
> "### Failure in: 0:3:0:0:6\n",
|
|
Packit |
bc3140 |
> "4\n",
|
|
Packit |
bc3140 |
> "Cases: 6 Tried: 6 Errors: 0 Failures: 4\n"]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> suites :: [(Integer, Test)]
|
|
Packit |
bc3140 |
> suites = [suite0, suite1, suite2, suite3]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testCount :: Show n => (n, Test) -> Int -> Test
|
|
Packit |
bc3140 |
> testCount (num, t) count =
|
|
Packit |
bc3140 |
> "testCaseCount suite" ++ show num ~:
|
|
Packit |
bc3140 |
> TestCase $ assertEqual "for test count," count (testCaseCount t)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testCaseCountTests :: Test
|
|
Packit |
bc3140 |
> testCaseCountTests = TestList [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "testCaseCount empty" ~: test (map testCountEmpty emptyTests),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testCount suite0 1,
|
|
Packit |
bc3140 |
> testCount suite1 0,
|
|
Packit |
bc3140 |
> testCount suite2 1,
|
|
Packit |
bc3140 |
> testCount suite3 suiteCount
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testPaths :: Show n => (n, Test) -> [[Node]] -> Test
|
|
Packit |
bc3140 |
> testPaths (num, t) paths =
|
|
Packit |
bc3140 |
> "testCasePaths suite" ++ show num ~:
|
|
Packit |
bc3140 |
> TestCase $ assertEqual "for test paths,"
|
|
Packit |
bc3140 |
> (map reverse paths) (testCasePaths t)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testPathsEmpty :: Test -> Test
|
|
Packit |
bc3140 |
> testPathsEmpty t = TestCase $ assertEqual "" [] (testCasePaths t)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testCasePathsTests :: Test
|
|
Packit |
bc3140 |
> testCasePathsTests = TestList [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "testCasePaths empty" ~: test (map testPathsEmpty emptyTests),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> testPaths suite0 [[]],
|
|
Packit |
bc3140 |
> testPaths suite1 [],
|
|
Packit |
bc3140 |
> testPaths suite2 [[Label "3"]],
|
|
Packit |
bc3140 |
> testPaths suite3 suitePaths
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> reportTests :: Test
|
|
Packit |
bc3140 |
> reportTests = "reports" ~: expectReports suiteReports suiteCounts suite
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> removeLocation :: String -> String
|
|
Packit |
bc3140 |
> removeLocation = unlines . filter (not . isInfixOf __FILE__) . lines
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectText :: Counts -> String -> Test -> Test
|
|
Packit |
bc3140 |
> expectText counts1 text1 t = TestCase $ do
|
|
Packit |
bc3140 |
> (counts2, text2) <- runTestText putTextToShowS t
|
|
Packit |
bc3140 |
> assertEqual "for the final counts," counts1 counts2
|
|
Packit |
bc3140 |
> assertEqual "for the failure text output," text1 (removeLocation $ text2 "")
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> textTests :: Test
|
|
Packit |
bc3140 |
> textTests = test [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "lone error" ~:
|
|
Packit |
bc3140 |
> expectText (Counts 1 1 1 0)
|
|
Packit |
bc3140 |
> "### Error:\nuser error (xyz)\nCases: 1 Tried: 1 Errors: 1 Failures: 0\n"
|
|
Packit |
bc3140 |
> (test (do _ <- ioError (userError "xyz"); return ())),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "lone failure" ~:
|
|
Packit |
bc3140 |
> expectText (Counts 1 1 0 1)
|
|
Packit |
bc3140 |
> "### Failure:\nxyz\nCases: 1 Tried: 1 Errors: 0 Failures: 1\n"
|
|
Packit |
bc3140 |
> (test (assert "xyz")),
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "putTextToShowS" ~:
|
|
Packit |
bc3140 |
> expectText suiteCounts suiteOutput suite,
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "putTextToHandle (file)" ~:
|
|
Packit |
bc3140 |
> let filename = "HUnitTest.tmp"
|
|
Packit |
bc3140 |
> trim = unlines . map (reverse . dropWhile (== ' ') . reverse) . lines
|
|
Packit |
bc3140 |
> in map test
|
|
Packit |
bc3140 |
> [ "show progress = " ++ show flag ~: do
|
|
Packit |
bc3140 |
> handle <- openFile filename WriteMode
|
|
Packit |
bc3140 |
> (counts', _) <- runTestText (putTextToHandle handle flag) suite
|
|
Packit |
bc3140 |
> hClose handle
|
|
Packit |
bc3140 |
> assertEqual "for the final counts," suiteCounts counts'
|
|
Packit |
bc3140 |
> text <- readFile filename
|
|
Packit |
bc3140 |
> let text' = removeLocation $ if flag then trim (terminalAppearance text) else text
|
|
Packit |
bc3140 |
> assertEqual "for the failure text output," suiteOutput text'
|
|
Packit |
bc3140 |
> | flag <- [False, True] ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> showPathTests :: Test
|
|
Packit |
bc3140 |
> showPathTests = "showPath" ~: [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "empty" ~: showPath [] ~?= "",
|
|
Packit |
bc3140 |
> ":" ~: showPath [Label ":", Label "::"] ~?= "\"::\":\":\"",
|
|
Packit |
bc3140 |
> "\"\\\n" ~: showPath [Label "\"\\n\n\""] ~?= "\"\\\"\\\\n\\n\\\"\"",
|
|
Packit |
bc3140 |
> "misc" ~: showPath [Label "b", ListItem 2, ListItem 3, Label "foo"] ~?=
|
|
Packit |
bc3140 |
> "foo:3:2:b"
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> showCountsTests :: Test
|
|
Packit |
bc3140 |
> showCountsTests = "showCounts" ~: showCounts (Counts 4 3 2 1) ~?=
|
|
Packit |
bc3140 |
> "Cases: 4 Tried: 3 Errors: 2 Failures: 1"
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> lift :: a -> IO a
|
|
Packit |
bc3140 |
> lift a = return a
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> assertableTests :: Test
|
|
Packit |
bc3140 |
> assertableTests =
|
|
Packit |
bc3140 |
> let assertables x = [
|
|
Packit |
bc3140 |
> ( "", assert x , test (lift x)) ,
|
|
Packit |
bc3140 |
> ( "IO ", assert (lift x) , test (lift (lift x))) ,
|
|
Packit |
bc3140 |
> ( "IO IO ", assert (lift (lift x)), test (lift (lift (lift x))))]
|
|
Packit |
bc3140 |
> assertabled l e x =
|
|
Packit |
bc3140 |
> test [ test [ "assert" ~: pre ++ l ~: expect e $ test $ a,
|
|
Packit |
bc3140 |
> "test" ~: pre ++ "IO " ++ l ~: expect e $ t ]
|
|
Packit |
bc3140 |
> | (pre, a, t) <- assertables x ]
|
|
Packit |
bc3140 |
> in "assertable" ~: [
|
|
Packit |
bc3140 |
> assertabled "()" Succ (),
|
|
Packit |
bc3140 |
> assertabled "True" Succ True,
|
|
Packit |
bc3140 |
> assertabled "False" (Fail "") False,
|
|
Packit |
bc3140 |
> assertabled "\"\"" Succ "",
|
|
Packit |
bc3140 |
> assertabled "\"x\"" (Fail "x") "x"
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> predicableTests :: Test
|
|
Packit |
bc3140 |
> predicableTests =
|
|
Packit |
bc3140 |
> let predicables x m = [
|
|
Packit |
bc3140 |
> ( "", assertionPredicate x , x @? m, x ~? m ),
|
|
Packit |
bc3140 |
> ( "IO ", assertionPredicate (l x) , l x @? m, l x ~? m ),
|
|
Packit |
bc3140 |
> ( "IO IO ", assertionPredicate (l(l x)), l(l x) @? m, l(l x) ~? m )]
|
|
Packit |
bc3140 |
> l x = lift x
|
|
Packit |
bc3140 |
> predicabled lab e m x =
|
|
Packit |
bc3140 |
> test [ test [ "pred" ~: pre ++ lab ~: m ~: expect e $ test $ tst p,
|
|
Packit |
bc3140 |
> "(@?)" ~: pre ++ lab ~: m ~: expect e $ test $ a,
|
|
Packit |
bc3140 |
> "(~?)" ~: pre ++ lab ~: m ~: expect e $ t ]
|
|
Packit |
bc3140 |
> | (pre, p, a, t) <- predicables x m ]
|
|
Packit |
bc3140 |
> where tst p = p >>= assertBool m
|
|
Packit |
bc3140 |
> in "predicable" ~: [
|
|
Packit |
bc3140 |
> predicabled "True" Succ "error" True,
|
|
Packit |
bc3140 |
> predicabled "False" (Fail "error") "error" False,
|
|
Packit |
bc3140 |
> predicabled "True" Succ "" True,
|
|
Packit |
bc3140 |
> predicabled "False" (Fail "" ) "" False
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> compareTests :: Test
|
|
Packit |
bc3140 |
> compareTests = test [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> let succ' = const Succ
|
|
Packit |
bc3140 |
> compare1 :: (String -> Expect) -> Integer -> Integer -> Test
|
|
Packit |
bc3140 |
> compare1 = compare'
|
|
Packit |
bc3140 |
> compare2 :: (String -> Expect)
|
|
Packit |
bc3140 |
> -> (Integer, Char, Double)
|
|
Packit |
bc3140 |
> -> (Integer, Char, Double)
|
|
Packit |
bc3140 |
> -> Test
|
|
Packit |
bc3140 |
> compare2 = compare'
|
|
Packit |
bc3140 |
> compare' f expected actual
|
|
Packit |
bc3140 |
> = test [ "(@=?)" ~: expect e $ test (expected @=? actual),
|
|
Packit |
bc3140 |
> "(@?=)" ~: expect e $ test (actual @?= expected),
|
|
Packit |
bc3140 |
> "(~=?)" ~: expect e $ expected ~=? actual,
|
|
Packit |
bc3140 |
> "(~?=)" ~: expect e $ actual ~?= expected ]
|
|
Packit |
bc3140 |
> where e = f $ "expected: " ++ show expected ++
|
|
Packit |
bc3140 |
> "\n but got: " ++ show actual
|
|
Packit |
bc3140 |
> in test [
|
|
Packit |
bc3140 |
> compare1 succ' 1 1,
|
|
Packit |
bc3140 |
> compare1 Fail 1 2,
|
|
Packit |
bc3140 |
> compare2 succ' (1,'b',3.0) (1,'b',3.0),
|
|
Packit |
bc3140 |
> compare2 Fail (1,'b',3.0) (1,'b',3.1)
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectList1 :: Int -> Test -> Test
|
|
Packit |
bc3140 |
> expectList1 c =
|
|
Packit |
bc3140 |
> expectReports
|
|
Packit |
bc3140 |
> [ Start (State [ListItem n] (Counts c n 0 0)) | n <- [0..c-1] ]
|
|
Packit |
bc3140 |
> (Counts c c 0 0)
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> expectList2 :: [Int] -> Test -> Test
|
|
Packit |
bc3140 |
> expectList2 cs t =
|
|
Packit |
bc3140 |
> expectReports
|
|
Packit |
bc3140 |
> [ Start (State [ListItem j, ListItem i] (Counts c n 0 0))
|
|
Packit |
bc3140 |
> | ((i,j),n) <- zip coords [0..] ]
|
|
Packit |
bc3140 |
> (Counts c c 0 0)
|
|
Packit |
bc3140 |
> t
|
|
Packit |
bc3140 |
> where coords = [ (i,j) | i <- [0 .. length cs - 1], j <- [0 .. cs!!i - 1] ]
|
|
Packit |
bc3140 |
> c = testCaseCount t
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> extendedTestTests :: Test
|
|
Packit |
bc3140 |
> extendedTestTests = test [
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "test idempotent" ~: expect Succ $ test $ test $ test $ ok,
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "test list 1" ~: expectList1 3 $ test [assert (), assert "", assert True],
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> "test list 2" ~: expectList2 [0, 1, 2] $ test [[], [ok], [ok, ok]]
|
|
Packit |
bc3140 |
|
|
Packit |
bc3140 |
> ]
|