0 | -- SPDX-FileCopyrightText: 2021 The test-idr developers
 1 | --
 2 | -- SPDX-License-Identifier: MPL-2.0
 3 |
 4 | module Tester.Runner
 5 |
 6 | import Tester
 7 | import Data.List
 8 |
 9 |
10 | import Control.ANSI
11 | import Control.Monad.Either
12 |
13 |
14 | ||| Run the set of tests in `tests` and print out the test result.
15 | ||| 
16 | ||| If a test failed the fail-message will be displayed.
17 | |||
18 | ||| @ tests The tests to run
19 | export
20 | runTests : (tests : List Test) -> IO Bool
21 | runTests tests = do
22 |     let longestDesc = foldl (\acc,t => max acc (length t.description)) 0 tests
23 |     let padding = \len =>
24 |             let diff = longestDesc `minus` len
25 |             in pack $ replicate diff ' '
26 |
27 |     res <- for tests $ \t => do
28 |         putStr $ t.description ++ padding (length t.description) ++ " ... " 
29 |         case !(runEitherT t.run) of
30 |             Left err => do
31 |
32 |                 printLn $ colored Red "failed"
33 |                 putStrLn err
34 |                 pure False
35 |             Right () => do
36 |                 printLn $ colored Green "passed"
37 |                 pure True
38 |     pure $ all (==True) res
39 |