on master help sign in
Merge branch 'pr/941'
commita822e24b78a5010fe41e8a739457757030e05eb8 authorEvan Czaplicki <info@elm-lang.org> dateThu 21 May 2015, 05:59 (11 years ago) parent0537abb9b06502
6 files changed+47−34
elm-compiler.cabal+2−4 tests/Test.hs+3−3 tests/Test/Compiler.hs+28−13 tests/Test/Property.hs+1−1 tests/test-files/good/Ports.elm+11−11 tests/test-files/good/PortsWithTypeAliases.elm+2−2
elm-compiler.cabal+2−4
@@ -186,7 +186,7 @@ Test-Suite compiler-tests
186186 Test.Property.Arbitrary
187187 AST.Helpers
188188 AST.Literal
189− AST.PrettyPrint
189+ Reporting.PrettyPrint
190190
191191 build-depends:
192192 test-framework > 0.8 && < 0.9,
@@ -217,6 +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−
220+ union-find >= 0.2 && < 0.3
tests/Test.hs+3−3
@@ -3,12 +3,12 @@ module Main where
33import Test.Framework
44
55import Test.Compiler
6−import Test.Property
6+--import Test.Property
77
88
9−main :: IO ()
9+main :: IO ()
1010main =
1111 defaultMain
1212 [ compilerTests
13− , propertyTests
13+-- , propertyTests
1414 ]
tests/Test/Compiler.hs+28−13
@@ -1,6 +1,7 @@
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)
67
@@ -45,29 +46,43 @@ testsDir =
4546-- RUN COMPILER
4647
4748testIf
48− :: (Either String (Module.Interface, String) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
4950 -> [FilePath]
5051 -> IO [Test]
5152testIf handleResult filePaths =
5253 traverse setupTest filePaths
5354 where
54− setupTest filePath =
55− do source <- readFile filePath
56− let result = Compiler.compile "elm-lang" "core" source Map.empty
57− return (testCase filePath (handleResult result))
55+ setupTest filePath = do
56+ source <- readFile filePath
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+
65+ return $ testCase filePath (handleResult formattedResult)
5866
5967
6068-- CHECK RESULTS
6169
62−isSuccess :: Either String a -> Assertion
63−isSuccess result =
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
71+isSuccess (_, result) =
6472 case result of
65− Right _ -> assertBool "" True
66− Left msg -> assertFailure msg
73+ Right _ ->
74+ assertBool "" True
75+
76+ Left errorMessages ->
77+ assertFailure errorMessages
6778
6879
69−isFailure :: Either a b -> Assertion
70−isFailure result =
80+isFailure :: ([Compiler.Warning], Either a b) -> Assertion
81+isFailure (_, result) =
7182 case result of
72− Right _ -> assertFailure "Compilation succeeded but should have failed"
73− Left _ -> assertBool "" True
83+ Right _ ->
84+ assertFailure "Compilation succeeded but should have failed"
85+
86+ Left _ ->
87+ assertBool "" True
88+
tests/Test/Property.hs+1−1
@@ -12,7 +12,7 @@ import Text.PrettyPrint as P
1212import AST.Literal as Lit
1313import qualified AST.Pattern as P
1414import qualified AST.Variable as V
15−import AST.PrettyPrint (Pretty, pretty)
15+import Reporting.PrettyPrint (Pretty, pretty)
1616import Parse.Helpers (IParser, iParse)
1717import Parse.Literal (literal)
1818import qualified Parse.Pattern as Pat (expr)
tests/test-files/good/Ports.elm+11−11
@@ -1,21 +1,21 @@
11
22-- incoming
3−input userID : String
4−input number : Int
5−input tuple : (Float,Bool)
6−input array : List Int
7−input record : { x:Float, y:Float }
3+port userID : String
4+port number : Int
5+port tuple : (Float,Bool)
6+port array : List Int
7+port record : { x:Float, y:Float }
88
99-- outgoing
10−output fortyTwo : Int
11−output fortyTwo =
10+port fortyTwo : Int
11+port fortyTwo =
1212 42
1313
1414
15−output time : Float
16−output time =
15+port time : Float
16+port time =
1717 3.14
1818
19−output students : List { name:String, age:Int }
20−output students =
19+port students : List { name:String, age:Int }
20+port students =
2121 [ { name = "Tom", age = 42 } ]
tests/test-files/good/PortsWithTypeAliases.elm+2−2
@@ -7,7 +7,7 @@ type alias Point x y =
77 { x:x, y:y }
88
99
10−input points : Point2D
10+port points : Point2D
1111
1212
13−input pairs : Point String String
13+port pairs : Point String String