Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First commit.

  • Loading branch information...
commit 67ae6f646bae5e14a97ab60f37c8b753d16297de 0 parents
@finnsson authored
BIN  .DS_Store
Binary file not shown
4 .gitignore
@@ -0,0 +1,4 @@
+dist
+*.swp
+*.hi
+*.o
6 Setup.lhs
@@ -0,0 +1,6 @@
+#!/usr/bin/runhaskell
+> module Main where
+> import Distribution.Simple
+> main :: IO ()
+> main = defaultMain
+
46 main-test-generator.cabal
@@ -0,0 +1,46 @@
+name: main-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: MainTestGenerator
+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:
65 src/MainTestGenerator.hs
@@ -0,0 +1,65 @@
+-----------------------------------------------------------------------------
+--
+-- Module : MainTestGenerator
+-- Copyright :
+-- License : BSD4
+--
+-- Maintainer : Oscar Finnsson
+-- Stability :
+-- Portability :
+--
+--
+-----------------------------------------------------------------------------
+{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
+
+module MainTestGenerator (
+ mainTestGenerator
+) 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 = $(mainTestGenerator)
+-- >
+-- > 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
+--
+mainTestGenerator :: ExpQ
+mainTestGenerator =
+ [| defaultMain [ testGroup $(locationModule) (mapTestCases $(functionExtractor "^test") ) ] |]
+
+mapTestCases :: [(String, Assertion)] -> [Test.Framework.Test]
+mapTestCases list =
+ map (uncurry testCase) list
26 src/MainTestGeneratorTest.hs
@@ -0,0 +1,26 @@
+-----------------------------------------------------------------------------
+--
+-- Module : MainTestGenerator
+-- Copyright :
+-- License : BSD4
+--
+-- Maintainer : Oscar Finnsson
+-- Stability :
+-- Portability :
+--
+-- |
+--
+-----------------------------------------------------------------------------
+{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
+module MainTestGeneratorTest where
+import MainTestGenerator
+
+import Test.HUnit
+
+main = $(mainTestGenerator)
+
+testFoo =
+ do 4 @=? 4
+
+testBar =
+ do "hej" @=? "hej"
Please sign in to comment.
Something went wrong with that request. Please try again.