6 data TestResult = MkSuccess | MkFailure String
10 constructor MkTestCase
14 runTestCase : TestCase -> IO TestResult
15 runTestCase testCase =
16 do putStrLn $ "Running test case: " <+> testCase.name
17 result <- testCase.run
19 MkSuccess => putStrLn "Success"
20 MkFailure message => putStrLn $ "Failure: " <+> message
24 data TestTree = MkTestLeaf TestCase | MkTestGroup String (List TestTree)
27 -- Helper. We can't just call use sequence . map runTestTree in runTestTree because the compiler wouldn't be able to tell runTestTree is total.
28 runTestTrees : List TestResult -> List TestTree -> IO (List TestResult)
29 runTestTrees acc [] = pure $ reverse acc
30 runTestTrees acc (tree :: trees) =
31 do result <- runTestTree tree
32 runTestTrees (result :: acc) trees
35 runTestTree : TestTree -> IO TestResult
36 runTestTree (MkTestLeaf testCase) = runTestCase testCase
37 runTestTree (MkTestGroup name subTrees) =
38 let resultToNumFailures : TestResult -> Nat
39 resultToNumFailures MkSuccess = 0
40 resultToNumFailures (MkFailure _) = 1
42 do putStrLn $ "Starting test group: " <+> name
43 results <- runTestTrees [] subTrees
44 let numFailures = sum $ map resultToNumFailures results
46 "Test group finished: " <+> name <+> ". " <+>
47 show numFailures <+> "/" <+> show (length results) <+>