diff options
Diffstat (limited to 'src/JUnit.hs')
| -rw-r--r-- | src/JUnit.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/JUnit.hs b/src/JUnit.hs index 3649d53..71fe3c1 100644 --- a/src/JUnit.hs +++ b/src/JUnit.hs @@ -8,6 +8,7 @@ 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.Scientific import Data.Text.Encoding import System.Directory @@ -18,19 +19,22 @@ import Run import Script.Var +showTime :: Scientific -> B.ByteString +showTime = BC.pack . formatScientific Fixed Nothing + writeJUnitReport :: FilePath -> Report -> IO () writeJUnitReport path Report {..} = do createDirectoryIfMissing True $ takeDirectory path withFile path WriteMode $ \h -> do B.hPutStr h $ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - B.hPutStr h $ "<testsuites time=\"" <> BC.pack (show reportTotalTime) <> "\">\n" + B.hPutStr h $ "<testsuites time=\"" <> showTime reportTotalTime <> "\">\n" forM_ (NE.groupBy ((==) `on` (testNameModule . reportTestName)) reportTests) $ \grp -> do - B.hPutStr h $ "<testsuite name=\"" <> encodeUtf8 (textModuleName $ testNameModule $ reportTestName $ NE.head grp) <> "\" time=\"" <> BC.pack (show $ sum $ map reportTime $ NE.toList grp) <> "\">" + B.hPutStr h $ "<testsuite name=\"" <> encodeUtf8 (textModuleName $ testNameModule $ reportTestName $ NE.head grp) <> "\" time=\"" <> showTime (sum $ map reportTime $ NE.toList grp) <> "\">" forM_ grp $ \SingleTestReport {..} -> do B.hPutStr h $ B.concat [ "<testcase name=\"", encodeUtf8 (testNameBase reportTestName), "\"" , " classname=\"", encodeUtf8 (textModuleName $ testNameModule reportTestName), "\"" - , " time=\"", BC.pack (show reportTime), "\"" + , " time=\"", showTime reportTime, "\"" , case reportTestFailed of Nothing -> do " />" |