hspec-smallcheck 0.5.0 → 0.5.1
raw patch · 3 files changed
+29/−13 lines, 3 filesdep ~hspec-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hspec-core
API changes (from Hackage documentation)
Files
- hspec-smallcheck.cabal +6/−6
- src/Test/Hspec/SmallCheck.hs +1/−2
- test/Test/Hspec/SmallCheckSpec.hs +22/−5
hspec-smallcheck.cabal view
@@ -1,11 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.21.2.+-- This file has been generated from package.yaml by hpack version 0.27.0. -- -- see: https://github.com/sol/hpack ----- hash: 9cd99f0806cf8dfefb5b2761767e11bcc64bbb719b6d31200201b36702038392+-- hash: 2fe681bca0766b159304a8582e5751a076fd3feb25e780316d6dbac9d0b27d10 name: hspec-smallcheck-version: 0.5.0+version: 0.5.1 license: MIT license-file: LICENSE copyright: (c) 2013-2018 Simon Hengel@@ -36,7 +36,7 @@ HUnit , base >=4.5.0.0 && <5 , call-stack- , hspec-core ==2.4.*+ , hspec-core >=2.5.0 , smallcheck >=1.1 default-language: Haskell2010 @@ -53,7 +53,7 @@ , base >=4.5.0.0 && <5 , call-stack , hspec- , hspec-core ==2.4.*+ , hspec-core >=2.5.0 , hspec-smallcheck , smallcheck >=1.1 default-language: Haskell2010@@ -78,6 +78,6 @@ , base >=4.5.0.0 && <5 , call-stack , hspec- , hspec-core ==2.4.*+ , hspec-core >=2.5.0 , smallcheck >=1.1 default-language: Haskell2010
src/Test/Hspec/SmallCheck.hs view
@@ -27,7 +27,6 @@ locationFile = srcLocFile loc , locationLine = srcLocStartLine loc , locationColumn = srcLocStartCol loc-, locationAccuracy = ExactLocation } instance Testable IO (IO ()) where@@ -52,7 +51,7 @@ n <- readIORef counter reportProgress (n, 0) r <- smallCheckWithHook (paramsSmallCheckDepth c) hook p- return $ case r of+ return . Result "" $ case r of Just e -> case T.parseResult (ppFailure e) of (m, Just (T.Failure loc reason)) -> Failure loc $ case reason of T.Reason err -> Reason (fromMaybe "" $ T.concatPrefix m err)
test/Test/Hspec/SmallCheckSpec.hs view
@@ -1,9 +1,13 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# OPTIONS_GHC -fno-warn-orphans #-} module Test.Hspec.SmallCheckSpec (main, spec) where import Test.Hspec +import qualified Control.Exception as E+ import qualified Test.Hspec.Core.Spec as H import qualified Test.Hspec.Runner as H import Test.SmallCheck@@ -15,30 +19,43 @@ main :: IO () main = hspec spec +exceptionEq :: E.SomeException -> E.SomeException -> Bool+exceptionEq a b+ | Just ea <- E.fromException a, Just eb <- E.fromException b = ea == (eb :: E.ErrorCall)+ | Just ea <- E.fromException a, Just eb <- E.fromException b = ea == (eb :: E.ArithException)+ | otherwise = undefined++deriving instance Eq H.FailureReason+deriving instance Eq H.ResultStatus+deriving instance Eq H.Result++instance Eq E.SomeException where+ (==) = exceptionEq+ spec :: Spec spec = do describe "evaluateExample" $ do context "with Property IO" $ do it "returns Success if property holds" $ do- eval True `shouldReturn` H.Success+ eval True `shouldReturn` H.Result "" H.Success it "returns Failure if property does not hold" $ do- eval False `shouldReturn` H.Failure Nothing (H.Reason "condition is false")+ eval False `shouldReturn` H.Result "" (H.Failure Nothing (H.Reason "condition is false")) it "shows what falsified it" $ do- eval (/= (2 :: Int)) `shouldReturn` H.Failure Nothing (H.Reason "there exists 2 such that\n condition is false")+ eval (/= (2 :: Int)) `shouldReturn` H.Result "" (H.Failure Nothing (H.Reason "there exists 2 such that\n condition is false")) it "propagates exceptions" $ do eval (error "foobar" :: Property IO) `shouldThrow` errorCall "foobar" context "with HUnit Assertion" $ do it "includes failure reason" $ do- H.Failure _loc reason <- eval ((\ _ -> assertFailure "some failure") :: Int -> Assertion)+ H.Result "" (H.Failure _loc reason) <- eval ((\ _ -> assertFailure "some failure") :: Int -> Assertion) reason `shouldBe` H.Reason "there exists 0 such that\nsome failure" context "with assertEqual" $ do it "includes actual and expected" $ do- H.Failure _loc reason <- eval (assertEqual "foo" (42 :: Int))+ H.Result "" (H.Failure _loc reason) <- eval (assertEqual "foo" (42 :: Int)) reason `shouldBe` H.ExpectedButGot (Just "there exists 0 such that\nfoo") "42" "0" where eval :: Testable IO a => a -> IO H.Result