on 40cc419 help sign in
elk/tests/Test/Compiler.hs
73 lines 1.7 kB history raw
1{-# OPTIONS_GHC -W #-}
2module Test.Compiler (compilerTests) where
4import qualified Data.Map as Map
5import Data.Traversable (traverse)
7import System.FilePath ((</>))
8import System.FilePath.Find (find, (==?), extension)
10import Test.Framework
11import Test.Framework.Providers.HUnit (testCase)
12import Test.HUnit (Assertion, assertFailure, assertBool)
14import qualified Elm.Compiler as Compiler
15import qualified Elm.Compiler.Module as Module
18compilerTests :: Test
19compilerTests =
20 buildTest $ do
21 goods <- testIf isSuccess =<< getElms "good"
22 bads <- testIf isFailure =<< getElms "bad"
23 return $
24 testGroup "Compile Tests"
25 [ testGroup "Good Tests" goods
26 , testGroup "Bad Tests" bads
27 ]
30-- GATHER ELM FILES
32getElms :: FilePath -> IO [FilePath]
33getElms filePath =
34 find
35 (return True)
36 (extension ==? ".elm")
37 (testsDir </> filePath)
40testsDir :: FilePath
41testsDir =
42 "tests" </> "compiler" </> "test-files"
45-- RUN COMPILER
47testIf
48 :: (Either String (Module.Interface, String) -> Assertion)
49 -> [FilePath]
50 -> IO [Test]
51testIf handleResult filePaths =
52 traverse setupTest filePaths
53 where
54 setupTest filePath =
55 do source <- readFile filePath
56 let result = Compiler.compile "elm-lang" "core" source Map.empty
57 return (testCase filePath (handleResult result))
60-- CHECK RESULTS
62isSuccess :: Either String a -> Assertion
63isSuccess result =
64 case result of
65 Right _ -> assertBool "" True
66 Left msg -> assertFailure msg
69isFailure :: Either a b -> Assertion
70isFailure result =
71 case result of
72 Left _ -> assertFailure "Compilation succeeded but should have failed"
73 Right _ -> assertBool "" True