@@ -1,9 +1,9 @@
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)
6−import Data.Bifunctor (first, second)
8import System.FilePath ((</>))
8import System.FilePath ((</>))
9import System.FilePath.Find (find, (==?), extension)
9import System.FilePath.Find (find, (==?), extension)
@@ -15,7 +15,6 @@ import Test.HUnit (Assertion, assertFailure, assertBool)
15import qualified Elm.Compiler as Compiler
15import qualified Elm.Compiler as Compiler
16import qualified Elm.Compiler.Module as Module
16import qualified Elm.Compiler.Module as Module
18−type ErrorMessage = String
20compilerTests :: Test
19compilerTests :: Test
21compilerTests =
20compilerTests =
@@ -47,31 +46,43 @@ testsDir =
47-- RUN COMPILER
46-- RUN COMPILER
50− :: (([Compiler.Warning], Either [ErrorMessage] (Module.Interface, String)) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
51 -> [FilePath]
50 -> [FilePath]
52 -> IO [Test]
51 -> IO [Test]
53testIf handleResult filePaths =
52testIf handleResult filePaths =
54 traverse setupTest filePaths
53 traverse setupTest filePaths
56− setupTest filePath = do
55+ setupTest filePath = do
57 source <- readFile filePath
56 source <- readFile filePath
59− let result = Compiler.compile "elm-lang" "core" True source Map.empty
60− let errorsToStrings = second (first $ map (Compiler.errorToString filePath source))
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
62− return $ testCase filePath (handleResult . errorsToStrings $ result)
65+ return $ testCase filePath (handleResult formattedResult)
64-- CHECK RESULTS
68-- CHECK RESULTS
66−isSuccess :: ([Compiler.Warning], Either [ErrorMessage] a) -> Assertion
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
67isSuccess (_, result) =
71isSuccess (_, result) =
68 case result of
72 case result of
69− Right _ -> assertBool "" True
74+ assertBool "" True
76+ Left errorMessages ->
70− Left errorMessages -> assertFailure $ concat errorMessages
77+ assertFailure errorMessages
73isFailure :: ([Compiler.Warning], Either a b) -> Assertion
80isFailure :: ([Compiler.Warning], Either a b) -> Assertion
74isFailure (_, result) =
81isFailure (_, result) =
75 case result of
82 case result of
76− Right _ -> assertFailure "Compilation succeeded but should have failed"
84+ assertFailure "Compilation succeeded but should have failed"
77− Left _ -> assertBool "" True
87+ assertBool "" True