Skip to content

Commit

Permalink
Fixed documentation thanks to @mwotton
Browse files Browse the repository at this point in the history
  • Loading branch information
finnsson committed Aug 28, 2010
1 parent ba5c317 commit 6484605
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 40 deletions.
76 changes: 54 additions & 22 deletions README.markdown
Expand Up @@ -15,20 +15,42 @@ Haskell-module to automagically generate repetetive code when writing HUnit/Quic
### example ### example


-- file SomeModule.hs -- file SomeModule.hs
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
module SomeModule where
import Test.Framework.TH
import Test.Framework
import Test.HUnit
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2

-- observe this line!
fooTestGroup = $(testGroupGenerator) fooTestGroup = $(testGroupGenerator)
main = defaultMain [fooTestGroup] main = defaultMain [fooTestGroup]
case_1 = do 1 @=? 1 case_1 = do 1 @=? 1
case_2 = do 2 @=? 2 case_2 = do 2 @=? 2
prop_reverse = reverse (reverse xs) == xs where types = xs::[Int] prop_reverse xs = reverse (reverse xs) == xs
where types = xs::[Int]


is the same as is the same as



-- file SomeModule.hs -- file SomeModule.hs
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
module SomeModule where
import Test.Framework.TH
import Test.Framework
import Test.HUnit
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2

-- observe this line!
fooTestGroup = testGroup "SomeModule" [testCase "1" case_1, testCase "2" case_2, testProperty "reverse" prop_reverse] fooTestGroup = testGroup "SomeModule" [testCase "1" case_1, testCase "2" case_2, testProperty "reverse" prop_reverse]
main = defaultMain [fooTestGroup] main = defaultMain [fooTestGroup]
case_1 = do 1 @=? 1 case_1 = do 1 @=? 1
case_2 = do 2 @=? 2 case_2 = do 2 @=? 2
prop_reverse = reverse (reverse xs) == xs where types = xs::[Int] prop_reverse xs = reverse (reverse xs) == xs
where types = xs::[Int]



## defaultMainGenerator ## defaultMainGenerator


Expand All @@ -42,44 +64,54 @@ is the same as


### example ### example



-- file SomeModule.hs
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-} {-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
module MyModuleTest where module SomeModule where
import Test.Framework.TH
import Test.Framework
import Test.HUnit import Test.HUnit
import MainTestGenerator import Test.Framework.Providers.HUnit

import Test.Framework.Providers.QuickCheck2
main = $(defaultMainGenerator)


case_Foo = do 4 @=? 4 -- observe this line!

main = $(defaultMainGenerator)
case_Bar = do "hej" @=? "hej" case_1 = do 1 @=? 1
case_2 = do 2 @=? 2
prop_reverse xs = reverse (reverse xs) == xs
where types = xs::[Int]


prop_reverse = reverse (reverse xs) == xs where types = xs::[Int]


will automagically extract prop_reverse, case_Foo and case_Bar and run them as well as present them as belonging to the testGroup 'MyModuleTest'. The above code is the same as will automagically extract prop_reverse, case_1 and case_2 and run them as well as present them as belonging to the testGroup 'SomeModule'. The above code is the same as


-- file SomeModule.hs
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-} {-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
module MyModuleTest where module SomeModule where
import Test.Framework.TH
import Test.Framework
import Test.HUnit import Test.HUnit
import MainTestGenerator import Test.Framework.Providers.HUnit

import Test.Framework.Providers.QuickCheck2

-- observe this line!
main = main =
defaultMain [ defaultMain [
testGroup "MyModuleTest" [ testCase "Foo" case_Foo, testCase "Bar" case_Bar, testProperty "reverse" prop_reverse] testGroup "SomeModule" [ testCase "1" case_1, testCase "2" case_2, testProperty "reverse" prop_reverse]
] ]

case_Foo = do 4 @=? 4

case_Bar = do "hej" @=? "hej"


prop_reverse = reverse (reverse xs) == xs where types = xs::[Int] case_1 = do 1 @=? 1
case_2 = do 2 @=? 2
prop_reverse xs = reverse (reverse xs) == xs
where types = xs::[Int]



and will give the following result and will give the following result


me: runghc MyModuleTest.hs me: runghc MyModuleTest.hs
MyModuleTest: MyModuleTest:
reverse: [OK, passed 100 tests] reverse: [OK, passed 100 tests]
Foo: [OK] 1: [OK]
Bar: [OK] 2: [OK]
Properties Test Cases Total Properties Test Cases Total
Passed 1 2 3 Passed 1 2 3
Expand Down
56 changes: 38 additions & 18 deletions test-framework-th.cabal
Expand Up @@ -15,26 +15,46 @@ description:
. .
@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_ or prop_ in the module and put them in a testGroup.
. .
> module Foo where > -- file SomeModule.hs
> ( -# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #- )
> module SomeModule where
> import Test.Framework.TH
> import Test.Framework
> import Test.HUnit
> import Test.Framework.Providers.HUnit
> import Test.Framework.Providers.QuickCheck2
>
> -- observe this line!
> main = $(defaultMainGenerator) > main = $(defaultMainGenerator)
> case_1 = do 1 @=? 1
> case_2 = do 2 @=? 2
> prop_reverse xs = reverse (reverse xs) == xs
> where types = xs::[Int]
.
is the same as
.
> -- file SomeModule.hs
> ( -# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #- )
> module SomeModule where
> import Test.Framework.TH
> import Test.Framework
> import Test.HUnit
> import Test.Framework.Providers.HUnit
> import Test.Framework.Providers.QuickCheck2
> >
> case_Two = 2 @=? 2 > -- observe this line!
> case_Hi = "hi" @=? "hi" > main =
> prop_Reverse xs = reverse (reverse xs) == xs > defaultMain [
> where types = xs :: [Int] > testGroup "SomeModule" [ testCase "1" case_1, testCase "2" case_2, testProperty "reverse" prop_reverse]
. > ]
is the same as >
. > case_1 = do 1 @=? 1
> module Foo where > case_2 = do 2 @=? 2
> main = defaultMain [testGroup "Foo" [testProperty "Reverse" prop_Reverse, testCase "Two" case_Two, testCase "Hi" case_Hi] > prop_reverse xs = reverse (reverse xs) == xs
> > where types = xs::[Int]
> case_Two = 2 @=? 2 .
> case_Hi = "hi" @=? "hi" @testGroupGenerator@ is like @defaultMainGenerator@ but without @defaultMain@. It is useful if you need a function for the testgroup
> prop_Reverse xs = reverse (reverse xs) == xs (e.g. if you want to be able to call the testgroup from another module).
> where types = xs :: [Int]
.
@testGroupGenerator@ is like @defaultMainGenerator@ but without @defaultMain@. It is useful if you need a function for the testgroup
(e.g. if you want to be able to call the testgroup from another module).
category: Testing category: Testing
author: Oscar Finnsson & Emil Nordling author: Oscar Finnsson & Emil Nordling
tested-with: tested-with:
Expand Down

0 comments on commit 6484605

Please sign in to comment.