@@ -3,6 +3,7 @@ module Test.Compiler (compilerTests) where
4import qualified Data.Map as Map
4import qualified Data.Map as Map
5import Data.Traversable (traverse)
5import Data.Traversable (traverse)
6+import Data.Bifunctor (first, second)
7import System.FilePath ((</>))
8import System.FilePath ((</>))
8import System.FilePath.Find (find, (==?), extension)
9import System.FilePath.Find (find, (==?), extension)
@@ -14,6 +15,8 @@ import Test.HUnit (Assertion, assertFailure, assertBool)
14import qualified Elm.Compiler as Compiler
15import qualified Elm.Compiler as Compiler
15import qualified Elm.Compiler.Module as Module
16import qualified Elm.Compiler.Module as Module
18+type ErrorMessage = String
17compilerTests :: Test
20compilerTests :: Test
18compilerTests =
21compilerTests =
19 buildTest $ do
22 buildTest $ do
@@ -44,25 +47,27 @@ testsDir =
44-- RUN COMPILER
47-- RUN COMPILER
47− :: (([Compiler.Warning], Either [Compiler.Error] (Module.Interface, String)) -> Assertion)
50+ :: (([Compiler.Warning], Either [ErrorMessage] (Module.Interface, String)) -> Assertion)
48 -> [FilePath]
51 -> [FilePath]
49 -> IO [Test]
52 -> IO [Test]
50testIf handleResult filePaths =
53testIf handleResult filePaths =
51 traverse setupTest filePaths
54 traverse setupTest filePaths
53− setupTest filePath =
56+ setupTest filePath = do
54− do source <- readFile filePath
57+ source <- readFile filePath
55− let result = Compiler.compile "elm-lang" "core" True source Map.empty
59+ let result = Compiler.compile "elm-lang" "core" True source Map.empty
56− return (testCase filePath (handleResult result))
60+ let errorsToStrings = second (first $ map (Compiler.errorToString filePath source))
62+ return $ testCase filePath (handleResult . errorsToStrings $ result)
59-- CHECK RESULTS
64-- CHECK RESULTS
61−isSuccess :: ([Compiler.Warning], Either [Compiler.Error] a) -> Assertion
66+isSuccess :: ([Compiler.Warning], Either [ErrorMessage] a) -> Assertion
62isSuccess (_, result) =
67isSuccess (_, result) =
63 case result of
68 case result of
64 Right _ -> assertBool "" True
69 Right _ -> assertBool "" True
65− Left errors -> assertFailure $ (unlines $ map (Compiler.errorToString "" "") errors)
70+ Left errorMessages -> assertFailure $ concat errorMessages
68isFailure :: ([Compiler.Warning], Either a b) -> Assertion
73isFailure :: ([Compiler.Warning], Either a b) -> Assertion