Skip to content

Commit

Permalink
react to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAlgehed committed Apr 18, 2024
1 parent 8a61a78 commit 2336786
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
4 changes: 0 additions & 4 deletions src/Test/QuickCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ module Test.QuickCheck
, quickCheckWith
, quickCheckWithResult
, quickCheckResult
#ifndef NO_TYPEABLE
, quickCheckWitnesses
, quickCheckWithWitnesses
#endif
, recheck
, isSuccess
-- ** Running tests verbosely
Expand Down
17 changes: 10 additions & 7 deletions src/Test/QuickCheck/Property.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,6 @@ coerceWitness (Wit a) = case cast a of
castWitness :: Typeable a => Witness -> Maybe a
castWitness (Wit a) = cast a

data Witnesses = NoWitnesses
| forall a. (Typeable a, Show a) => a :! Witnesses

toWitnesses :: [Witness] -> Witnesses
toWitnesses [] = NoWitnesses
toWitnesses (Wit a : ces) = a :! toWitnesses ces

#define WITNESSES(a) , theWitnesses a
#else
#define WITNESSES(a)
Expand Down Expand Up @@ -534,6 +527,16 @@ withMaxSize n = n `seq` mapTotalResult (\res -> res{ maybeMaxTestSize = Just n }
#ifndef NO_TYPEABLE
-- | Return a value in the 'witnesses' field of the 'Result' returned by 'quickCheckResult'. Witnesses
-- are returned outer-most first.
--
-- In ghci, for example:
--
-- >>> [Wit x] <- fmap witnesses . quickCheckResult $ \ x -> witness x $ x == (0 :: Int)
-- *** Failed! Falsified (after 2 tests):
-- 1
-- >>> x
-- 1
-- >>> :t x
-- x :: Int
witness :: (Typeable a, Show a, Testable prop) => a -> prop -> Property
witness a = a `seq` mapTotalResult (\res -> res{ theWitnesses = Wit a : theWitnesses res })
#endif
Expand Down
17 changes: 0 additions & 17 deletions src/Test/QuickCheck/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,6 @@ quickCheckWithResult :: Testable prop => Args -> prop -> IO Result
quickCheckWithResult a p =
withState a (\s -> test s (property p))

#ifndef NO_TYPEABLE
-- | Test a property and get witnesses as a result. Can be used like:
--
-- @
-- $> x :! _ <- quickCheckWitnesses $ \ x -> witness (x :: Int) (x > 0)
-- *** Failed! Falsified (after 1 test):
-- 0
-- $> x
-- 0
quickCheckWitnesses :: Testable prop => prop -> IO Witnesses
quickCheckWitnesses = quickCheckWithWitnesses stdArgs

-- | Test a property, using test arguments, and get witnesses as a result.
quickCheckWithWitnesses :: Testable prop => Args -> prop -> IO Witnesses
quickCheckWithWitnesses args p = toWitnesses . witnesses <$> quickCheckWithResult args p
#endif

-- | Re-run a property with the seed and size that failed in a run of 'quickCheckResult'.
recheck :: Testable prop => Result -> prop -> IO ()
recheck res@Failure{} = quickCheckWith stdArgs{ replay = Just (usedSeed res, usedSize res)} . once
Expand Down

0 comments on commit 2336786

Please sign in to comment.