on master help sign in
Updated documentation and error reporting.
commit0cd1496e0c240d40afb502bbe1647c961c37ab23 authorJan de Muijnck-Hughes <jan.deMuijnck-Hughes@glasgow.ac.uk> dateThu 9 Nov 2017, 10:12 (9 years ago) parent4e2b726
4 files changed+31−23
libs/contrib/Test/Unit.idr+2 libs/contrib/Test/Unit/Assertions.idr+7−6 libs/contrib/Test/Unit/Generic.idr+12−14 libs/contrib/Test/Unit/Runners.idr+10−3
libs/contrib/Test/Unit.idr+2
@@ -10,3 +10,5 @@ import public Test.Unit.Display
1010import public Test.Unit.Generic
1111import public Test.Unit.Assertions
1212import public Test.Unit.Runners
13+
14+-- --------------------------------------------------------------------- [ EOF ]
libs/contrib/Test/Unit/Assertions.idr+7−6
@@ -3,16 +3,17 @@
33-- Copyright : (c) The Idris Community
44-- License : see LICENSE
55-- --------------------------------------------------------------------- [ EOH ]
6+||| Some simple assertions.
67module Test.Unit.Assertions
78
89import Test.Unit.Generic
910
1011%access export
1112
12−assertTrue : Bool -> IO Bool
13+assertTrue : (given : Bool) -> IO Bool
1314assertTrue b = genericTest (Just "Assert True") b True (==)
1415
15−assertFalse : Bool -> IO Bool
16+assertFalse : (given : Bool) -> IO Bool
1617assertFalse b = genericTest (Just "Assert False") b False (==)
1718
1819assertEquals : (Eq a, Show a) => (given : a) -> (expected : a) -> IO Bool
@@ -21,16 +22,16 @@ assertEquals g e = genericTest (Just "Assert Equals") g e (==)
2122assertNotEquals : (Eq a, Show a) => (given : a) -> (expected : a) -> IO Bool
2223assertNotEquals g e = genericTest (Just "Assert Not Equals") g e (\x,y => not (x == y))
2324
24−assertJust : Show a => Maybe a -> IO Bool
25+assertJust : Show a => (given : Maybe a) -> IO Bool
2526assertJust g = genericTest (Just "Assert Is Just") (isJust g) True (==)
2627
27−assertNothing : Show a => Maybe a -> IO Bool
28+assertNothing : Show a => (given : Maybe a) -> IO Bool
2829assertNothing g = genericTest (Just "Assert Is Nothing") (isNothing g) True (==)
2930
30−assertLeft : (Show a, Show b) => Either a b -> IO Bool
31+assertLeft : (Show a, Show b) => (given : Either a b) -> IO Bool
3132assertLeft g = genericTest (Just "Assert is Left") (isLeft g) True (==)
3233
33−assertRight : (Show a, Show b) => Either a b -> IO Bool
34+assertRight : (Show a, Show b) => (given : Either a b) -> IO Bool
3435assertRight g = genericTest (Just "Assert is Right") (isRight g) True (==)
3536
3637-- --------------------------------------------------------------------- [ EOF ]
libs/contrib/Test/Unit/Generic.idr+12−14
@@ -6,6 +6,8 @@
66||| Generic Tests
77module Test.Unit.Generic
88
9+import Text.PrettyPrint.WL
10+
911import Test.Unit.Display
1012
1113%default total
@@ -26,20 +28,16 @@ genericTest : Show a
2628genericTest title g e eq = do
2729 putStrLn $ unwords ["Test:" , fromMaybe "Unnamed Test" title]
2830 let res = eq g e
29− when (not res) $ with List do
30− putStrLn $ unwords [
31− errLine
32− , "\n"
33− , "Error:\n\n"
34− , "Given:\n\t"
35− , show g
36− , "\n"
37− , "Expected:\n\t"
38− , show e
39− , "\n"
40− , errLine
41− , "\n"
42− ]
31+ when (not res) $ do
32+ let errMsg = vcat [
33+ text errLine
34+ , text "An error occured" <+> colon
35+ , indent 2 $ text "Given" <+> colon
36+ , indent 4 $ text (show g)
37+ , indent 2 $ text "Expected" <+> colon
38+ , indent 4 $ text (show e)
39+ , text errLine]
40+ putStrLn $ Default.toString errMsg
4341 pure res
4442
4543-- --------------------------------------------------------------------- [ EOF ]
libs/contrib/Test/Unit/Runners.idr+10−3
@@ -1,8 +1,9 @@
11-- ------------------------------------------------------------- [ Runners.idr ]
22-- Module : Runners.idr
3−-- Copyright : (c) Jan de Muijnck-Hughes
3+-- Copyright : (c) The Idris Community.
44-- License : see LICENSE
55-- --------------------------------------------------------------------- [ EOH ]
6+||| Given a series of tests, execute them and report results.
67module Test.Unit.Runners
78
89import Test.Unit.Display
@@ -11,13 +12,19 @@ import Test.Unit.Display
1112%access export
1213
1314namespace NonReporting
15+ ||| Run the given set of tests, but don't report results.
1416 runTests : List (IO a) -> IO ()
15− runTests Nil = do putStrLn "All Tests have passed"; putStrLn succLine
17+ runTests Nil = do
18+ putStrLn "All Tests have been performed."
19+ putStrLn succLine
1620 runTests (t::ts) = do t; runTests ts
1721
1822namespace Reporting
23+ ||| Run the given set of tests and return the results.
1924 runTests : List (IO a) -> IO (List a)
20− runTests Nil = pure Nil
25+ runTests Nil = do
26+ putStrLn "All tests have been performed."
27+ putStrLn succLine
2128 runTests (x::xs) = do
2229 r <- x
2330 rs <- Reporting.runTests xs