-- similar to the test runner as in HList module Main where import Control.Exception import System.FilePath import Test.Hspec import System.Process import System.Exit import System.Directory import Data.Maybe import Control.Monad import Control.Applicative main = do es <- getDirectoryContents "examples" putStrLn "Candidate tests" print es -- very dumb es <- filterM (\e -> allM [return (takeExtension e == ".hs"), doesFileExist (dropExtension ("examples"e) ++ ".ref")]) es putStrLn "\nSelected tests" print es hspec $ do mapM_ runghcwith es runghcwith f = describe f $ it "ok" $ checkResult $ do let ex = ("examples" ) let inFile = ex (takeBaseName f) outFile = dropExtension inFile ++ ".out" refFile = dropExtension inFile ++ ".ref" (ec, stdout, stderr) <- readProcessWithExitCode "cabal" ["repl","-v0", "--ghc-options", "-w -fcontext-stack=50 -iexamples -v0 "] (":set -package lens\n\ \:load " ++ inFile ++ "\nmain\n") writeFile outFile stdout ofe <- doesFileExist refFile diff <- if ofe then fmap Just $ readProcess "diff" ["-b", outFile, refFile] "" else return Nothing return (ec, stderr, diff) where checkResult io = blankStdout io `shouldReturn` (ExitSuccess, (), Just "") blankStdout x = fmap (\(a,b,c) -> (a, (), c)) x allM [] = return True allM (x:xs) = do x <- x if x then allM xs else return False