git.iko.soy/rowtype-yoga/purescript-native
on ebbc4e4 help sign in
120 lines 3.9 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.Directory
24-------------------------------------------------------------------------------
25testsDir :: IO (FilePath, FilePath)
26-------------------------------------------------------------------------------
27testsDir = do
28 baseDir <- getCurrentDirectory
29 return (baseDir </> "pcc-tests", baseDir)
31-------------------------------------------------------------------------------
32main :: IO ()
33-------------------------------------------------------------------------------
34main = do
36 (outputDir, baseDir) <- testsDir
38 outputDirExists <- doesDirectoryExist outputDir
39 when outputDirExists $ removeDirectoryRecursive outputDir
40 createDirectory outputDir
42 fetchPackages
44 let srcDir = outputDir </> "src"
45 createDirectory srcDir
47 let passingDir = baseDir </> "examples" </> "passing"
48 passingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents passingDir
50 -- Auto-generate Makefile
51 setCurrentDirectory outputDir
52 callProcess "../.cabal-sandbox/bin/pcc" []
54 let tests = filter (`notElem` skipped) passingTestCases
56 -- Run the tests
57 --
58 forM_ tests $ \inputFile -> do
59 --
60 -- Compile/build
61 --
62 putStrLn $ "Compiling test " ++ inputFile ++ " ..."
63 setCurrentDirectory outputDir
64 copyFile (passingDir </> inputFile) (srcDir </> inputFile)
65 callProcess "make" ["clean"]
66 callProcess "make" ["debug"]
67 --
68 -- Run C++ files
69 --
70 callProcess ("output" </> "bin" </> "main") []
72 removeFile (srcDir </> inputFile)
74 -- TODO: support failing test cases
75 --
76 -- let failing = baseDir </> "examples" </> "failing"
77 -- failingTestCases <- sort . filter (".purs" `isSuffixOf`) <$> getDirectoryContents failing
78 --
80 setCurrentDirectory baseDir
81 putStrLn "pcc-tests finished"
82 putStrLn $ "Total tests available: " ++ show (length passingTestCases)
83 putStrLn $ "Tests run: " ++ show (length tests)
84 putStrLn $ "Tests skipped: " ++ show (length skipped)
86-------------------------------------------------------------------------------
87repo :: String
88-------------------------------------------------------------------------------
89repo = "git://github.com/pure11/"
91-------------------------------------------------------------------------------
92packages :: [(String, String)]
93-------------------------------------------------------------------------------
94packages =
95 [ ("purescript-eff", "")
96 , ("purescript-prelude", "")
97 , ("purescript-assert", "")
98 , ("purescript-st", "")
99 , ("purescript-console", "")
100 , ("purescript-functions", "")
101 ]
103-------------------------------------------------------------------------------
104fetchPackages :: IO ()
105-------------------------------------------------------------------------------
106fetchPackages = do
107 (outputDir, baseDir) <- testsDir
108 let packageDir = outputDir </> "packages"
109 createDirectory packageDir
110 setCurrentDirectory packageDir
111 forM_ packages $ \package -> let branch = snd package in
112 callProcess "git" $ ["clone"] ++ (if null branch then [] else ["--branch", branch]) ++ [repo ++ (fst package) ++ ".git"]
113 setCurrentDirectory baseDir
115-------------------------------------------------------------------------------
116skipped :: [String]
117-------------------------------------------------------------------------------
118skipped =
119 [ "ExplicitImportReExport.purs" -- OK, test has no main (would pass otherwise)
120 ]