on master help sign in
Refactor testIf so that compiler errors are printed correctly.
37e4dfeJustin Manley
elm-compiler.cabal+2−1
@@ -218,5 +218,6 @@ Test-Suite compiler-tests
218 text >= 1 && < 2,
218 text >= 1 && < 2,
219 transformers >= 0.2 && < 0.5,
219 transformers >= 0.2 && < 0.5,
220 union-find >= 0.2 && < 0.3,
220 union-find >= 0.2 && < 0.3,
221− unordered-containers >= 0.1 && < 0.3
221+ unordered-containers >= 0.1 && < 0.3,
222+ bifunctors >= 4.2.1
222
223
tests/Test/Compiler.hs+12−7
@@ -3,6 +3,7 @@ module Test.Compiler (compilerTests) where
3
3
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)
6
7
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
16
17
18+type ErrorMessage = String
19+
17compilerTests :: Test
20compilerTests :: Test
18compilerTests =
21compilerTests =
19 buildTest $ do
22 buildTest $ do
@@ -44,25 +47,27 @@ testsDir =
44-- RUN COMPILER
47-- RUN COMPILER
45
48
46testIf
49testIf
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
52 where
55 where
53− setupTest filePath =
56+ setupTest filePath = do
54− do source <- readFile filePath
57+ source <- readFile filePath
58+
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))
57
61
62+ return $ testCase filePath (handleResult . errorsToStrings $ result)
58
63
59-- CHECK RESULTS
64-- CHECK RESULTS
60
65
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
66
71
67
72
68isFailure :: ([Compiler.Warning], Either a b) -> Assertion
73isFailure :: ([Compiler.Warning], Either a b) -> Assertion