on master help sign in
Make testing fixes a bit less fancy
commit9b065020ed3c37b9d4d7be8c96cf71b092bf3877 authorEvan Czaplicki <info@elm-lang.org> dateThu 21 May 2015, 05:59 (11 years ago) parent08566b3
2 files changed+25−17
elm-compiler.cabal+1−4 tests/Test/Compiler.hs+24−13
elm-compiler.cabal+1−4
@@ -217,7 +217,4 @@ Test-Suite compiler-tests
217217 process,
218218 text >= 1 && < 2,
219219 transformers >= 0.2 && < 0.5,
220− union-find >= 0.2 && < 0.3,
221− unordered-containers >= 0.1 && < 0.3,
222− bifunctors >= 4.2.1
223−
220+ union-find >= 0.2 && < 0.3
tests/Test/Compiler.hs+24−13
@@ -1,9 +1,9 @@
11{-# OPTIONS_GHC -W #-}
22module Test.Compiler (compilerTests) where
33
4+import Control.Arrow (second)
45import qualified Data.Map as Map
56import Data.Traversable (traverse)
6−import Data.Bifunctor (first, second)
77
88import System.FilePath ((</>))
99import System.FilePath.Find (find, (==?), extension)
@@ -15,7 +15,6 @@ import Test.HUnit (Assertion, assertFailure, assertBool)
1515import qualified Elm.Compiler as Compiler
1616import qualified Elm.Compiler.Module as Module
1717
18−type ErrorMessage = String
1918
2019compilerTests :: Test
2120compilerTests =
@@ -47,31 +46,43 @@ testsDir =
4746-- RUN COMPILER
4847
4948testIf
50− :: (([Compiler.Warning], Either [ErrorMessage] (Module.Interface, String)) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
5150 -> [FilePath]
5251 -> IO [Test]
5352testIf handleResult filePaths =
5453 traverse setupTest filePaths
5554 where
56− setupTest filePath = do
55+ setupTest filePath = do
5756 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))
6157
62− return $ testCase filePath (handleResult . errorsToStrings $ result)
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+
65+ return $ testCase filePath (handleResult formattedResult)
66+
6367
6468-- CHECK RESULTS
6569
66−isSuccess :: ([Compiler.Warning], Either [ErrorMessage] a) -> Assertion
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
6771isSuccess (_, result) =
6872 case result of
69− Right _ -> assertBool "" True
70− Left errorMessages -> assertFailure $ concat errorMessages
73+ Right _ ->
74+ assertBool "" True
75+
76+ Left errorMessages ->
77+ assertFailure errorMessages
7178
7279
7380isFailure :: ([Compiler.Warning], Either a b) -> Assertion
7481isFailure (_, result) =
7582 case result of
76− Right _ -> assertFailure "Compilation succeeded but should have failed"
77− Left _ -> assertBool "" True
83+ Right _ ->
84+ assertFailure "Compilation succeeded but should have failed"
85+
86+ Left _ ->
87+ assertBool "" True
88+