on master help sign in
Updated documentation and error reporting.
0cd1496Jan de Muijnck-Hughes
libs/contrib/Test/Unit.idr+2
@@ -10,3 +10,5 @@ import public Test.Unit.Display
10import public Test.Unit.Generic
10import public Test.Unit.Generic
11import public Test.Unit.Assertions
11import public Test.Unit.Assertions
12import public Test.Unit.Runners
12import public Test.Unit.Runners
13+
14+-- --------------------------------------------------------------------- [ EOF ]
libs/contrib/Test/Unit/Assertions.idr+7−6
@@ -3,16 +3,17 @@
3-- Copyright : (c) The Idris Community
3-- Copyright : (c) The Idris Community
4-- License : see LICENSE
4-- License : see LICENSE
5-- --------------------------------------------------------------------- [ EOH ]
5-- --------------------------------------------------------------------- [ EOH ]
6+||| Some simple assertions.
6module Test.Unit.Assertions
7module Test.Unit.Assertions
7
8
8import Test.Unit.Generic
9import Test.Unit.Generic
9
10
10%access export
11%access export
11
12
12−assertTrue : Bool -> IO Bool
13+assertTrue : (given : Bool) -> IO Bool
13assertTrue b = genericTest (Just "Assert True") b True (==)
14assertTrue b = genericTest (Just "Assert True") b True (==)
14
15
15−assertFalse : Bool -> IO Bool
16+assertFalse : (given : Bool) -> IO Bool
16assertFalse b = genericTest (Just "Assert False") b False (==)
17assertFalse b = genericTest (Just "Assert False") b False (==)
17
18
18assertEquals : (Eq a, Show a) => (given : a) -> (expected : a) -> IO Bool
19assertEquals : (Eq a, Show a) => (given : a) -> (expected : a) -> IO Bool
@@ -21,16 +22,16 @@ assertEquals g e = genericTest (Just "Assert Equals") g e (==)
21assertNotEquals : (Eq a, Show a) => (given : a) -> (expected : a) -> IO Bool
22assertNotEquals : (Eq a, Show a) => (given : a) -> (expected : a) -> IO Bool
22assertNotEquals g e = genericTest (Just "Assert Not Equals") g e (\x,y => not (x == y))
23assertNotEquals g e = genericTest (Just "Assert Not Equals") g e (\x,y => not (x == y))
23
24
24−assertJust : Show a => Maybe a -> IO Bool
25+assertJust : Show a => (given : Maybe a) -> IO Bool
25assertJust g = genericTest (Just "Assert Is Just") (isJust g) True (==)
26assertJust g = genericTest (Just "Assert Is Just") (isJust g) True (==)
26
27
27−assertNothing : Show a => Maybe a -> IO Bool
28+assertNothing : Show a => (given : Maybe a) -> IO Bool
28assertNothing g = genericTest (Just "Assert Is Nothing") (isNothing g) True (==)
29assertNothing g = genericTest (Just "Assert Is Nothing") (isNothing g) True (==)
29
30
30−assertLeft : (Show a, Show b) => Either a b -> IO Bool
31+assertLeft : (Show a, Show b) => (given : Either a b) -> IO Bool
31assertLeft g = genericTest (Just "Assert is Left") (isLeft g) True (==)
32assertLeft g = genericTest (Just "Assert is Left") (isLeft g) True (==)
32
33
33−assertRight : (Show a, Show b) => Either a b -> IO Bool
34+assertRight : (Show a, Show b) => (given : Either a b) -> IO Bool
34assertRight g = genericTest (Just "Assert is Right") (isRight g) True (==)
35assertRight g = genericTest (Just "Assert is Right") (isRight g) True (==)
35
36
36-- --------------------------------------------------------------------- [ EOF ]
37-- --------------------------------------------------------------------- [ EOF ]
libs/contrib/Test/Unit/Generic.idr+12−14
@@ -6,6 +6,8 @@
6||| Generic Tests
6||| Generic Tests
7module Test.Unit.Generic
7module Test.Unit.Generic
8
8
9+import Text.PrettyPrint.WL
10+
9import Test.Unit.Display
11import Test.Unit.Display
10
12
11%default total
13%default total
@@ -26,20 +28,16 @@ genericTest : Show a
26genericTest title g e eq = do
28genericTest title g e eq = do
27 putStrLn $ unwords ["Test:" , fromMaybe "Unnamed Test" title]
29 putStrLn $ unwords ["Test:" , fromMaybe "Unnamed Test" title]
28 let res = eq g e
30 let res = eq g e
29− when (not res) $ with List do
31+ when (not res) $ do
30− putStrLn $ unwords [
32+ let errMsg = vcat [
31− errLine
33+ text errLine
32− , "\n"
34+ , text "An error occured" <+> colon
33− , "Error:\n\n"
35+ , indent 2 $ text "Given" <+> colon
34− , "Given:\n\t"
35− , show g
36+ , indent 4 $ text (show g)
36− , "\n"
37− , "Expected:\n\t"
37+ , indent 2 $ text "Expected" <+> colon
38− , show e
38+ , indent 4 $ text (show e)
39− , "\n"
40− , errLine
39+ , text errLine]
41− , "\n"
40+ putStrLn $ Default.toString errMsg
42− ]
43 pure res
41 pure res
44
42
45-- --------------------------------------------------------------------- [ EOF ]
43-- --------------------------------------------------------------------- [ EOF ]
libs/contrib/Test/Unit/Runners.idr+10−3
@@ -1,8 +1,9 @@
1-- ------------------------------------------------------------- [ Runners.idr ]
1-- ------------------------------------------------------------- [ Runners.idr ]
2-- Module : Runners.idr
2-- Module : Runners.idr
3−-- Copyright : (c) Jan de Muijnck-Hughes
3+-- Copyright : (c) The Idris Community.
4-- License : see LICENSE
4-- License : see LICENSE
5-- --------------------------------------------------------------------- [ EOH ]
5-- --------------------------------------------------------------------- [ EOH ]
6+||| Given a series of tests, execute them and report results.
6module Test.Unit.Runners
7module Test.Unit.Runners
7
8
8import Test.Unit.Display
9import Test.Unit.Display
@@ -11,13 +12,19 @@ import Test.Unit.Display
11%access export
12%access export
12
13
13namespace NonReporting
14namespace NonReporting
15+ ||| Run the given set of tests, but don't report results.
14 runTests : List (IO a) -> IO ()
16 runTests : List (IO a) -> IO ()
17+ runTests Nil = do
15− runTests Nil = do putStrLn "All Tests have passed"; putStrLn succLine
18+ putStrLn "All Tests have been performed."
19+ putStrLn succLine
16 runTests (t::ts) = do t; runTests ts
20 runTests (t::ts) = do t; runTests ts
17
21
18namespace Reporting
22namespace Reporting
23+ ||| Run the given set of tests and return the results.
19 runTests : List (IO a) -> IO (List a)
24 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
21 runTests (x::xs) = do
28 runTests (x::xs) = do
22 r <- x
29 r <- x
23 rs <- Reporting.runTests xs
30 rs <- Reporting.runTests xs