packages feed

hspec-experimental (empty) → 0.1.0

raw patch · 5 files changed

+105/−0 lines, 5 filesdep +HUnitdep +QuickCheckdep +basesetup-changed

Dependencies added: HUnit, QuickCheck, base, hspec, hspec-experimental, hspec-meta

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2012 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-experimental.cabal view
@@ -0,0 +1,39 @@+name:             hspec-experimental+version:          0.1.0+license:          MIT+license-file:     LICENSE+copyright:        (c) 2012 Simon Hengel+author:           Simon Hengel <sol@typeful.net>+maintainer:       Simon Hengel <sol@typeful.net>+build-type:       Simple+cabal-version:    >= 1.8+category:         Testing+stability:        experimental+synopsis:         An experimental DSL for testing on top of Hspec+description:      /Note:/ This is experimental!  If you are looking for a+                  stable solution for testing Haskell code, try Hspec:+                  <http://hspec.github.com/>++source-repository head+  type: git+  location: https://github.com/sol/hspec-experimental++library+  ghc-options:      -Wall+  hs-source-dirs:   src+  exposed-modules:  Test.Hspec.Experimental+  build-depends:+      base        == 4.*+    , hspec       == 1.4.*+    , QuickCheck  >= 2.5+    , HUnit++test-suite spec+  type:             exitcode-stdio-1.0+  ghc-options:      -Wall+  hs-source-dirs:   test+  main-is:          Spec.hs+  build-depends:+      base+    , hspec-experimental+    , hspec-meta
+ src/Test/Hspec/Experimental.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Test.Hspec.Experimental (+  module Test.Hspec+, it+) where++import           Test.Hspec hiding (it)+import           Test.Hspec.Core (Params(..), Result(..), SpecTree(..), fromSpecList)++import qualified Control.Exception as E+import           Test.HUnit.Lang (HUnitFailure(..))++import qualified Test.QuickCheck.Property as QCP+import qualified Test.QuickCheck as QC++runExpectation :: Expectation -> QC.Property+runExpectation action = QCP.morallyDubiousIOProperty $ do+  (action >> return succeeded) `E.catch` \(HUnitFailure err) -> return (failed err)+  where+    succeeded  = QC.property QCP.succeeded+    failed err = QC.property QCP.failed {QCP.reason = err}++instance QC.Testable Expectation where+  property     = runExpectation+  exhaustive _ = True++it :: QC.Testable a => String -> a -> Spec+it s p = fromSpecList [SpecItem s result]+  where+    result c = do+      -- copied from Test.Hspec.Core.Type+      r <- QC.quickCheckWithResult (paramsQuickCheckArgs c) p+      return $+        case r of+          QC.Success {}               -> Success+          f@(QC.Failure {})           -> Fail (QC.output f)+          QC.GaveUp {QC.numTests = n} -> Fail ("Gave up after " ++ quantify n "test" )+          QC.NoExpectedFailure {}     -> Fail ("No expected failure")++quantify :: Int -> String -> String+quantify 1 s = "1 " ++ s+quantify n s = show n ++ " " ++ s ++ "s"
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-meta-discover #-}