on 577fc17 help sign in
elk/tests/compiler/Tests/Compiler.hs
49 lines 1.7 kB history raw
1module Tests.Compiler (compilerTests) where
3import Data.Functor ((<$>))
4import Data.Traversable (traverse)
5import System.FilePath ((</>))
6import System.FilePath.Find (find, (==?), extension)
7import Test.Framework
8import Test.Framework.Providers.HUnit (testCase)
9import Test.HUnit (Assertion, assertFailure, assertBool)
10import Text.Parsec (ParseError)
12import Elm.Internal.Utils as Elm
14compilerTests :: Test
15compilerTests =
16 buildTest $ do
17 goods <- mkTests goodCompile =<< getElms "good"
18 bads <- mkTests badCompile =<< getElms "bad"
19 return $ testGroup "Compile Tests"
20 [ testGroup "Good Tests" goods
21 , testGroup "Bad Tests" bads
22 ]
23 where
24 getElms :: FilePath -> IO [FilePath]
25 getElms fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
27 mkTests :: (Either String String -> Assertion) -> [FilePath] -> IO [Test]
28 mkTests h = traverse setupTest
29 where setupTest f = testCase f . mkCompileTest h <$> readFile f
31 testsDir :: FilePath
32 testsDir = "tests" </> "compiler" </> "test-files"
34goodCompile :: Either String String -> Assertion
35goodCompile result =
36 case result of
37 Left err -> assertFailure err
38 Right _ -> assertBool "" True
40badCompile :: Either String String -> Assertion
41badCompile result =
42 case result of
43 Left _ -> assertBool "" True
44 Right _ -> assertFailure "Compilation succeeded but should have failed"
46mkCompileTest :: ((Either String String) -> Assertion) -- ^ Handler
47 -> String -- ^ File Contents
48 -> Assertion
49mkCompileTest handle = handle . Elm.compile