on master help sign in
Refactor testIf so that compiler errors are printed correctly.
commit37e4dfe9ac482844c0e3ad546cb3caf469a9902d authorJustin Manley <manleyjster@gmail.com> dateWed 20 May 2015, 12:32 (11 years ago) parent9087bb7
2 files changed+14−8
elm-compiler.cabal+2−1 tests/Test/Compiler.hs+12−7
elm-compiler.cabal+2−1
@@ -218,5 +218,6 @@ Test-Suite compiler-tests
218218 text >= 1 && < 2,
219219 transformers >= 0.2 && < 0.5,
220220 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
222223
tests/Test/Compiler.hs+12−7
@@ -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