packages feed

hspec-hedgehog (empty) → 0.0.0.1

raw patch · 7 files changed

+164/−0 lines, 7 filesdep +basedep +hedgehogdep +hspecsetup-changed

Dependencies added: base, hedgehog, hspec, hspec-core, hspec-hedgehog

Files

+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for hspec-hedgehog++## 0.1.0.0  -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2017 Erik de Castro Lopo <erikd@mega-nerd.com>++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.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Test/Hspec/Hedgehog.hs view
@@ -0,0 +1,50 @@+{-# LANGUAGE TypeFamilies #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+module Test.Hspec.Hedgehog+  ( prop+  , evalHedgehogExample+  ) where++import           Control.Monad.IO.Class (MonadIO, liftIO)++import           Data.Coerce (coerce)++import           Hedgehog (Property, Size (..), Test)+import qualified Hedgehog+import qualified Hedgehog.Internal.Property as HP+import qualified Hedgehog.Internal.Runner as HR+import qualified Hedgehog.Internal.Seed as HS+import           Hedgehog.Internal.Report (Report (..), Status (..), TestCount (..))++import           Test.Hspec.Core.Spec (Arg, Example (..), Spec)+import           Test.Hspec.Core.Spec (ActionWith, Params, ProgressCallback, Result)+import qualified Test.Hspec.Core.Spec as Hspec++prop :: String -> Test IO () -> Spec+prop str = Hspec.it str . Hedgehog.property+++instance Example Property where+  type Arg Property = ()+  evaluateExample = evalHedgehogExample+++evalHedgehogExample :: MonadIO m+                    => Property -> Params -> (ActionWith (Arg Property) -> IO ()) -> ProgressCallback -> m Result+evalHedgehogExample p params _ reportProgress = do+  seed <- HS.random+  rep <- liftIO $ HR.checkReport HP.defaultConfig size seed (HP.propertyTest p) (reportProgress . reporter)+  case reportStatus rep of+    Waiting -> error "waiting"+    Running -> error "running"+    Shrinking _ -> error "shrinking"+    Failed _ -> pure $ Hspec.Failure Nothing (Hspec.Reason "condition is false")+    GaveUp -> error "running"+    OK -> pure Hspec.Success+  where+    size = Size $ Hspec.paramsSmallCheckDepth params+++    reporter :: Report -> (Int, Int)+    reporter r =+      (coerce (reportTests r), Hspec.paramsSmallCheckDepth params)
+ hspec-hedgehog.cabal view
@@ -0,0 +1,44 @@+-- Initial hspec-hedgehog.cabal generated by cabal init.  For further+-- documentation, see http://haskell.org/cabal/users-guide/++name:                hspec-hedgehog+version:             0.0.0.1+synopsis:            Hedgehog support for the Hspec testing framework+-- description:+homepage:            https://github.com/erikd/hspec-hedgehog/+license:             MIT+license-file:        LICENSE+author:              Erik de Castro Lopo+maintainer:          erikd@mega-nerd.com+-- copyright:+category:            Testing+build-type:          Simple+extra-source-files:  ChangeLog.md+cabal-version:       >=1.10++library+  default-language:     Haskell2010+  ghc-options:          -Wall -fwarn-tabs+  hs-source-dirs:       .++  exposed-modules:     Test.Hspec.Hedgehog++  build-depends:       base                          >= 4.8         && < 5.0+                     , hedgehog                      == 0.1.*+                     , hspec-core++test-suite test+  default-language:   Haskell2010+  ghc-options:        -Wall -fwarn-tabs -threaded -O2+  type:               exitcode-stdio-1.0++  main-is:            test.hs+  hs-source-dirs:     test++  other-modules:      Test.Test.Hspec.Hedgehog++  build-depends:       base                          >= 4.8         && < 5.0+                     , hedgehog+                     , hspec                         >= 2.3         && < 2.5+                     , hspec-core+                     , hspec-hedgehog
+ test/Test/Test/Hspec/Hedgehog.hs view
@@ -0,0 +1,38 @@+module Test.Test.Hspec.Hedgehog+  ( hedgehogSpec+  ) where++import           Hedgehog (Property)+import qualified Hedgehog+import qualified Hedgehog.Gen as HG+import qualified Hedgehog.Range as HR++import           Test.Hspec.Hedgehog++import           Test.Hspec (Spec, errorCall, shouldReturn, shouldThrow)+import qualified Test.Hspec.Core.Spec as Hspec+++hedgehogSpec :: Spec+hedgehogSpec = do+  Hspec.describe "evaluateExample" $ do+    Hspec.context "Property" $ do+      Hspec.it "returns Success if property holds" $ do+        evaluateExample (Hedgehog.property $ Hedgehog.assert True) `shouldReturn` Hspec.Success++      Hspec.it "returns Fail if property does not hold" $ do+        evaluateExample (Hedgehog.property $ Hedgehog.assert False) `shouldReturn` Hspec.Failure Nothing (Hspec.Reason "condition is false")++      Hspec.it "shows what falsified it" $ do+        evaluateExample notTwo `shouldReturn` Hspec.Failure Nothing (Hspec.Reason "condition is false")++      Hspec.it "propagates exceptions" $ do+        evaluateExample (error "foobar") `shouldThrow` errorCall "foobar"+  where+    evaluateExample :: Property -> IO Hspec.Result+    evaluateExample e = evalHedgehogExample e Hspec.defaultParams (const $ pure ()) (const $ pure ())++    notTwo :: Property+    notTwo = Hedgehog.property $ do+      x <- Hedgehog.forAll $ HG.integral (HR.linear 0 10)+      Hedgehog.assert $ x /= (2 :: Int)
+ test/test.hs view
@@ -0,0 +1,6 @@++import qualified Test.Hspec as Hspec+import           Test.Test.Hspec.Hedgehog++main :: IO ()+main = Hspec.hspec hedgehogSpec