pathtype-0.5.4.3: tool/CreateTest.hs
module Main where
import Control.Applicative ((<$>))
import Data.List (stripPrefix, isInfixOf)
import Data.Maybe (mapMaybe)
import Text.Printf (printf)
srcfiles :: [String]
template, testModule, tok, testPrefix :: String
srcfiles =
map ("src/System/Path/" ++) $
["Internal.hs", "Directory.hs", "IO.hs"]
template = "test/TestTemplate.hs"
testModule = "test/TestResult.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