on master help sign in
Migrate tests to test-framework and make them more specific.
840eca6Max New
Elm.cabal+7−1
@@ -230,4 +230,10 @@ Test-Suite test-elm
230 Type: exitcode-stdio-1.0
230 Type: exitcode-stdio-1.0
231 Hs-Source-Dirs: tests
231 Hs-Source-Dirs: tests
232 Main-is: Main.hs
232 Main-is: Main.hs
233− build-depends: base, directory, HTF
233+ build-depends: base,
234+ directory,
235+ Elm,
236+ test-framework,
237+ test-framework-hunit,
238+ HUnit,
239+ filemanip
tests/Main.hs+34−18
@@ -1,22 +1,38 @@
1module Main where
1module Main where
2
2
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)
9+
10+import Elm.Internal.Utils as Elm
8
11
9main :: IO ()
12main :: IO ()
10−main = do
13+main = defaultMain [compilerTests]
11− args <- getArgs
14+
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
16− exitWith code
19+
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")
28+
29+ mkTests :: Bool -> [FilePath] -> IO [Test]
30+ mkTests b = traverse setupTest
31+ where setupTest f = testCase f . mkCompileTest b <$> readFile f
32+
33+mkCompileTest :: Bool -- ^ Expect success?
34+ -> String -- ^ File Contents
35+ -> Assertion
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"