From ac8bae764b026def10fa110c675002f14c84860a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 30 Aug 2026 20:05:25 +0200 Subject: Implement report in JUnit XML format Changelog: Added `--junit-report` switch to generate test report in JUnit XML format. --- src/JUnit.hs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/JUnit.hs (limited to 'src/JUnit.hs') diff --git a/src/JUnit.hs b/src/JUnit.hs new file mode 100644 index 0000000..c935987 --- /dev/null +++ b/src/JUnit.hs @@ -0,0 +1,40 @@ +module JUnit ( + writeJUnitReport, +) where + +import Control.Monad + +import Data.ByteString qualified as B +import Data.ByteString.Char8 qualified as BC +import Data.Function +import Data.List.NonEmpty qualified as NE +import Data.Text.Encoding + +import System.IO + +import Run +import Script.Var + + +writeJUnitReport :: FilePath -> Report -> IO () +writeJUnitReport path Report {..} = withFile path WriteMode $ \h -> do + B.hPutStr h $ "\n" + B.hPutStr h $ " BC.pack (show reportTotalTime) <> "\">\n" + forM_ (NE.groupBy ((==) `on` (testNameModule . reportTestName)) reportTests) $ \grp -> do + B.hPutStr h $ " encodeUtf8 (textModuleName $ testNameModule $ reportTestName $ NE.head grp) <> "\" time=\"" <> BC.pack (show $ sum $ map reportTime $ NE.toList grp) <> "\">" + forM_ grp $ \SingleTestReport {..} -> do + B.hPutStr h $ B.concat + [ " do + " />" + Just Failed -> do + ">" + Just (ProcessCrashed _) -> do + ">" + ] + + B.hPutStr h $ "" + B.hPutStr h $ "\n" -- cgit v1.2.3