Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions QuickCheck.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,14 @@ Test-Suite test-quickcheck-monoids
cpp-options: -DNO_SEMIGROUP_SUPERCLASS
if !impl(ghc >= 8.0)
cpp-options: -DNO_SEMIGROUP_CLASS

Test-Suite test-quickcheck-tabulate-slow
type: exitcode-stdio-1.0
Default-language: Haskell2010
hs-source-dirs: tests
main-is: TabulateSlow.hs
build-depends: base, QuickCheck
if !impl(ghc >= 8.4)
cpp-options: -DNO_SEMIGROUP_SUPERCLASS
if !impl(ghc >= 8.0)
cpp-options: -DNO_SEMIGROUP_CLASS
13 changes: 8 additions & 5 deletions src/Test/QuickCheck/Property.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ instance Testable prop => Testable (Gen prop) where
property mp = MkProperty $ do p <- mp; unProperty (property p)

instance Testable Property where
property (MkProperty mp) = MkProperty (fmap protectProp mp)
property = id

-- | Do I/O inside a property.
{-# DEPRECATED morallyDubiousIOProperty "Use 'ioProperty' instead" #-}
Expand Down Expand Up @@ -241,10 +241,13 @@ 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 ->
IORose $ do
y <- protectResult (return x)
return (MkRose y (map protectResults rs))
protectResults = IORose . protect'
where
protect' :: Rose Result -> IO (Rose Result)
protect' (MkRose x rs) = do
y <- protectResult (return x)
return (MkRose y (map protectResults rs))
protect' (IORose m) = m >>= protect'

-- ** Result type

Expand Down
3 changes: 2 additions & 1 deletion src/Test/QuickCheck/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ quickCheckResult p = quickCheckWithResult stdArgs p
-- | Tests a property, using test arguments, produces a test result, and prints the results to 'stdout'.
quickCheckWithResult :: Testable prop => Args -> prop -> IO Result
quickCheckWithResult a p =
withState a (\s -> test s (property p))
let MkProperty mp = property p
in withState a (\s -> test s $ MkProperty $ fmap protectProp mp)

-- | Re-run a property with the seed and size that failed in a run of 'quickCheckResult'.
recheck :: Testable prop => Result -> prop -> IO ()
Expand Down
18 changes: 18 additions & 0 deletions tests/TabulateSlow.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Test.QuickCheck
import Test.QuickCheck.Monadic
import Control.Monad
import System.Exit

prop_tabulateALot :: Int -> Property
prop_tabulateALot x =
tabulates 1000
where
tabulates 0 = x === x
tabulates n =
tabulate "World" ["Hello"] $
tabulate "Hello" (["World" | even n] ++ ["There" | odd n]) $
tabulates (n - 1)

main = do
r <- quickCheckResult $ within 10000 $ forAll arbitrary prop_tabulateALot
unless (isSuccess r) exitFailure