2module Test.Compiler (compilerTests) where
4import qualified Data.Map as Map
5import Data.Traversable (traverse)
6import Data.Bifunctor (first, second)
8import System.FilePath ((</>))
9import System.FilePath.Find (find, (==?), extension)
12import Test.Framework.Providers.HUnit (testCase)
13import Test.HUnit (Assertion, assertFailure, assertBool)
15import qualified Elm.Compiler as Compiler
16import qualified Elm.Compiler.Module as Module
18type ErrorMessage = String
23 goods <- testIf isSuccess =<< getElms "good"
24 bads <- testIf isFailure =<< getElms "bad"
26 testGroup "Compile Tests"
27 [ testGroup "Good Tests" goods
28 , testGroup "Bad Tests" bads
34getElms :: FilePath -> IO [FilePath]
38 (extension ==? ".elm")
39 (testsDir </> filePath)
44 "tests" </> "test-files"
50 :: (([Compiler.Warning], Either [ErrorMessage] (Module.Interface, String)) -> Assertion)
53testIf handleResult filePaths =
54 traverse setupTest filePaths
56 setupTest filePath = do
57 source <- readFile filePath
59 let result = Compiler.compile "elm-lang" "core" True source Map.empty
60 let errorsToStrings = second (first $ map (Compiler.errorToString filePath source))
62 return $ testCase filePath (handleResult . errorsToStrings $ result)
66isSuccess :: ([Compiler.Warning], Either [ErrorMessage] a) -> Assertion
67isSuccess (_, result) =
69 Right _ -> assertBool "" True
70 Left errorMessages -> assertFailure $ concat errorMessages
73isFailure :: ([Compiler.Warning], Either a b) -> Assertion
74isFailure (_, result) =
76 Right _ -> assertFailure "Compilation succeeded but should have failed"
77 Left _ -> assertBool "" True
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list