1-----------------------------------------------------------------------------
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
15{-# LANGUAGE DoAndIfThenElse #-}
17module Main (main) where
19import qualified Language.PureScript as P
21import Data.List (isSuffixOf)
22import Data.Traversable (traverse)
23import Control.Applicative
25import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
28import System.FilePath (pathSeparator)
29import System.Directory (getCurrentDirectory, getDirectoryContents, findExecutable)
30import System.Environment (getArgs)
31import Text.Parsec (ParseError)
32import qualified Paths_purescript as Paths
33import qualified System.IO.UTF8 as U
34import qualified Data.Map as M
36preludeFilename :: IO FilePath
37preludeFilename = Paths.getDataFileName "prelude/prelude.purs"
39readInput :: [FilePath] -> IO (Either ParseError [P.Module])
40readInput inputFiles = fmap (fmap concat . sequence) $ forM inputFiles $ \inputFile -> do
41 text <- U.readFile inputFile
42 return $ P.runIndentParser inputFile P.parseModules text
44compile :: P.Options -> [FilePath] -> IO (Either String String)
45compile opts inputFiles = do
46 modules <- readInput inputFiles
49 return (Left $ show parseError)
51 case P.compile opts ms of
53 return (Left typeError)
54 Right (js, _, _) -> do
57assert :: P.Options -> [FilePath] -> (Either String String -> IO (Maybe String)) -> IO ()
58assert opts inputFiles f = do
59 e <- compile opts inputFiles
62 Just err -> putStrLn err >> exitFailure
65assertCompiles :: FilePath -> IO ()
66assertCompiles inputFile = do
67 putStrLn $ "assert " ++ inputFile ++ " compiles successfully"
68 prelude <- preludeFilename
69 assert (P.defaultOptions { P.optionsMain = Just "Main", P.optionsNoOptimizations = True, P.optionsModules = ["Main"] }) [prelude, inputFile] $ either (return . Just) $ \js -> do
71 if "--run-js" `elem` args
73 process <- findNodeProcess
74 result <- traverse (\node -> readProcessWithExitCode node [] js) process
76 Just (ExitSuccess, out, _) -> putStrLn out >> return Nothing
77 Just (ExitFailure _, _, err) -> return $ Just err
78 Nothing -> return $ Just "Couldn't find node.js executable"
81findNodeProcess :: IO (Maybe String)
82findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
83 where names = ["nodejs", "node"]
85assertDoesNotCompile :: FilePath -> IO ()
86assertDoesNotCompile inputFile = do
87 putStrLn $ "assert " ++ inputFile ++ " does not compile"
88 assert P.defaultOptions [inputFile] $ \e ->
90 Left _ -> return Nothing
91 Right _ -> return $ Just "Should not have compiled"
95 cd <- getCurrentDirectory
97 let examples = cd ++ pathSeparator : "examples"
98 let passing = examples ++ pathSeparator : "passing"
99 passingTestCases <- getDirectoryContents passing
100 forM_ passingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
101 assertCompiles (passing ++ pathSeparator : inputFile)
102 let failing = examples ++ pathSeparator : "failing"
103 failingTestCases <- getDirectoryContents failing
104 forM_ failingTestCases $ \inputFile -> when (".purs" `isSuffixOf` inputFile) $
105 assertDoesNotCompile (failing ++ pathSeparator : inputFile)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list