on master help sign in
Migrate tests to test-framework and make them more specific.

Use test-framework as it's more widely used/has better support for HUnit/QuickCheck. Make test cases test the `compile` function explicitly instead of the elm executable as that's all they're actually intended to test.

commit840eca65735f11dc90288dcb9ff67fc70479ad99 authorMax New <maxsnew@gmail.com> dateSun 29 Dec 2013, 13:44 (13 years ago) parentf26610b
2 files changed+41−19
Elm.cabal+7−1 tests/Main.hs+34−18
Elm.cabal+7−1
@@ -230,4 +230,10 @@ Test-Suite test-elm
230230 Type: exitcode-stdio-1.0
231231 Hs-Source-Dirs: tests
232232 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 @@
11module Main where
22
3−import System.Directory
4−import System.Exit (exitWith)
5−import System.Environment (getArgs)
6−import Test.Framework.TestManager
7−import Test.Framework.BlackBoxTest
3+import Data.Functor ((<$>))
4+import Data.Traversable (traverse)
5+import System.FilePath.Find (find, (==?), extension)
6+import Test.Framework
7+import Test.Framework.Providers.HUnit (testCase)
8+import Test.HUnit ((@=?), Assertion)
9+
10+import Elm.Internal.Utils as Elm
811
912main :: IO ()
10−main = do
11− args <- getArgs
12− tests <- blackBoxTests "tests" "dist/build/elm/elm" ".elm" bbtArgs
13− code <- runTestWithArgs args tests
14− removeDirectoryRecursive "cache"
15− removeDirectoryRecursive "build"
16− exitWith code
17−
18−bbtArgs = defaultBBTArgs { bbtArgs_stdoutDiff = ignoreDiff
19− , bbtArgs_stderrDiff = ignoreDiff }
20−
21−ignoreDiff :: Diff
22−ignoreDiff _ _ = return Nothing
13+main = defaultMain [compilerTests]
14+
15+compilerTests :: Test
16+compilerTests = buildTest $ do
17+ goods <- getElms "tests/good" >>= mkTests True
18+ bads <- getElms "tests/bad" >>= mkTests False
19+
20+ return $ testGroup "Compile Tests"
21+ [
22+ testGroup "Good Tests" goods
23+ , testGroup "Bad Tests" bads
24+ ]
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"