@@ -1,22 +1,38 @@
1module Main where
1module Main where
3−import System.Directory
3+import Data.Functor ((<$>))
4−import System.Exit (exitWith)
4+import Data.Traversable (traverse)
5−import System.Environment (getArgs)
5+import System.FilePath.Find (find, (==?), extension)
6−import Test.Framework.TestManager
6+import Test.Framework
7−import Test.Framework.BlackBoxTest
7+import Test.Framework.Providers.HUnit (testCase)
8+import Test.HUnit ((@=?), Assertion)
10+import Elm.Internal.Utils as Elm
9main :: IO ()
12main :: IO ()
10−main = do
13+main = defaultMain [compilerTests]
12− tests <- blackBoxTests "tests" "dist/build/elm/elm" ".elm" bbtArgs
15+compilerTests :: Test
13− code <- runTestWithArgs args tests
16+compilerTests = buildTest $ do
14− removeDirectoryRecursive "cache"
17+ goods <- getElms "tests/good" >>= mkTests True
15− removeDirectoryRecursive "build"
18+ bads <- getElms "tests/bad" >>= mkTests False
17−
20+ return $ testGroup "Compile Tests"
18−bbtArgs = defaultBBTArgs { bbtArgs_stdoutDiff = ignoreDiff
21+ [
19− , bbtArgs_stderrDiff = ignoreDiff }
22+ testGroup "Good Tests" goods
20−
23+ , testGroup "Bad Tests" bads
21−ignoreDiff :: Diff
24+ ]
22−ignoreDiff _ _ = return Nothing
25+
26+ where getElms :: FilePath -> IO [FilePath]
27+ getElms = find (return True) (extension ==? ".elm")
29+ mkTests :: Bool -> [FilePath] -> IO [Test]
30+ mkTests b = traverse setupTest
31+ where setupTest f = testCase f . mkCompileTest b <$> readFile f
33+mkCompileTest :: Bool -- ^ Expect success?
34+ -> String -- ^ File Contents
36+mkCompileTest succ modul = noCompileErr @=? succ
37+ where noCompileErr = either (const False) (const True) . Elm.compile $ modul
38+ expectation = "Compile " ++ if succ then "Success" else "Error"