on 6dec2ae help sign in
elk/tests/Tests/Compiler.hs
38 lines 1.3 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)
12import Elm.Internal.Utils as Elm
14compilerTests :: Test
15compilerTests = buildTest $ do
16 goods <- mkTests True =<< getElms "good"
17 bads <- mkTests False =<< getElms "bad"
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 fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
27 mkTests :: Bool -> [FilePath] -> IO [Test]
28 mkTests b = traverse setupTest
29 where setupTest f = testCase f . mkCompileTest b <$> readFile f
31 testsDir = "tests" </> "data"
33mkCompileTest :: Bool -- ^ Expect success?
34 -> String -- ^ File Contents
35 -> Assertion
36mkCompileTest succ modul = noCompileErr @=? succ
37 where noCompileErr = either (const False) (const True) . Elm.compile $ modul
38 expectation = "Compile " ++ if succ then "Success" else "Error"