Skip to content

Commit

Permalink
optimize test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
henrytill committed Nov 10, 2024
1 parent eca7dbb commit 093ee11
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Main (main) where

import Control.Monad (unless)
import qualified Data.List as List
import Data.Map.Strict (Map)
import Data.Text (Text)
import qualified Data.Text.IO as TIO
Expand Down Expand Up @@ -131,14 +130,16 @@ testArrayKey1 kv =
expected = [1, 2, 3]
actual = kv ^.. mapAt "array" . valueAt "key1" . _List . traverse . _Integer

makeFolder :: Table -> (String, Bool) -> (Table -> Test) -> (String, Bool)
makeFolder kv (output, isPassed) test =
makeStep :: Table -> (Table -> Test) -> (ShowS, Bool) -> (ShowS, Bool)
makeStep kv test (f, allPassed) =
let result = runTest (test kv)
in (output <> "\n" <> resultToString result, isPassed && resultIsPassed result)
in (showString (resultToString result) . showChar '\n' . f, resultIsPassed result && allPassed)

runTests :: Table -> (String, Bool)
runTests kv = List.foldl' (makeFolder kv) (mempty, True) tests
runTests kv = (buildString mempty, passed)
where
step = makeStep kv
(buildString, passed) = foldr step (mempty, True) tests
tests =
[ testTableKey,
testTableZoo,
Expand All @@ -161,5 +162,5 @@ main :: IO ()
main = do
ex <- readTomlFile "./example/example-v0.4.0.toml"
let (output, passed) = runTests ex
putStrLn output
putStr output
unless passed exitFailure

0 comments on commit 093ee11

Please sign in to comment.