git.iko.soy/rowtype-yoga/purescript-native
on 136cd21 help sign in
70 lines 2.3 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Main
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15module Main (main) where
17import Language.PureScript
19import Data.List (isSuffixOf)
20import Control.Applicative
21import Control.Monad
22import System.Exit (exitSuccess, exitFailure)
23import System.FilePath (pathSeparator)
24import System.Directory (getCurrentDirectory, getDirectoryContents)
25import qualified System.IO.UTF8 as U
26import qualified Data.Map as M
28compile :: FilePath -> IO (Either String Environment)
29compile inputFile = do
30 ast <- runIndentParser parseDeclarations <$> U.readFile inputFile
31 case ast of
32 Left parseError -> do
33 return (Left $ show parseError)
34 Right decls -> do
35 case check (typeCheckAll decls) of
36 Left typeError -> do
37 return (Left typeError)
38 Right (_, env) -> do
39 return (Right env)
41assert :: FilePath -> (Either String Environment -> Maybe String) -> IO ()
42assert inputFile f = do
43 e <- compile inputFile
44 case f e of
45 Just err -> exitFailure
46 Nothing -> return ()
48assertCompiles :: FilePath -> IO ()
49assertCompiles inputFile = do
50 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
51 assert inputFile $ either Just (const Nothing)
53assertDoesNotCompile :: FilePath -> IO ()
54assertDoesNotCompile inputFile = do
55 putStrLn $ "assert " ++ inputFile ++ " does not compile"
56 assert inputFile $ either (const Nothing) (const $ Just "Should not have compiled")
58main :: IO ()
59main = do
60 cd <- getCurrentDirectory
61 let examples = cd ++ pathSeparator : "examples"
62 let passing = examples ++ pathSeparator : "passing"
63 passingTestCases <- getDirectoryContents passing
64 forM_ passingTestCases $ \inputFile -> when (".ps" `isSuffixOf` inputFile) $
65 assertCompiles (passing ++ pathSeparator : inputFile)
66 let failing = examples ++ pathSeparator : "failing"
67 failingTestCases <- getDirectoryContents failing
68 forM_ failingTestCases $ \inputFile -> when (".ps" `isSuffixOf` inputFile) $
69 assertDoesNotCompile (failing ++ pathSeparator : inputFile)
70 exitSuccess