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