on master help sign in
Make testing fixes a bit less fancy
9b06502Evan Czaplicki
elm-compiler.cabal+1−4
@@ -217,7 +217,4 @@ Test-Suite compiler-tests
217 process,
217 process,
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,
222− bifunctors >= 4.2.1
223−
tests/Test/Compiler.hs+24−13
@@ -1,9 +1,9 @@
1{-# OPTIONS_GHC -W #-}
1{-# OPTIONS_GHC -W #-}
2module Test.Compiler (compilerTests) where
2module Test.Compiler (compilerTests) where
3
3
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)
7
7
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
17
17
18−type ErrorMessage = String
19
18
20compilerTests :: Test
19compilerTests :: Test
21compilerTests =
20compilerTests =
@@ -47,31 +46,43 @@ testsDir =
47-- RUN COMPILER
46-- RUN COMPILER
48
47
49testIf
48testIf
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
55 where
54 where
56− setupTest filePath = do
55+ setupTest filePath = do
57 source <- readFile filePath
56 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))
61
57
58+ let result =
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
64+
62− return $ testCase filePath (handleResult . errorsToStrings $ result)
65+ return $ testCase filePath (handleResult formattedResult)
66+
63
67
64-- CHECK RESULTS
68-- CHECK RESULTS
65
69
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
73+ Right _ ->
69− Right _ -> assertBool "" True
74+ assertBool "" True
75+
76+ Left errorMessages ->
70− Left errorMessages -> assertFailure $ concat errorMessages
77+ assertFailure errorMessages
71
78
72
79
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
83+ Right _ ->
76− Right _ -> assertFailure "Compilation succeeded but should have failed"
84+ assertFailure "Compilation succeeded but should have failed"
85+
86+ Left _ ->
77− Left _ -> assertBool "" True
87+ assertBool "" True
88+