git.iko.soy/rowtype-yoga/purescript-native
on 67bfcd5 help sign in
142 lines 4.3 kB history raw
1-------------------------------------------------------------------------------
2--
3-- Module : Main
4-- Copyright : (c) 2015 Andy Arvanitis and other contributors
5-- License : MIT
6--
7-- Maintainer : Andy Arvanitis
8-- Stability : experimental
9-- Portability :
10--
11--
12--
13-------------------------------------------------------------------------------
14module Main where
16import Data.List
17import Control.Applicative
18import Control.Monad
20import System.Process
21import System.FilePath
22import System.IO
23import System.Directory
25-------------------------------------------------------------------------------
26testsDir :: IO (FilePath, FilePath)
27-------------------------------------------------------------------------------
28testsDir = do
29 baseDir <- getCurrentDirectory
30 return (baseDir </> "pcc-tests", baseDir)
32-------------------------------------------------------------------------------
33main :: IO ()
34-------------------------------------------------------------------------------
35main = do
37 (outputDir, baseDir) <- testsDir
39 outputDirExists <- doesDirectoryExist outputDir
40 when outputDirExists $ removeDirectoryRecursive outputDir
41 createDirectory outputDir
43 let srcDir = outputDir </> "src"
44 createDirectory srcDir
46 let passingDir = baseDir </> "examples" </> "passing"
47 passingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents passingDir
49 -- Auto-generate Makefile
50 setCurrentDirectory outputDir
51 callProcess "pcc" []
53 fetchPackages
55 let tests = filter (`notElem` skipped) passingTestCases
57 tmp <- getTemporaryDirectory
58 createDirectoryIfMissing False (tmp </> logpath)
59 outputFile <- openFile (tmp </> logpath </> logfile) WriteMode
60 hClose outputFile
62 -- Run the tests
63 --
64 forM_ tests $ \inputFile -> do
65 --
66 -- Compile/build
67 --
68 putStrLn $ "Compiling test " ++ inputFile ++ " ..."
69 setCurrentDirectory outputDir
70 copyFile (passingDir </> inputFile) (srcDir </> inputFile)
72 let testCaseDir = passingDir </> (takeWhile (/='.') inputFile)
73 testCaseDirExists <- doesDirectoryExist testCaseDir
74 when testCaseDirExists $ callProcess "cp" ["-R", testCaseDir, srcDir]
76 callProcess "make" ["clean"]
77 callProcess "make" ["debug"]
78 --
79 -- Run C++ files
80 --
81 outputFile <- openFile (tmp </> logpath </> logfile) AppendMode
82 hPutStrLn outputFile ("\n" ++ inputFile ++ ":")
83 proc <- runProcess ("output" </> "bin" </> "main") [] Nothing Nothing Nothing (Just outputFile) Nothing
85 removeFile (srcDir </> inputFile)
86 when testCaseDirExists $ callProcess "rm" ["-rf", srcDir </> (takeWhile (/='.') inputFile)]
88 -- TODO: support failing test cases
89 --
90 -- let failing = baseDir </> "examples" </> "failing"
91 -- failingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents failing
92 --
94 setCurrentDirectory baseDir
95 putStrLn "pcc-tests finished"
96 putStrLn $ "Total tests available: " ++ show (length passingTestCases)
97 putStrLn $ "Tests run: " ++ show (length tests)
98 putStrLn $ "Tests skipped: " ++ show (length skipped)
100-------------------------------------------------------------------------------
101repo :: String
102-------------------------------------------------------------------------------
103repo = "git://github.com/pure11/"
105-------------------------------------------------------------------------------
106packages :: [String]
107-------------------------------------------------------------------------------
108packages =
109 [ "eff"
110 , "prelude"
111 , "assert"
112 , "st"
113 , "console"
114 , "functions"
115 , "partial"
116 , "newtype"
117 , "control"
118 , "invariant"
119 , "monoid"
120 , "generics-rep"
121 ]
123-------------------------------------------------------------------------------
124fetchPackages :: IO ()
125-------------------------------------------------------------------------------
126fetchPackages = do
127 mapM (callProcess "psc-package" . (\p -> ["install", p])) packages
128 return ()
130-------------------------------------------------------------------------------
131skipped :: [String]
132-------------------------------------------------------------------------------
133skipped =
134 [ "NumberLiterals.purs" -- unreliable float comparison, test manually
135 , "FunWithFunDeps.purs" -- requires FFI
136 ]
138logpath :: FilePath
139logpath = "purescript-output"
141logfile :: FilePath
142logfile = "pcc-tests.out"