@@ -1,9 +1,9 @@
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)
6−import Data.Bifunctor (first, second)
77
88import System.FilePath ((</>))
99import System.FilePath.Find (find, (==?), extension)
@@ -15,7 +15,6 @@ import Test.HUnit (Assertion, assertFailure, assertBool)
1515import qualified Elm.Compiler as Compiler
1616import qualified Elm.Compiler.Module as Module
1717
18−type ErrorMessage = String
1918
2019compilerTests :: Test
2120compilerTests =
@@ -47,31 +46,43 @@ testsDir =
4746-- RUN COMPILER
4847
4948testIf
50− :: (([Compiler.Warning], Either [ErrorMessage] (Module.Interface, String)) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
5150 -> [FilePath]
5251 -> IO [Test]
5352testIf handleResult filePaths =
5453 traverse setupTest filePaths
5554 where
56− setupTest filePath = do
55+ setupTest filePath = do
5756 source <- readFile filePath
58−
59− let result = Compiler.compile "elm-lang" "core" True source Map.empty
60− let errorsToStrings = second (first $ map (Compiler.errorToString filePath source))
6157
62− return $ testCase filePath (handleResult . errorsToStrings $ result)
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)
66+
6367
6468-- CHECK RESULTS
6569
66−isSuccess :: ([Compiler.Warning], Either [ErrorMessage] a) -> Assertion
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
6771isSuccess (_, result) =
6872 case result of
69− Right _ -> assertBool "" True
70− Left errorMessages -> assertFailure $ concat errorMessages
73+ Right _ ->
74+ assertBool "" True
75+
76+ Left errorMessages ->
77+ assertFailure errorMessages
7178
7279
7380isFailure :: ([Compiler.Warning], Either a b) -> Assertion
7481isFailure (_, result) =
7582 case result of
76− Right _ -> assertFailure "Compilation succeeded but should have failed"
77− Left _ -> assertBool "" True
83+ Right _ ->
84+ assertFailure "Compilation succeeded but should have failed"
85+
86+ Left _ ->
87+ assertBool "" True
88+