Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8 from dag/testGroup

Support custom test groups, closes #7

Thanks for the pull request. I'll upload a new version to HackageDB.
  • Loading branch information...
commit 4439f31f981ceee1d1cb37df357f65e0fc31202d 2 parents f56f90e + bb35bad
@finnsson authored
View
27 src/Test/Framework/TH.hs
@@ -28,7 +28,7 @@ import Language.Haskell.Extract
import Test.Framework (defaultMain, testGroup)
-- | Generate the usual code and extract the usual functions needed in order to run HUnit/Quickcheck/Quickcheck2.
--- All functions beginning with case_ or prop_ will be extracted.
+-- All functions beginning with case_, prop_ or test_ will be extracted.
--
-- > {-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
-- > module MyModuleTest where
@@ -43,31 +43,39 @@ import Test.Framework (defaultMain, testGroup)
-- >
-- > prop_Reverse xs = reverse (reverse xs) == xs
-- > where types = xs :: [Int]
+-- >
+-- > test_Group =
+-- > [ testCase "1" case_Foo
+-- > , testProperty "2" prop_Reverse
+-- > ]
--
--- will automagically extract prop_Reverse, case_Foo and case_Bar and run them as well as present them as belonging to the testGroup 'MyModuleTest' such as
+-- will automagically extract prop_Reverse, case_Foo, case_Bar and test_Group and run them as well as present them as belonging to the testGroup 'MyModuleTest' such as
--
-- > me: runghc MyModuleTest.hs
-- > MyModuleTest:
-- > Reverse: [OK, passed 100 tests]
-- > Foo: [OK]
-- > Bar: [OK]
+-- > Group:
+-- > 1: [OK]
+-- > 2: [OK, passed 100 tests]
-- >
-- > Properties Test Cases Total
--- > Passed 1 2 3
+-- > Passed 2 3 5
-- > Failed 0 0 0
--- > Total 1 1 3
+-- > Total 2 3 5
--
defaultMainGenerator :: ExpQ
defaultMainGenerator =
- [| defaultMain [ testGroup $(locationModule) $ $(propListGenerator) ++ $(caseListGenerator) ] |]
+ [| defaultMain [ testGroup $(locationModule) $ $(propListGenerator) ++ $(caseListGenerator) ++ $(testListGenerator) ] |]
defaultMainGenerator2 :: ExpQ
defaultMainGenerator2 =
- [| defaultMain [ testGroup $(locationModule) $ $(caseListGenerator) ++ $(propListGenerator) ] |]
+ [| defaultMain [ testGroup $(locationModule) $ $(caseListGenerator) ++ $(propListGenerator) ++ $(testListGenerator) ] |]
-- | Generate the usual code and extract the usual functions needed for a testGroup in HUnit/Quickcheck/Quickcheck2.
--- All functions beginning with case_ or prop_ will be extracted.
+-- All functions beginning with case_, prop_ or test_ will be extracted.
--
-- > -- file SomeModule.hs
-- > fooTestGroup = $(testGroupGenerator)
@@ -89,7 +97,7 @@ defaultMainGenerator2 =
--
testGroupGenerator :: ExpQ
testGroupGenerator =
- [| testGroup $(locationModule) $ $(propListGenerator) ++ $(caseListGenerator) |]
+ [| testGroup $(locationModule) $ $(propListGenerator) ++ $(caseListGenerator) ++ $(testListGenerator) |]
listGenerator :: String -> String -> ExpQ
listGenerator beginning funcName =
@@ -101,6 +109,9 @@ propListGenerator = listGenerator "^prop_" "testProperty"
caseListGenerator :: ExpQ
caseListGenerator = listGenerator "^case_" "testCase"
+testListGenerator :: ExpQ
+testListGenerator = listGenerator "^test_" "testGroup"
+
-- | The same as
-- e.g. \n f -> testProperty (fixName n) f
applyNameFix :: String -> ExpQ
View
6 src/Test/Framework/TestTH.hs
@@ -1,5 +1,6 @@
{-# OPTIONS_GHC -XTemplateHaskell #-}
module Test.Framework.TestTH where
+import Test.Framework
import Test.Framework.TH
import Test.HUnit
@@ -22,3 +23,8 @@ case_num_Prop =
do let expected = 1
actual = length $ $(functionExtractor "^prop")
expected @=? actual
+
+test_Group =
+ [ testCase "1" case_Foo
+ , testProperty "2" prop_Reverse
+ ]
View
2  test-framework-th.cabal
@@ -10,7 +10,7 @@ synopsis: Automagically generate the HUnit- and Quickcheck-bulk-code using Templ
description:
@test-framework-th@ contains two interesting functions: @defaultMainGenerator@ and @testGroupGenerator@.
.
- @defaultMainGenerator@ will extract all functions beginning with case_ or prop_ in the module and put them in a testGroup.
+ @defaultMainGenerator@ will extract all functions beginning with case_, prop_ or test_in the module and put them in a testGroup.
.
> -- file SomeModule.hs
> ( -# LANGUAGE TemplateHaskell #- )
Please sign in to comment.
Something went wrong with that request. Please try again.