Skip to content

Commit

Permalink
rename withWitness to witness and rename Cex to Wit
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAlgehed committed Apr 18, 2024
1 parent e37cfc5 commit c3f1a7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Test/QuickCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ module Test.QuickCheck
-- ** What to do on failure
#ifndef NO_TYPEABLE
, Witness(..)
, withWitness
, witness
, coerceWitness
, castWitness
#endif
Expand Down
14 changes: 7 additions & 7 deletions src/Test/QuickCheck/Property.hs
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,25 @@ data CallbackKind = Counterexample -- ^ Affected by the 'verbose' combinator
| NotCounterexample -- ^ Not affected by the 'verbose' combinator

#ifndef NO_TYPEABLE
data Witness = forall a. (Typeable a, Show a) => Cex a
data Witness = forall a. (Typeable a, Show a) => Wit a

instance Show Witness where
show (Cex a) = show a
show (Wit a) = show a

coerceWitness :: Typeable a => Witness -> a
coerceWitness (Cex a) = case cast a of
coerceWitness (Wit a) = case cast a of
Nothing -> error $ "Can't coerceWitness " ++ show a
Just a -> a

castWitness :: Typeable a => Witness -> Maybe a
castWitness (Cex a) = cast a
castWitness (Wit a) = cast a

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

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

#define WITNESSES(a) , theWitnesses a
#else
Expand Down Expand Up @@ -534,8 +534,8 @@ 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.
withWitness :: (Typeable a, Show a, Testable prop) => a -> prop -> Property
withWitness a = a `seq` mapTotalResult (\res -> res{ theWitnesses = Cex a : theWitnesses res })
witness :: (Typeable a, Show a, Testable prop) => a -> prop -> Property
witness a = a `seq` mapTotalResult (\res -> res{ theWitnesses = Wit a : theWitnesses res })
#endif

-- | Check that all coverage requirements defined by 'cover' and 'coverTable'
Expand Down
4 changes: 2 additions & 2 deletions src/Test/QuickCheck/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ data Result
-- ^ The test case's classes (see 'classify')
#ifndef NO_TYPEABLE
, witnesses :: [Witness]
-- ^ The existentially quantified witnesses provided by 'withWitness'
-- ^ The existentially quantified witnesses provided by 'witness'
#endif
}
-- | A property that should have failed did not
Expand Down Expand Up @@ -207,7 +207,7 @@ quickCheckWithResult a p =
-- | Test a property and get witnesses as a result. Can be used like:
--
-- @
-- $> x :! _ <- quickCheckWitnesses $ \ x -> withWitness (x :: Int) (x > 0)
-- $> x :! _ <- quickCheckWitnesses $ \ x -> witness (x :: Int) (x > 0)
-- *** Failed! Falsified (after 1 test):
-- 0
-- $> x
Expand Down

0 comments on commit c3f1a7c

Please sign in to comment.