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