git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make tests work again
44028b3Phil Freeman
src/Language/PureScript/Errors.hs+5
@@ -43,6 +43,7 @@ import qualified Text.Parsec as P
43--
43--
44data ErrorMessage
44data ErrorMessage
45 = ErrorParsingExterns P.ParseError
45 = ErrorParsingExterns P.ParseError
46+ | ErrorParsingPrelude P.ParseError
46 | InvalidExternsFile FilePath
47 | InvalidExternsFile FilePath
47 | CannotGetFileInfo FilePath
48 | CannotGetFileInfo FilePath
48 | CannotReadFile FilePath
49 | CannotReadFile FilePath
@@ -135,6 +136,7 @@ instance UnificationError Kind ErrorMessage where
135--
136--
136errorCode :: ErrorMessage -> String
137errorCode :: ErrorMessage -> String
137errorCode (ErrorParsingExterns _) = "ErrorParsingExterns"
138errorCode (ErrorParsingExterns _) = "ErrorParsingExterns"
139+errorCode (ErrorParsingPrelude _) = "ErrorParsingPrelude"
138errorCode (InvalidExternsFile _) = "InvalidExternsFile"
140errorCode (InvalidExternsFile _) = "InvalidExternsFile"
139errorCode (CannotGetFileInfo _) = "CannotGetFileInfo"
141errorCode (CannotGetFileInfo _) = "CannotGetFileInfo"
140errorCode (CannotReadFile _) = "CannotReadFile"
142errorCode (CannotReadFile _) = "CannotReadFile"
@@ -271,6 +273,9 @@ prettyPrintSingleError full e = prettyPrintErrorMessage (if full then e else sim
271 go (ErrorParsingExterns err) = paras [ line "Error parsing externs files: "
273 go (ErrorParsingExterns err) = paras [ line "Error parsing externs files: "
272 , indent . line . show $ err
274 , indent . line . show $ err
273 ]
275 ]
276+ go (ErrorParsingPrelude err) = paras [ line "Error parsing prelude: "
277+ , indent . line . show $ err
278+ ]
274 go (InvalidExternsFile path) = paras [ line "Externs file is invalid: "
279 go (InvalidExternsFile path) = paras [ line "Externs file is invalid: "
275 , indent . line $ path
280 , indent . line $ path
276 ]
281 ]
tests/Main.hs+8−8
@@ -35,21 +35,21 @@ readInput inputFiles = forM inputFiles $ \inputFile -> do
35 text <- readFile inputFile
35 text <- readFile inputFile
36 return (inputFile, text)
36 return (inputFile, text)
37
37
38−loadPrelude :: Either String (String, String, P.Environment)
38+loadPrelude :: Either P.MultipleErrors (String, String, P.Environment)
39loadPrelude =
39loadPrelude =
40 case P.parseModulesFromFiles id [("", P.prelude)] of
40 case P.parseModulesFromFiles id [("", P.prelude)] of
41− Left parseError -> Left (show parseError)
41+ Left parseError -> Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
42 Right ms -> runReaderT (P.compile (map snd ms) []) $ P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }
42 Right ms -> runReaderT (P.compile (map snd ms) []) $ P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }
43
43
44−compile :: P.Options P.Compile -> [FilePath] -> IO (Either String (String, String, P.Environment))
44+compile :: P.Options P.Compile -> [FilePath] -> IO (Either P.MultipleErrors (String, String, P.Environment))
45compile opts inputFiles = do
45compile opts inputFiles = do
46 modules <- P.parseModulesFromFiles id <$> readInput inputFiles
46 modules <- P.parseModulesFromFiles id <$> readInput inputFiles
47 case modules of
47 case modules of
48 Left parseError ->
48 Left parseError ->
49− return (Left $ show parseError)
49+ return . Left . P.errorMessage . P.ErrorParsingPrelude $ parseError
50 Right ms -> return $ runReaderT (P.compile (map snd ms) []) opts
50 Right ms -> return $ runReaderT (P.compile (map snd ms) []) opts
51
51
52−assert :: FilePath -> P.Options P.Compile -> FilePath -> (Either String (String, String, P.Environment) -> IO (Maybe String)) -> IO ()
52+assert :: FilePath -> P.Options P.Compile -> FilePath -> (Either P.MultipleErrors (String, String, P.Environment) -> IO (Maybe String)) -> IO ()
53assert preludeExterns opts inputFile f = do
53assert preludeExterns opts inputFile f = do
54 e <- compile opts [preludeExterns, inputFile]
54 e <- compile opts [preludeExterns, inputFile]
55 maybeErr <- f e
55 maybeErr <- f e
@@ -64,7 +64,7 @@ assertCompiles preludeJs preludeExterns inputFile = do
64 { P.optionsMain = Just "Main"
64 { P.optionsMain = Just "Main"
65 , P.optionsAdditional = P.CompileOptions "Tests" ["Main"] ["Main"]
65 , P.optionsAdditional = P.CompileOptions "Tests" ["Main"] ["Main"]
66 }
66 }
67− assert preludeExterns options inputFile $ either (return . Just) $ \(js, _, _) -> do
67+ assert preludeExterns options inputFile $ either (return . Just . P.prettyPrintMultipleErrors False) $ \(js, _, _) -> do
68 process <- findNodeProcess
68 process <- findNodeProcess
69 result <- traverse (\node -> readProcessWithExitCode node [] (preludeJs ++ js)) process
69 result <- traverse (\node -> readProcessWithExitCode node [] (preludeJs ++ js)) process
70 case result of
70 case result of
@@ -77,7 +77,7 @@ assertDoesNotCompile preludeExterns inputFile = do
77 putStrLn $ "Assert " ++ inputFile ++ " does not compile"
77 putStrLn $ "Assert " ++ inputFile ++ " does not compile"
78 assert preludeExterns (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }) inputFile $ \e ->
78 assert preludeExterns (P.defaultCompileOptions { P.optionsAdditional = P.CompileOptions "Tests" [] [] }) inputFile $ \e ->
79 case e of
79 case e of
80− Left err -> putStrLn err >> return Nothing
80+ Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> return Nothing
81 Right _ -> return $ Just "Should not have compiled"
81 Right _ -> return $ Just "Should not have compiled"
82
82
83findNodeProcess :: IO (Maybe String)
83findNodeProcess :: IO (Maybe String)
@@ -88,7 +88,7 @@ main :: IO ()
88main = do
88main = do
89 putStrLn "Compiling Prelude"
89 putStrLn "Compiling Prelude"
90 case loadPrelude of
90 case loadPrelude of
91− Left err -> putStrLn err >> exitFailure
91+ Left errs -> putStrLn (P.prettyPrintMultipleErrors False errs) >> exitFailure
92 Right (preludeJs, exts, _) -> do
92 Right (preludeJs, exts, _) -> do
93 tmp <- getTemporaryDirectory
93 tmp <- getTemporaryDirectory
94 let preludeExterns = tmp ++ pathSeparator : "prelude.externs"
94 let preludeExterns = tmp ++ pathSeparator : "prelude.externs"