aboutsummaryrefslogtreecommitdiff
path: root/haddock-test/src/Test
diff options
context:
space:
mode:
Diffstat (limited to 'haddock-test/src/Test')
-rw-r--r--haddock-test/src/Test/Haddock.hs4
-rw-r--r--haddock-test/src/Test/Haddock/Utils.hs10
2 files changed, 13 insertions, 1 deletions
diff --git a/haddock-test/src/Test/Haddock.hs b/haddock-test/src/Test/Haddock.hs
index ab6ce775..18ae38ca 100644
--- a/haddock-test/src/Test/Haddock.hs
+++ b/haddock-test/src/Test/Haddock.hs
@@ -69,9 +69,11 @@ maybeDiff cfg@(Config { cfgDiffTool = (Just diff) }) files = do
runHaddock :: Config c -> IO ()
-runHaddock (Config { .. }) = do
+runHaddock cfg@(Config { .. }) = do
haddockStdOut <- openFile cfgHaddockStdOut WriteMode
+ createEmptyDirectory $ cfgOutDir cfg
+
putStrLn "Generating documentation..."
forM_ cfgPackages $ \tpkg -> do
handle <- runProcess' cfgHaddockPath $ processConfig
diff --git a/haddock-test/src/Test/Haddock/Utils.hs b/haddock-test/src/Test/Haddock/Utils.hs
index 4640fe97..4f97fa72 100644
--- a/haddock-test/src/Test/Haddock/Utils.hs
+++ b/haddock-test/src/Test/Haddock/Utils.hs
@@ -21,6 +21,10 @@ partitionM p (x:xs) = do
pure $ if b then (x:ss, fs) else (ss, x:fs)
+whenM :: Monad m => m Bool -> m () -> m ()
+whenM mb action = mb >>= \b -> when b action
+
+
getDirectoryTree :: FilePath -> IO [FilePath]
getDirectoryTree path = do
(dirs, files) <- partitionM isDirectory =<< contents
@@ -31,3 +35,9 @@ getDirectoryTree path = do
contents = filter realEntry <$> getDirectoryContents path
isDirectory entry = doesDirectoryExist $ path </> entry
realEntry entry = not $ entry == "." || entry == ".."
+
+
+createEmptyDirectory :: FilePath -> IO ()
+createEmptyDirectory path = do
+ whenM (doesDirectoryExist path) $ removeDirectoryRecursive path
+ createDirectory path