elm/tests/Tests/Compiler.hs

39 lines
1.3 KiB
Haskell
Raw Normal View History

2013-12-29 21:04:25 +00:00
module Tests.Compiler (compilerTests)
where
import Data.Functor ((<$>))
import Data.Traversable (traverse)
import System.FilePath ((</>))
2013-12-29 21:04:25 +00:00
import System.FilePath.Find (find, (==?), extension)
import Test.Framework
import Test.Framework.Providers.HUnit (testCase)
import Test.HUnit ((@=?), Assertion)
import Elm.Internal.Utils as Elm
compilerTests :: Test
compilerTests = buildTest $ do
goods <- mkTests True =<< getElms "good"
bads <- mkTests False =<< getElms "bad"
2013-12-29 21:04:25 +00:00
return $ testGroup "Compile Tests"
[
testGroup "Good Tests" goods
, testGroup "Bad Tests" bads
]
where getElms :: FilePath -> IO [FilePath]
getElms fname = find (return True) (extension ==? ".elm") (testsDir </> fname)
2013-12-29 21:04:25 +00:00
mkTests :: Bool -> [FilePath] -> IO [Test]
mkTests b = traverse setupTest
where setupTest f = testCase f . mkCompileTest b <$> readFile f
testsDir = "tests" </> "data"
2013-12-29 21:04:25 +00:00
mkCompileTest :: Bool -- ^ Expect success?
-> String -- ^ File Contents
-> Assertion
mkCompileTest succ modul = noCompileErr @=? succ
where noCompileErr = either (const False) (const True) . Elm.compile $ modul
expectation = "Compile " ++ if succ then "Success" else "Error"