------------------------------------------------------------------------------- -- -- Module : Main -- Copyright : (c) 2015 Andy Arvanitis and other contributors -- License : MIT -- -- Maintainer : Andy Arvanitis -- Stability : experimental -- Portability : -- -- -- ------------------------------------------------------------------------------- module Main where import Data.List import Control.Applicative import Control.Monad import System.Process import System.FilePath import System.IO import System.Directory ------------------------------------------------------------------------------- testsDir :: IO (FilePath, FilePath) ------------------------------------------------------------------------------- testsDir = do baseDir <- getCurrentDirectory return (baseDir "pcc-tests", baseDir) ------------------------------------------------------------------------------- main :: IO () ------------------------------------------------------------------------------- main = do (outputDir, baseDir) <- testsDir outputDirExists <- doesDirectoryExist outputDir when outputDirExists $ removeDirectoryRecursive outputDir createDirectory outputDir let srcDir = outputDir "src" createDirectory srcDir let passingDir = baseDir "examples" "passing" passingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents passingDir -- Auto-generate Makefile setCurrentDirectory outputDir callProcess "pcc" [] fetchPackages let tests = filter (`notElem` skipped) passingTestCases tmp <- getTemporaryDirectory createDirectoryIfMissing False (tmp logpath) outputFile <- openFile (tmp logpath logfile) WriteMode hClose outputFile -- Run the tests -- forM_ tests $ \inputFile -> do -- -- Compile/build -- putStrLn $ "Compiling test " ++ inputFile ++ " ..." setCurrentDirectory outputDir copyFile (passingDir inputFile) (srcDir inputFile) let testCaseDir = passingDir (takeWhile (/='.') inputFile) testCaseDirExists <- doesDirectoryExist testCaseDir when testCaseDirExists $ callProcess "cp" ["-R", testCaseDir, srcDir] callProcess "make" ["clean"] callProcess "make" ["debug"] -- -- Run C++ files -- outputFile <- openFile (tmp logpath logfile) AppendMode hPutStrLn outputFile ("\n" ++ inputFile ++ ":") proc <- runProcess ("output" "bin" "main") [] Nothing Nothing Nothing (Just outputFile) Nothing removeFile (srcDir inputFile) when testCaseDirExists $ callProcess "rm" ["-rf", srcDir (takeWhile (/='.') inputFile)] -- TODO: support failing test cases -- -- let failing = baseDir "examples" "failing" -- failingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents failing -- setCurrentDirectory baseDir putStrLn "pcc-tests finished" putStrLn $ "Total tests available: " ++ show (length passingTestCases) putStrLn $ "Tests run: " ++ show (length tests) putStrLn $ "Tests skipped: " ++ show (length skipped) ------------------------------------------------------------------------------- repo :: String ------------------------------------------------------------------------------- repo = "git://github.com/pure11/" ------------------------------------------------------------------------------- packages :: [String] ------------------------------------------------------------------------------- packages = [ "eff" , "prelude" , "assert" , "st" , "console" , "functions" , "partial" , "newtype" , "control" , "invariant" , "monoid" , "generics-rep" ] ------------------------------------------------------------------------------- fetchPackages :: IO () ------------------------------------------------------------------------------- fetchPackages = do mapM (callProcess "psc-package" . (\p -> ["install", p])) packages return () ------------------------------------------------------------------------------- skipped :: [String] ------------------------------------------------------------------------------- skipped = [ "NumberLiterals.purs" -- unreliable float comparison, test manually , "FunWithFunDeps.purs" -- requires FFI ] logpath :: FilePath logpath = "purescript-output" logfile :: FilePath logfile = "pcc-tests.out"