pathtype-0.5.4.2: Test.hs
module Main where
import Control.Monad (void)
import Control.Applicative ((<$>))
import Data.List (stripPrefix, isInfixOf)
import Data.Maybe (mapMaybe)
import System.Process (rawSystem)
import System.Exit (exitWith)
import Text.Printf (printf)
srcfiles :: [String]
template, testModule, tok, testPrefix :: String
srcfiles = ["System/Path/Internal.hs","System/Path/Directory.hs","System/Path/IO.hs"]
template = "TestTemplate.hs"
testModule = "TestModule.hs"
tok = "<TESTS_GO_HERE>"
testPrefix = "-- >> "
main :: IO ()
main = do
testLines <-
mapMaybe (stripPrefix testPrefix) . concatMap lines <$> mapM readFile srcfiles
(templateHead,_:templateTail) <-
break (tok `isInfixOf`) . lines <$> readFile template
let outLines = (\t -> printf " (%s,\n %s) :" (show t) t) <$> testLines
writeFile testModule $ unlines $
("{- Do not edit! Created from " ++ template ++ " -}") :
templateHead ++ outLines ++ templateTail
let ghc = "ghc"
args =
["-optP-include", "-optPdist/build/autogen/cabal_macros.h",
"-e", "TestModule.main", testModule]
void $ printf "Running %d tests...\n" (length testLines)
exitWith =<< rawSystem ghc args