module Test (runTests) where import Control.Monad (when) import Control.Applicative ((<$>)) import System.IO import System.Cmd import System.Directory import System.Process (readProcess) import System.FilePath import System.FilePath.Glob runTests :: FilePath -> FilePath -> FilePath -> IO () runTests compiler prelude dir = do testFiles <- filter (\path -> path !! 0 /= '.') <$> globDir1 (compile "*.test") dir mapM_ (runTest compiler prelude) testFiles putStrLn "All tests passed" runTest :: FilePath -> FilePath -> FilePath -> IO () runTest compiler prelude testFile = do let executable = "/tmp/" `combine` takeBaseName testFile rawSystem compiler [testFile, "--prelude", prelude, "-o", executable] result <- read <$> readProcess executable [] "" expectedResult <- read <$> readFile (replaceExtension testFile "result") when ( (result :: Int) /= expectedResult ) $ error $ "Expected " ++ show expectedResult ++ " but got " ++ show result main = runTests "dist/build/lambdapic/lambdapic" "Prelude.lp" "tests"