@@ -1,6 +1,7 @@
11{-# OPTIONS_GHC -W #-}
22module Test.Compiler (compilerTests) where
33
4+import Control.Arrow (second)
45import qualified Data.Map as Map
56import Data.Traversable (traverse)
67
@@ -45,29 +46,43 @@ testsDir =
4546-- RUN COMPILER
4647
4748testIf
48− :: (Either String (Module.Interface, String) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
4950 -> [FilePath]
5051 -> IO [Test]
5152testIf handleResult filePaths =
5253 traverse setupTest filePaths
5354 where
54− setupTest filePath =
55− do source <- readFile filePath
56− let result = Compiler.compile "elm-lang" "core" source Map.empty
57− return (testCase filePath (handleResult result))
55+ setupTest filePath = do
56+ source <- readFile filePath
57+
58+ let result =
59+ Compiler.compile "elm-lang" "core" True source Map.empty
60+ let formatErrors errors =
61+ concatMap (Compiler.errorToString filePath source) errors
62+ let formattedResult =
63+ second (either (Left . formatErrors) Right) result
64+
65+ return $ testCase filePath (handleResult formattedResult)
5866
5967
6068-- CHECK RESULTS
6169
62−isSuccess :: Either String a -> Assertion
63−isSuccess result =
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
71+isSuccess (_, result) =
6472 case result of
65− Right _ -> assertBool "" True
66− Left msg -> assertFailure msg
73+ Right _ ->
74+ assertBool "" True
75+
76+ Left errorMessages ->
77+ assertFailure errorMessages
6778
6879
69−isFailure :: Either a b -> Assertion
70−isFailure result =
80+isFailure :: ([Compiler.Warning], Either a b) -> Assertion
81+isFailure (_, result) =
7182 case result of
72− Right _ -> assertFailure "Compilation succeeded but should have failed"
73− Left _ -> assertBool "" True
83+ Right _ ->
84+ assertFailure "Compilation succeeded but should have failed"
85+
86+ Left _ ->
87+ assertBool "" True
88+