@@ -7,14 +7,15 @@ import System.FilePath ((</>))
7import System.FilePath.Find (find, (==?), extension)
7import System.FilePath.Find (find, (==?), extension)
8import Test.Framework
8import Test.Framework
9import Test.Framework.Providers.HUnit (testCase)
9import Test.Framework.Providers.HUnit (testCase)
10−import Test.HUnit ((@=?), Assertion)
10+import Test.HUnit (Assertion, assertFailure, assertBool)
11+import Text.Parsec (ParseError)
12import Elm.Internal.Utils as Elm
13import Elm.Internal.Utils as Elm
14compilerTests :: Test
15compilerTests :: Test
15compilerTests = buildTest $ do
16compilerTests = buildTest $ do
16− goods <- mkTests True =<< getElms "good"
17+ goods <- mkTests goodCompile =<< getElms "good"
17− bads <- mkTests False =<< getElms "bad"
18+ bads <- mkTests badCompile =<< getElms "bad"
18 return $ testGroup "Compile Tests"
19 return $ testGroup "Compile Tests"
20 testGroup "Good Tests" goods
21 testGroup "Good Tests" goods
@@ -24,15 +25,21 @@ compilerTests = buildTest $ do
24 where getElms :: FilePath -> IO [FilePath]
25 where getElms :: FilePath -> IO [FilePath]
25 getElms fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
26 getElms fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
27− mkTests :: Bool -> [FilePath] -> IO [Test]
28+ mkTests :: (Either String String -> Assertion) -> [FilePath] -> IO [Test]
28− mkTests b = traverse setupTest
29+ mkTests h = traverse setupTest
29− where setupTest f = testCase f . mkCompileTest b <$> readFile f
30+ where setupTest f = testCase f . mkCompileTest h <$> readFile f
31− testsDir = "tests" </> "data"
32+ testsDir = "tests" </> "test-files"
33−mkCompileTest :: Bool -- ^ Expect success?
34+goodCompile :: Either String String -> Assertion
35+goodCompile (Left err) = assertFailure err
36+goodCompile (Right _) = assertBool "" True
38+badCompile :: Either String String -> Assertion
39+badCompile (Left _) = assertBool "" True
40+badCompile (Right _) = assertFailure "Compilation succeeded but should have failed"
42+mkCompileTest :: ((Either String String) -> Assertion) -- ^ Handler
34 -> String -- ^ File Contents
43 -> String -- ^ File Contents
35 -> Assertion
44 -> Assertion
36−mkCompileTest succ modul = noCompileErr @=? succ
45+mkCompileTest handle = handle . Elm.compile
37− where noCompileErr = either (const False) (const True) . Elm.compile $ modul
38− expectation = "Compile " ++ if succ then "Success" else "Error"