servant/servant-server/test/Doctests.hs

42 lines
1.3 KiB
Haskell
Raw Normal View History

2015-05-03 01:27:48 +02:00
module Main where
import Data.List (isPrefixOf)
2015-05-14 13:47:39 +02:00
import System.Directory
import System.FilePath
2015-05-03 01:27:48 +02:00
import System.FilePath.Find
import Test.DocTest
main :: IO ()
main = do
files <- find always (extension ==? ".hs") "src"
2015-07-25 11:22:05 +02:00
mCabalMacrosFile <- getCabalMacrosFile
doctest $ "-isrc" :
(maybe [] (\ f -> ["-optP-include", "-optP" ++ f]) mCabalMacrosFile) ++
"-XOverloadedStrings" :
"-XFlexibleInstances" :
"-XMultiParamTypeClasses" :
"-XDataKinds" :
"-XTypeOperators" :
files
2015-05-03 01:27:48 +02:00
2015-07-25 11:22:05 +02:00
getCabalMacrosFile :: IO (Maybe FilePath)
2015-05-14 13:47:39 +02:00
getCabalMacrosFile = do
2015-07-25 11:22:05 +02:00
exists <- doesDirectoryExist "dist"
if exists
then do
contents <- getDirectoryContents "dist"
let rest = "build" </> "autogen" </> "cabal_macros.h"
whenExists $ case filter ("dist-sandbox-" `isPrefixOf`) contents of
[x] -> "dist" </> x </> rest
[] -> "dist" </> rest
xs -> error $ "ran doctests with multiple dist/dist-sandbox-xxxxx's: \n"
++ show xs ++ "\nTry cabal clean"
else return Nothing
where
whenExists :: FilePath -> IO (Maybe FilePath)
whenExists file = do
exists <- doesFileExist file
return $ if exists
then Just file
else Nothing