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"