Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed name from main-test-generator to test-generator
- Loading branch information
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
----------------------------------------------------------------------------- | ||
-- | ||
-- Module : MainTestGenerator | ||
-- Copyright : | ||
-- License : BSD4 | ||
-- | ||
-- Maintainer : Oscar Finnsson | ||
-- Stability : | ||
-- Portability : | ||
-- | ||
-- | ||
----------------------------------------------------------------------------- | ||
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-} | ||
|
||
module TestGenerator ( | ||
defaultMainGenerator, | ||
testGroupGenerator | ||
) where | ||
import Language.Haskell.TH | ||
import Language.Haskell.Exts.Parser | ||
import Language.Haskell.Exts.Syntax | ||
import Text.Regex.Posix | ||
import Maybe | ||
import Language.Haskell.Exts.Extension | ||
import Test.Framework.Providers.HUnit | ||
import FunctionExtractor | ||
import Test.Framework (Test) | ||
|
||
import Test.HUnit | ||
|
||
|
||
import Test.Framework (defaultMain, testGroup) | ||
import Test.Framework.Providers.HUnit | ||
|
||
-- | Generate the usual code and extract the usual functions needed in order to run HUnit. | ||
-- | ||
-- > {-# 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' such as | ||
-- | ||
-- > me: runghc MyModuleTest.hs | ||
-- > MyModuleTest: | ||
-- > testFoo: [OK] | ||
-- > testBar: [OK] | ||
-- > | ||
-- > Test Cases Total | ||
-- > Passed 2 2 | ||
-- > Failed 0 0 | ||
-- > Total 2 2 | ||
-- | ||
defaultMainGenerator :: ExpQ | ||
defaultMainGenerator = | ||
[| defaultMain [ testGroup $(locationModule) (mapTestCases $(functionExtractor "^test") ) ] |] | ||
|
||
-- | Generate the usual code and extract the usual functions needed for a testGroup in HUnit. | ||
-- | ||
-- > -- 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 | ||
-- | ||
testGroupGenerator :: ExpQ | ||
testGroupGenerator = | ||
[| testGroup $(locationModule) (mapTestCases $(functionExtractor "^test") ) |] | ||
|
||
|
||
mapTestCases :: [(String, Assertion)] -> [Test.Framework.Test] | ||
mapTestCases list = | ||
map (uncurry testCase) list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
----------------------------------------------------------------------------- | ||
-- | ||
-- Module : TestGenerator | ||
-- Copyright : | ||
-- License : BSD4 | ||
-- | ||
-- Maintainer : Oscar Finnsson | ||
-- Stability : | ||
-- Portability : | ||
-- | ||
-- | | ||
-- | ||
----------------------------------------------------------------------------- | ||
{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-} | ||
module TestGeneratorTest where | ||
import TestGenerator | ||
|
||
import Test.HUnit | ||
|
||
main = $(defaultMainGenerator) | ||
|
||
testFoo = | ||
do 4 @=? 4 | ||
|
||
testBar = | ||
do "hej" @=? "hej" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: test-generator | ||
version: 0.0.1 | ||
cabal-version: -any | ||
build-type: Simple | ||
license: BSD4 | ||
license-file: "" | ||
copyright: | ||
maintainer: Oscar Finnsson | ||
build-depends: base -any, test-framework-hunit, test-framework, HUnit, function-extractor, haskell-src-exts, haskell98, regex-posix, template-haskell | ||
stability: | ||
homepage: | ||
package-url: | ||
bug-reports: | ||
synopsis: | ||
description: Automagically generated the HUnit-bulk-code. | ||
category: | ||
author: Oscar Finnsson & Emil Nordling | ||
tested-with: | ||
data-files: | ||
data-dir: "" | ||
extra-source-files: | ||
extra-tmp-files: | ||
exposed-modules: TestGenerator | ||
exposed: True | ||
buildable: True | ||
build-tools: | ||
cpp-options: | ||
cc-options: | ||
ld-options: | ||
pkgconfig-depends: | ||
frameworks: | ||
c-sources: | ||
extensions: | ||
extra-libraries: | ||
extra-lib-dirs: | ||
includes: | ||
install-includes: | ||
include-dirs: | ||
hs-source-dirs: src | ||
other-modules: | ||
ghc-prof-options: | ||
ghc-shared-options: | ||
ghc-options: | ||
hugs-options: | ||
nhc98-options: | ||
jhc-options: |