on master help sign in
Merge branch 'pr/941'
a822e24Evan Czaplicki
elm-compiler.cabal+2−4
@@ -186,7 +186,7 @@ Test-Suite compiler-tests
186 Test.Property.Arbitrary
186 Test.Property.Arbitrary
187 AST.Helpers
187 AST.Helpers
188 AST.Literal
188 AST.Literal
189− AST.PrettyPrint
189+ Reporting.PrettyPrint
190
190
191 build-depends:
191 build-depends:
192 test-framework > 0.8 && < 0.9,
192 test-framework > 0.8 && < 0.9,
@@ -217,6 +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−
tests/Test.hs+3−3
@@ -3,12 +3,12 @@ module Main where
3import Test.Framework
3import Test.Framework
4
4
5import Test.Compiler
5import Test.Compiler
6−import Test.Property
6+--import Test.Property
7
7
8
8
9−main :: IO ()
9+main :: IO ()
10main =
10main =
11 defaultMain
11 defaultMain
12 [ compilerTests
12 [ compilerTests
13− , propertyTests
13+-- , propertyTests
14 ]
14 ]
tests/Test/Compiler.hs+28−13
@@ -1,6 +1,7 @@
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
7
@@ -45,29 +46,43 @@ testsDir =
45-- RUN COMPILER
46-- RUN COMPILER
46
47
47testIf
48testIf
48− :: (Either String (Module.Interface, String) -> Assertion)
49+ :: (([Compiler.Warning], Either String (Module.Interface, String)) -> Assertion)
49 -> [FilePath]
50 -> [FilePath]
50 -> IO [Test]
51 -> IO [Test]
51testIf handleResult filePaths =
52testIf handleResult filePaths =
52 traverse setupTest filePaths
53 traverse setupTest filePaths
53 where
54 where
54− setupTest filePath =
55+ setupTest filePath = do
55− do source <- readFile filePath
56+ source <- readFile filePath
57+
58+ let result =
56− let result = Compiler.compile "elm-lang" "core" source Map.empty
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+
57− return (testCase filePath (handleResult result))
65+ return $ testCase filePath (handleResult formattedResult)
58
66
59
67
60-- CHECK RESULTS
68-- CHECK RESULTS
61
69
62−isSuccess :: Either String a -> Assertion
70+isSuccess :: ([Compiler.Warning], Either String a) -> Assertion
63−isSuccess result =
71+isSuccess (_, result) =
64 case result of
72 case result of
73+ Right _ ->
65− Right _ -> assertBool "" True
74+ assertBool "" True
75+
76+ Left errorMessages ->
66− Left msg -> assertFailure msg
77+ assertFailure errorMessages
67
78
68
79
69−isFailure :: Either a b -> Assertion
80+isFailure :: ([Compiler.Warning], Either a b) -> Assertion
70−isFailure result =
81+isFailure (_, result) =
71 case result of
82 case result of
83+ Right _ ->
72− Right _ -> assertFailure "Compilation succeeded but should have failed"
84+ assertFailure "Compilation succeeded but should have failed"
85+
86+ Left _ ->
73− Left _ -> assertBool "" True
87+ assertBool "" True
88+
tests/Test/Property.hs+1−1
@@ -12,7 +12,7 @@ import Text.PrettyPrint as P
12import AST.Literal as Lit
12import AST.Literal as Lit
13import qualified AST.Pattern as P
13import qualified AST.Pattern as P
14import qualified AST.Variable as V
14import qualified AST.Variable as V
15−import AST.PrettyPrint (Pretty, pretty)
15+import Reporting.PrettyPrint (Pretty, pretty)
16import Parse.Helpers (IParser, iParse)
16import Parse.Helpers (IParser, iParse)
17import Parse.Literal (literal)
17import Parse.Literal (literal)
18import qualified Parse.Pattern as Pat (expr)
18import qualified Parse.Pattern as Pat (expr)
tests/test-files/good/Ports.elm+11−11
@@ -1,21 +1,21 @@
1
1
2-- incoming
2-- incoming
3−input userID : String
3+port userID : String
4−input number : Int
4+port number : Int
5−input tuple : (Float,Bool)
5+port tuple : (Float,Bool)
6−input array : List Int
6+port array : List Int
7−input record : { x:Float, y:Float }
7+port record : { x:Float, y:Float }
8
8
9-- outgoing
9-- outgoing
10−output fortyTwo : Int
10+port fortyTwo : Int
11−output fortyTwo =
11+port fortyTwo =
12 42
12 42
13
13
14
14
15−output time : Float
15+port time : Float
16−output time =
16+port time =
17 3.14
17 3.14
18
18
19−output students : List { name:String, age:Int }
19+port students : List { name:String, age:Int }
20−output students =
20+port students =
21 [ { name = "Tom", age = 42 } ]
21 [ { name = "Tom", age = 42 } ]
tests/test-files/good/PortsWithTypeAliases.elm+2−2
@@ -7,7 +7,7 @@ type alias Point x y =
7 { x:x, y:y }
7 { x:x, y:y }
8
8
9
9
10−input points : Point2D
10+port points : Point2D
11
11
12
12
13−input pairs : Point String String
13+port pairs : Point String String