From b43f0b18bdb4580443c8c6d4bbdf5c86d6afbeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sat, 5 Sep 2026 20:52:41 +0200 Subject: Create directory for report file if needed --- src/JUnit.hs | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/JUnit.hs b/src/JUnit.hs index c935987..3649d53 100644 --- a/src/JUnit.hs +++ b/src/JUnit.hs @@ -10,6 +10,8 @@ import Data.Function import Data.List.NonEmpty qualified as NE import Data.Text.Encoding +import System.Directory +import System.FilePath import System.IO import Run @@ -17,24 +19,26 @@ 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 - ">" - ] +writeJUnitReport path Report {..} = do + createDirectoryIfMissing True $ takeDirectory path + 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" + B.hPutStr h $ "" + B.hPutStr h $ "\n" -- cgit v1.2.3