packages feed

hspec-test-framework-th (empty) → 0.0.0

raw patch · 4 files changed

+202/−0 lines, 4 filesdep +basedep +hspec-test-frameworkdep +language-haskell-extractsetup-changed

Dependencies added: base, hspec-test-framework, language-haskell-extract, template-haskell

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2013 Simon Hengel <sol@typeful.net>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ hspec-test-framework-th.cabal view
@@ -0,0 +1,59 @@+name:             hspec-test-framework-th+version:          0.0.0+license:          MIT+license-file:     LICENSE+copyright:        (c) 2013 Simon Hengel+maintainer:       Simon Hengel <sol@typeful.net>+build-type:       Simple+cabal-version:    >= 1.8+category:         Testing+bug-reports:      https://github.com/sol/hspec-test-framework/issues+homepage:         http://hspec.github.io/+synopsis:         Run test-framework tests with Hspec+description:      A `test-framework` compatibility layer on top of Hspec, it+                  allows you to run `test-framework` tests with Hspec+                  unmodified.+                  .+                  All that is required is to remove+                  .+                  * `test-framework`+                  .+                  * `test-framework-quickcheck2`+                  .+                  * `test-framework-hunit`+                  .+                  * `test-framework-th`+                  .+                  from the `build-depends` section of your cabal file and add+                  .+                  * `hspec-test-framework`+                  .+                  * `hspec-test-framework-th`+                  .+                  in theire place.+                  .+                  NOTE: The packages `hspec-test-framework` and+                  `hspec-test-framework-th` are hidden by default, so that they+                  do not interfere with an installed version of+                  `test-framework`.  If you want to use them with e.g. `ghci`,+                  you have to pass the command-line flags+                  @-packagehspec-test-framework -packagehspec-test-framework-th@+                  to GHC.++source-repository head+  type: git+  location: https://github.com/sol/hspec-test-framework++library+  exposed: False+  ghc-options:+      -Wall+  hs-source-dirs:+      src+  exposed-modules:+      Test.Framework.TH+  build-depends:+      base    == 4.*+    , hspec-test-framework+    , template-haskell+    , language-haskell-extract
+ src/Test/Framework/TH.hs view
@@ -0,0 +1,121 @@+-----------------------------------------------------------------------------+--+-- Module      :  MainTestGenerator+-- Copyright   :  +-- License     :  BSD4+--+-- Maintainer  :  Oscar Finnsson+-- Stability   :  +-- Portability :  +--+-- +-----------------------------------------------------------------------------+{-# OPTIONS_GHC -XTemplateHaskell #-}++module Test.Framework.TH (+  defaultMainGenerator,+  defaultMainGenerator2,+  testGroupGenerator+) where+import Language.Haskell.TH+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_, prop_ or test_ will be extracted.+--  +--   > {-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}+--   > module MyModuleTest where+--   > import Test.HUnit+--   > import MainTestGenerator+--   > +--   > main = $(defaultMainGenerator)+--   >+--   > case_Foo = do 4 @=? 4+--   >+--   > case_Bar = do "hej" @=? "hej"+--   > +--   > 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, 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  2           3            5          +--   >  Failed  0           0            0           +--   >  Total   2           3            5+ +--   +defaultMainGenerator :: ExpQ+defaultMainGenerator = +  [| defaultMain [ testGroup $(locationModule) $ $(propListGenerator) ++ $(caseListGenerator) ++ $(testListGenerator) ] |]++defaultMainGenerator2 :: ExpQ+defaultMainGenerator2 = +  [| 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_, prop_ or test_ will be extracted.+--  +--   > -- file SomeModule.hs+--   > fooTestGroup = $(testGroupGenerator)+--   > main = defaultMain [fooTestGroup]+--   > case_1 = do 1 @=? 1+--   > case_2 = do 2 @=? 2+--   > prop_p xs = reverse (reverse xs) == xs+--   >  where types = xs :: [Int]+--   +--   is the same as+--+--   > -- file SoomeModule.hs+--   > fooTestGroup = testGroup "SomeModule" [testProperty "p" prop_1, testCase "1" case_1, testCase "2" case_2]+--   > main = defaultMain [fooTestGroup]+--   > case_1 = do 1 @=? 1+--   > case_2 = do 2 @=? 2+--   > prop_1 xs = reverse (reverse xs) == xs+--   >  where types = xs :: [Int]+--+testGroupGenerator :: ExpQ+testGroupGenerator =+  [| testGroup $(locationModule) $ $(propListGenerator) ++ $(caseListGenerator) ++ $(testListGenerator) |]++listGenerator :: String -> String -> ExpQ+listGenerator beginning funcName =+  functionExtractorMap beginning (applyNameFix funcName)++propListGenerator :: ExpQ+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+applyNameFix n =+  do fn <- [|fixName|]+     return $ LamE [VarP (mkName "n")] (AppE (VarE (mkName n)) (AppE (fn) (VarE (mkName "n"))))++fixName :: String -> String+fixName name = replace '_' ' ' $ drop 5 name++replace :: Eq a => a -> a -> [a] -> [a]+replace b v = map (\i -> if b == i then v else i)