on master help sign in
cosmetic: get style more in line with rest of compiler
069a4c5Evan Czaplicki
tests/compiler/Tests/Compiler.hs+27−23
@@ -1,5 +1,4 @@
1−module Tests.Compiler (compilerTests)
1+module Tests.Compiler (compilerTests) where
2− where
3
2
4import Data.Functor ((<$>))
3import Data.Functor ((<$>))
5import Data.Traversable (traverse)
4import Data.Traversable (traverse)
@@ -13,31 +12,36 @@ import Text.Parsec (ParseError)
13import Elm.Internal.Utils as Elm
12import Elm.Internal.Utils as Elm
14
13
15compilerTests :: Test
14compilerTests :: Test
16−compilerTests = buildTest $ do
15+compilerTests =
16+ buildTest $ do
17− goods <- mkTests goodCompile =<< getElms "good"
17+ goods <- mkTests goodCompile =<< getElms "good"
18− bads <- mkTests badCompile =<< getElms "bad"
18+ bads <- mkTests badCompile =<< getElms "bad"
19− return $ testGroup "Compile Tests"
19+ return $ testGroup "Compile Tests"
20− [
21− testGroup "Good Tests" goods
20+ [ testGroup "Good Tests" goods
22− , testGroup "Bad Tests" bads
21+ , testGroup "Bad Tests" bads
23− ]
22+ ]
24−
23+ where
25− where getElms :: FilePath -> IO [FilePath]
24+ getElms :: FilePath -> IO [FilePath]
26− getElms fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
25+ getElms fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
27−
26+
28− mkTests :: (Either String String -> Assertion) -> [FilePath] -> IO [Test]
27+ mkTests :: (Either String String -> Assertion) -> [FilePath] -> IO [Test]
29− mkTests h = traverse setupTest
28+ mkTests h = traverse setupTest
30− where setupTest f = testCase f . mkCompileTest h <$> readFile f
29+ where setupTest f = testCase f . mkCompileTest h <$> readFile f
31−
30+
31+ testsDir :: FilePath
32− testsDir = "tests" </> "compiler" </> "test-files"
32+ testsDir = "tests" </> "compiler" </> "test-files"
33
33
34goodCompile :: Either String String -> Assertion
34goodCompile :: Either String String -> Assertion
35+goodCompile result =
36+ case result of
35−goodCompile (Left err) = assertFailure err
37+ Left err -> assertFailure err
36−goodCompile (Right _) = assertBool "" True
38+ Right _ -> assertBool "" True
37
39
38badCompile :: Either String String -> Assertion
40badCompile :: Either String String -> Assertion
41+badCompile result =
42+ case result of
39−badCompile (Left _) = assertBool "" True
43+ Left _ -> assertBool "" True
40−badCompile (Right _) = assertFailure "Compilation succeeded but should have failed"
44+ Right _ -> assertFailure "Compilation succeeded but should have failed"
41
45
42mkCompileTest :: ((Either String String) -> Assertion) -- ^ Handler
46mkCompileTest :: ((Either String String) -> Assertion) -- ^ Handler
43 -> String -- ^ File Contents
47 -> String -- ^ File Contents