on 2da9009 help sign in
elk/tests/Tests/Compiler.hs
36 lines 1.2 kB history raw
1module Tests.Compiler (compilerTests)
2 where
4import Data.Functor ((<$>))
5import Data.Traversable (traverse)
6import System.FilePath.Find (find, (==?), extension)
7import Test.Framework
8import Test.Framework.Providers.HUnit (testCase)
9import Test.HUnit ((@=?), Assertion)
11import Elm.Internal.Utils as Elm
13compilerTests :: Test
14compilerTests = buildTest $ do
15 goods <- getElms "tests/data/good" >>= mkTests True
16 bads <- getElms "tests/data/bad" >>= mkTests False
18 return $ testGroup "Compile Tests"
19 [
20 testGroup "Good Tests" goods
21 , testGroup "Bad Tests" bads
22 ]
24 where getElms :: FilePath -> IO [FilePath]
25 getElms = find (return True) (extension ==? ".elm")
27 mkTests :: Bool -> [FilePath] -> IO [Test]
28 mkTests b = traverse setupTest
29 where setupTest f = testCase f . mkCompileTest b <$> readFile f
31mkCompileTest :: Bool -- ^ Expect success?
32 -> String -- ^ File Contents
33 -> Assertion
34mkCompileTest succ modul = noCompileErr @=? succ
35 where noCompileErr = either (const False) (const True) . Elm.compile $ modul
36 expectation = "Compile " ++ if succ then "Success" else "Error"