@@ -9,23 +9,33 @@ import Test.DocTest
99main :: IO ()
1010main = do
1111 files <- find always (extension ==? ".hs") "src"
12− cabalMacrosFile <- getCabalMacrosFile
13− doctest $ [ "-isrc"
14− , "-optP-include"
15− , "-optP" ++ cabalMacrosFile
16− , "-XOverloadedStrings"
17− , "-XFlexibleInstances"
18− , "-XMultiParamTypeClasses"
19− , "-XDataKinds"
20− , "-XTypeOperators"
21− ] ++ files
12+ mCabalMacrosFile <- getCabalMacrosFile
13+ doctest $ "-isrc" :
14+ (maybe [] (\ f -> ["-optP-include", "-optP" ++ f]) mCabalMacrosFile) ++
15+ "-XOverloadedStrings" :
16+ "-XFlexibleInstances" :
17+ "-XMultiParamTypeClasses" :
18+ "-XDataKinds" :
19+ "-XTypeOperators" :
20+ files
2221
23−getCabalMacrosFile :: IO FilePath
22+getCabalMacrosFile :: IO (Maybe FilePath)
2423getCabalMacrosFile = do
25− contents <- getDirectoryContents "dist"
26− let rest = "build" </> "autogen" </> "cabal_macros.h"
27− return $ case filter ("dist-sandbox-" `isPrefixOf`) contents of
28− [x] -> "dist" </> x </> rest
29− [] -> "dist" </> rest
30− xs -> error $ "ran doctests with multiple dist/dist-sandbox-xxxxx's: \n"
31− ++ show xs ++ "\nTry cabal clean"
24+ exists <- doesDirectoryExist "dist"
25+ if exists
26+ then do
27+ contents <- getDirectoryContents "dist"
28+ let rest = "build" </> "autogen" </> "cabal_macros.h"
29+ whenExists $ case filter ("dist-sandbox-" `isPrefixOf`) contents of
30+ [x] -> "dist" </> x </> rest
31+ [] -> "dist" </> rest
32+ xs -> error $ "ran doctests with multiple dist/dist-sandbox-xxxxx's: \n"
33+ ++ show xs ++ "\nTry cabal clean"
34+ else return Nothing
35+ where
36+ whenExists :: FilePath -> IO (Maybe FilePath)
37+ whenExists file = do
38+ exists <- doesFileExist file
39+ return $ if exists
40+ then Just file
41+ else Nothing