From b515ae37932b800b69df3ded320e4b673ee23cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 25 Aug 2026 18:09:40 +0200 Subject: Retport summary of test execution Changelog: Added `--report` command-line option to print summary of passed/failed tests. --- src/Run.hs | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/Run.hs') diff --git a/src/Run.hs b/src/Run.hs index a253e51..27dc756 100644 --- a/src/Run.hs +++ b/src/Run.hs @@ -1,5 +1,7 @@ module Run ( module Run.Monad, + Report(..), + TestName, textTestName, runTests, runTest, @@ -58,17 +60,44 @@ import Test import Test.Builtins -runTests :: Output -> TestOptions -> GlobalDefs -> [ Test ] -> IO Bool +data Report = Report + { reportTotalCount :: Int + , reportPassedCount :: Int + , reportSkippedCount :: Int + , reportFailedCount :: Int + , reportFailedList :: [ TestName ] + } + +reportPassed :: Report -> Report +reportPassed r = r + { reportTotalCount = reportTotalCount r + 1 + , reportPassedCount = reportPassedCount r + 1 + } + +reportFailed :: TestName -> Report -> Report +reportFailed tname r = r + { reportTotalCount = reportTotalCount r + 1 + , reportFailedCount = reportFailedCount r + 1 + , reportFailedList = tname : reportFailedList r + } + +runTests :: Output -> TestOptions -> GlobalDefs -> [ Test ] -> IO Report runTests out opts gdefs tests = do go $ concat $ replicate (optRepeat opts) tests where go (t : ts) = do runTest out opts gdefs t >>= \case - True -> go ts - False - | optKeepGoing opts -> go ts >> return False - | otherwise -> return False - go [] = return True + True -> reportPassed <$> go ts + False -> reportFailed (testName t) <$> if + | optKeepGoing opts -> go ts + | otherwise -> go [] + go [] = return Report + { reportTotalCount = 0 + , reportPassedCount = 0 + , reportSkippedCount = 0 + , reportFailedCount = 0 + , reportFailedList = [] + } runTest :: Output -> TestOptions -> GlobalDefs -> Test -> IO Bool -- cgit v1.2.3