Skip to content

Commit

Permalink
Updated README.markdown. Fixed indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnsson committed Oct 12, 2009
1 parent d93ce91 commit 87b0b76
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions README.markdown
Expand Up @@ -4,57 +4,57 @@ Haskell-module to automagically generate repetetive code when writing HUnit-test

## testGroupGenerator

> -- file SomeModule.hs
> fooTestGroup = $(testGroupGenerator)
> main = defaultMain [fooTestGroup]
> test1 = do 1 @=? 1
> test2 = do 2 @=? 2
-- file SomeModule.hs
fooTestGroup = $(testGroupGenerator)
main = defaultMain [fooTestGroup]
test1 = do 1 @=? 1
test2 = do 2 @=? 2

is the same as

> -- file SoomeModule.hs
> fooTestGroup = testGroup "SomeModule" [testCase "test1" test1, testCase "test2" test2]
> main = defaultMain [fooTestGroup]
> test1 = do 1 @=? 1
> test2 = do 2 @=? 2
-- file SoomeModule.hs
fooTestGroup = testGroup "SomeModule" [testCase "test1" test1, testCase "test2" test2]
main = defaultMain [fooTestGroup]
test1 = do 1 @=? 1
test2 = do 2 @=? 2

## defaultMainGenerator

> {-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
> module MyModuleTest where
> import Test.HUnit
> import MainTestGenerator
>
> main = $(defaultMainGenerator)
>
> testFoo = do 4 @=? 4
>
> testBar = do "hej" @=? "hej"
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
module MyModuleTest where
import Test.HUnit
import MainTestGenerator
main = $(defaultMainGenerator)
testFoo = do 4 @=? 4
testBar = do "hej" @=? "hej"

will automagically extract testFoo and testBar and run them as well as present them as belonging to the testGroup 'MyModuleTest'. The above code is the same as

> {-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
> module MyModuleTest where
> import Test.HUnit
> import MainTestGenerator
>
> main =
> defaultMain [
> testGroup "MyModuleTest" [ testCase "testFoo" testFoo, testCase "testBar" testBar]
> ]
>
> testFoo = do 4 @=? 4
>
> testBar = do "hej" @=? "hej"
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
module MyModuleTest where
import Test.HUnit
import MainTestGenerator
main =
defaultMain [
testGroup "MyModuleTest" [ testCase "testFoo" testFoo, testCase "testBar" testBar]
]
testFoo = do 4 @=? 4
testBar = do "hej" @=? "hej"

and will give the following result

> me: runghc MyModuleTest.hs
> MyModuleTest:
> testFoo: [OK]
> testBar: [OK]
>
> Test Cases Total
> Passed 2 2
> Failed 0 0
> Total 2 2
me: runghc MyModuleTest.hs
MyModuleTest:
testFoo: [OK]
testBar: [OK]
Test Cases Total
Passed 2 2
Failed 0 0
Total 2 2

0 comments on commit 87b0b76

Please sign in to comment.