@@ -1,6 +1,7 @@
1{-# OPTIONS_GHC -W #-}
1{-# OPTIONS_GHC -W #-}
2module Test.Compiler (compilerTests) where
2module Test.Compiler (compilerTests) where
4+import Control.Arrow (second)
4import qualified Data.Map as Map
5import qualified Data.Map as Map
5import Data.Traversable (traverse)
6import Data.Traversable (traverse)
@@ -45,29 +46,43 @@ testsDir =
45-- RUN COMPILER
46-- RUN COMPILER
48− :: (Either String (Module.Interface, String) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
49 -> [FilePath]
50 -> [FilePath]
50 -> IO [Test]
51 -> IO [Test]
51testIf handleResult filePaths =
52testIf handleResult filePaths =
52 traverse setupTest filePaths
53 traverse setupTest filePaths
54− setupTest filePath =
55+ setupTest filePath = do
55− do source <- readFile filePath
56+ source <- readFile filePath
56− let result = Compiler.compile "elm-lang" "core" source Map.empty
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
57− return (testCase filePath (handleResult result))
65+ return $ testCase filePath (handleResult formattedResult)
60-- CHECK RESULTS
68-- CHECK RESULTS
62−isSuccess :: Either String a -> Assertion
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
63−isSuccess result =
71+isSuccess (_, result) =
64 case result of
72 case result of
65− Right _ -> assertBool "" True
74+ assertBool "" True
76+ Left errorMessages ->
66− Left msg -> assertFailure msg
77+ assertFailure errorMessages
69−isFailure :: Either a b -> Assertion
80+isFailure :: ([Compiler.Warning], Either a b) -> Assertion
70−isFailure result =
81+isFailure (_, result) =
71 case result of
82 case result of
72− Right _ -> assertFailure "Compilation succeeded but should have failed"
84+ assertFailure "Compilation succeeded but should have failed"
73− Left _ -> assertBool "" True
87+ assertBool "" True