summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNickSmallbone <>2019-03-29 05:59:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-03-29 05:59:00 (GMT)
commita8d200c4ef789992d46c0dfab13c4e6d5487c162 (patch)
tree1f8f994444c9963660751b7104cf93d0028af8bb
parent8d60e20c1b2ad194b1c5b68d37e7d38da90b5d6b (diff)
version 2.13.12.13.1
-rw-r--r--QuickCheck.cabal12
-rw-r--r--README6
-rw-r--r--Test/QuickCheck/Property.hs35
-rw-r--r--changelog3
-rw-r--r--tests/Misc.hs26
5 files changed, 67 insertions, 15 deletions
diff --git a/QuickCheck.cabal b/QuickCheck.cabal
index 288fd85..4d307fd 100644
--- a/QuickCheck.cabal
+++ b/QuickCheck.cabal
@@ -1,5 +1,5 @@
Name: QuickCheck
-Version: 2.13
+Version: 2.13.1
Cabal-Version: >= 1.8
Build-type: Simple
License: BSD3
@@ -56,7 +56,7 @@ source-repository head
source-repository this
type: git
location: https://github.com/nick8325/quickcheck
- tag: 2.13
+ tag: 2.13.1
flag templateHaskell
Description: Build Test.QuickCheck.All, which uses Template Haskell.
@@ -199,3 +199,11 @@ Test-Suite test-quickcheck-split
hs-source-dirs: tests
main-is: Split.hs
build-depends: base, QuickCheck
+
+Test-Suite test-quickcheck-misc
+ type: exitcode-stdio-1.0
+ hs-source-dirs: tests
+ main-is: Misc.hs
+ build-depends: base, QuickCheck
+ if !flag(templateHaskell) || !impl(ghc >= 7.10)
+ buildable: False
diff --git a/README b/README
index df2766b..0404cf1 100644
--- a/README
+++ b/README
@@ -7,7 +7,7 @@ $ cabal install
The quickcheck-instances [1] companion package provides instances for types in
Haskell Platform packages at the cost of additional dependencies.
-[1]: http://hackage.haskell.org/package/quickcheck-instances
-
-The make-hugs scripts makes a Hugs-compatible version of QuickCheck.
+The make-hugs script makes a Hugs-compatible version of QuickCheck.
It may also be useful for other non-GHC implementations.
+
+[1]: http://hackage.haskell.org/package/quickcheck-instances
diff --git a/Test/QuickCheck/Property.hs b/Test/QuickCheck/Property.hs
index caeb785..16d311b 100644
--- a/Test/QuickCheck/Property.hs
+++ b/Test/QuickCheck/Property.hs
@@ -95,13 +95,14 @@ class Testable prop where
property :: prop -> Property
-- | Optional; used internally in order to improve shrinking.
- -- @propertyForAll gen shr shw f@ is normally equivalent to
- -- @'forAllShrinkShow' gen shr shw f@.
+ -- Tests a property but also quantifies over an extra value
+ -- (with a custom shrink and show function).
-- The 'Testable' instance for functions defines
- -- @propertyForAll@ in a way that improves shrinking.
- propertyForAllShrinkShow :: Show a => Gen a -> (a -> [a]) -> (a -> String) -> (a -> prop) -> Property
- propertyForAllShrinkShow gen shr f =
- forAllShrinkShow gen shr f
+ -- @propertyForAllShrinkShow@ in a way that improves shrinking.
+ propertyForAllShrinkShow :: Gen a -> (a -> [a]) -> (a -> [String]) -> (a -> prop) -> Property
+ propertyForAllShrinkShow gen shr shw f =
+ forAllShrinkBlind gen shr $
+ \x -> foldr counterexample (property (f x)) (shw x)
-- | If a property returns 'Discard', the current test case is discarded,
-- the same as if a precondition was false.
@@ -138,13 +139,13 @@ instance Testable Result where
property = MkProperty . return . MkProp . protectResults . return
instance Testable Prop where
- property (MkProp r) = MkProperty . return . MkProp . ioRose . return $ r
+ property p = MkProperty . return . protectProp $ p
instance Testable prop => Testable (Gen prop) where
property mp = MkProperty $ do p <- mp; unProperty (again p)
instance Testable Property where
- property (MkProperty mp) = MkProperty $ do p <- mp; unProperty (property p)
+ property (MkProperty mp) = MkProperty (fmap protectProp mp)
-- | Do I/O inside a property.
{-# DEPRECATED morallyDubiousIOProperty "Use 'ioProperty' instead" #-}
@@ -174,14 +175,14 @@ idempotentIOProperty =
instance (Arbitrary a, Show a, Testable prop) => Testable (a -> prop) where
property f =
- propertyForAllShrinkShow arbitrary shrink show f
+ propertyForAllShrinkShow arbitrary shrink (return . show) f
propertyForAllShrinkShow gen shr shw f =
-- gen :: Gen b, shr :: b -> [b], f :: b -> a -> prop
-- Idea: Generate and shrink (b, a) as a pair
propertyForAllShrinkShow
(liftM2 (,) gen arbitrary)
(liftShrink2 shr shrink)
- (\(x, y) -> shw x ++ "\n" ++ show y)
+ (\(x, y) -> shw x ++ [show y])
(uncurry f)
-- ** Exception handling
@@ -241,6 +242,10 @@ onRose f (IORose m) = IORose (fmap (onRose f) m)
protectRose :: IO (Rose Result) -> IO (Rose Result)
protectRose = protect (return . exception "Exception")
+-- | Wrap the top level of a 'Prop' in an exception handler.
+protectProp :: Prop -> Prop
+protectProp (MkProp r) = MkProp (IORose . protectRose . return $ r)
+
-- | Wrap all the Results in a rose tree in exception handlers.
protectResults :: Rose Result -> Rose Result
protectResults = onRose $ \x rs ->
@@ -754,6 +759,16 @@ True ==> p = property p
-- | Considers a property failed if it does not complete within
-- the given number of microseconds.
+--
+-- Note: if the property times out, variables quantified inside the
+-- `within` will not be printed. Therefore, you should use `within`
+-- only in the body of your property.
+--
+-- Good: @prop_foo a b c = within 1000000 ...@
+--
+-- Bad: @prop_foo = within 1000000 $ \\a b c -> ...@
+--
+-- Bad: @prop_foo a b c = ...; main = quickCheck (within 1000000 prop_foo)@
within :: Testable prop => Int -> prop -> Property
within n = mapRoseResult f
where
diff --git a/changelog b/changelog
index 0f8cb15..93486d0 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,6 @@
+QuickCheck 2.13.1 (release 2019-03-29)
+ * A couple of bug fixes
+
QuickCheck 2.13 (released 2019-03-26)
* Properties with multiple arguments now shrink better.
Previously, the first argument was shrunk, then the second, and
diff --git a/tests/Misc.hs b/tests/Misc.hs
new file mode 100644
index 0000000..016be56
--- /dev/null
+++ b/tests/Misc.hs
@@ -0,0 +1,26 @@
+-- Miscellaneous tests.
+
+{-# LANGUAGE TemplateHaskell #-}
+import Test.QuickCheck
+import Test.QuickCheck.Random
+
+prop_verbose :: Blind (Int -> Int -> Bool) -> Property
+prop_verbose (Blind p) =
+ forAll (mkQCGen <$> arbitrary) $ \g ->
+ ioProperty $ do
+ res1 <- quickCheckWithResult stdArgs{replay = Just (g, 100), chatty = False} p
+ res2 <- quickCheckWithResult stdArgs{replay = Just (g, 100), chatty = False} (verbose p)
+ return $
+ numTests res1 === numTests res2 .&&.
+ failingTestCase res1 === failingTestCase res2
+
+prop_failingTestCase :: Blind (Int -> Int -> Int -> Bool) -> Property
+prop_failingTestCase (Blind p) = ioProperty $ do
+ res <- quickCheckWithResult stdArgs{chatty = False} p
+ let [x, y, z] = failingTestCase res
+ return (not (p (read x) (read y) (read z)))
+
+return []
+main = do
+ True <- $quickCheckAll
+ return ()