@@ -3,6 +3,7 @@ module Test.Compiler (compilerTests) where
33
44import qualified Data.Map as Map
55import Data.Traversable (traverse)
6+import Data.Bifunctor (first, second)
67
78import System.FilePath ((</>))
89import System.FilePath.Find (find, (==?), extension)
@@ -14,6 +15,8 @@ import Test.HUnit (Assertion, assertFailure, assertBool)
1415import qualified Elm.Compiler as Compiler
1516import qualified Elm.Compiler.Module as Module
1617
18+type ErrorMessage = String
19+
1720compilerTests :: Test
1821compilerTests =
1922 buildTest $ do
@@ -44,25 +47,27 @@ testsDir =
4447-- RUN COMPILER
4548
4649testIf
47− :: (([Compiler.Warning], Either [Compiler.Error] (Module.Interface, String)) -> Assertion)
50+ :: (([Compiler.Warning], Either [ErrorMessage] (Module.Interface, String)) -> Assertion)
4851 -> [FilePath]
4952 -> IO [Test]
5053testIf handleResult filePaths =
5154 traverse setupTest filePaths
5255 where
53− setupTest filePath =
54− do source <- readFile filePath
55− let result = Compiler.compile "elm-lang" "core" True source Map.empty
56− return (testCase filePath (handleResult result))
56+ setupTest filePath = do
57+ 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))
5761
62+ return $ testCase filePath (handleResult . errorsToStrings $ result)
5863
5964-- CHECK RESULTS
6065
61−isSuccess :: ([Compiler.Warning], Either [Compiler.Error] a) -> Assertion
66+isSuccess :: ([Compiler.Warning], Either [ErrorMessage] a) -> Assertion
6267isSuccess (_, result) =
6368 case result of
6469 Right _ -> assertBool "" True
65− Left errors -> assertFailure $ (unlines $ map (Compiler.errorToString "" "") errors)
70+ Left errorMessages -> assertFailure $ concat errorMessages
6671
6772
6873isFailure :: ([Compiler.Warning], Either a b) -> Assertion