From fdfa60c42e93b022b2d576a271091d43d642a1f2 Mon Sep 17 00:00:00 2001 From: Maximilian Algehed Date: Thu, 4 Apr 2024 10:41:37 +0200 Subject: [PATCH] Counterexample -> Witness --- src/Test/QuickCheck.hs | 12 +++++----- src/Test/QuickCheck/Property.hs | 40 ++++++++++++++++----------------- src/Test/QuickCheck/Test.hs | 16 ++++++------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Test/QuickCheck.hs b/src/Test/QuickCheck.hs index d9fb61ae..1782d654 100644 --- a/src/Test/QuickCheck.hs +++ b/src/Test/QuickCheck.hs @@ -79,8 +79,8 @@ module Test.QuickCheck , quickCheckWithResult , quickCheckResult #ifndef NO_TYPEABLE - , quickCheckCounterexample - , quickCheckWithCounterexample + , quickCheckWitness + , quickCheckWithWitness #endif , recheck , isSuccess @@ -323,10 +323,10 @@ module Test.QuickCheck , disjoin -- ** What to do on failure #ifndef NO_TYPEABLE - , Counterexample(..) - , withCounterexample - , coerceCounterexample - , castCounterexample + , Witness(..) + , withWitness + , coerceWitness + , castWitness #endif , counterexample , printTestCase diff --git a/src/Test/QuickCheck/Property.hs b/src/Test/QuickCheck/Property.hs index 21817678..75040935 100644 --- a/src/Test/QuickCheck/Property.hs +++ b/src/Test/QuickCheck/Property.hs @@ -256,29 +256,29 @@ data CallbackKind = Counterexample -- ^ Affected by the 'verbose' combinator | NotCounterexample -- ^ Not affected by the 'verbose' combinator #ifndef NO_TYPEABLE -data Counterexample = forall a. (Typeable a, Show a) => Cex a +data Witness = forall a. (Typeable a, Show a) => Cex a -instance Show Counterexample where +instance Show Witness where show (Cex a) = show a -coerceCounterexample :: Typeable a => Counterexample -> a -coerceCounterexample (Cex a) = case cast a of - Nothing -> error $ "Can't coerceCounterexample " ++ show a +coerceWitness :: Typeable a => Witness -> a +coerceWitness (Cex a) = case cast a of + Nothing -> error $ "Can't coerceWitness " ++ show a Just a -> a -castCounterexample :: Typeable a => Counterexample -> Maybe a -castCounterexample (Cex a) = cast a +castWitness :: Typeable a => Witness -> Maybe a +castWitness (Cex a) = cast a -data Counterexamples = NoCounterexamples - | forall a. (Typeable a, Show a) => a :! Counterexamples +data Witnesses = NoWitnesses + | forall a. (Typeable a, Show a) => a :! Witnesses -toCounterexamples :: [Counterexample] -> Counterexamples -toCounterexamples [] = NoCounterexamples -toCounterexamples (Cex a : ces) = a :! toCounterexamples ces +toWitnesses :: [Witness] -> Witnesses +toWitnesses [] = NoWitnesses +toWitnesses (Cex a : ces) = a :! toWitnesses ces -#define COUNTEREXAMPLES(a) , theCounterexamples a +#define WITNESSES(a) , theWitnesses a #else -#define COUNTEREXAMPLES(a) +#define WITNESSES(a) #endif -- | The result of a single test. @@ -316,7 +316,7 @@ data Result -- ^ the callbacks for this test case , testCase :: [String] -- ^ the generated test case - COUNTEREXAMPLES(:: [Counterexample]) + WITNESSES(:: [Witness]) } exception :: String -> AnException -> Result @@ -357,7 +357,7 @@ succeeded, failed, rejected :: Result , requiredCoverage = [] , callbacks = [] , testCase = [] - COUNTEREXAMPLES(= []) + WITNESSES(= []) } -------------------------------------------------------------------------- @@ -532,10 +532,10 @@ withMaxSize :: Testable prop => Int -> prop -> Property withMaxSize n = n `seq` mapTotalResult (\res -> res{ maybeMaxTestSize = Just n }) #ifndef NO_TYPEABLE --- | Return a value in the 'counterexamples' field of the 'Result' returned by 'quickCheckResult'. Counterexamples +-- | Return a value in the 'counterexamples' field of the 'Result' returned by 'quickCheckResult'. Witnesses -- are returned outer-most first. -withCounterexample :: (Typeable a, Show a, Testable prop) => a -> prop -> Property -withCounterexample a = a `seq` mapTotalResult (\res -> res{ theCounterexamples = Cex a : theCounterexamples res }) +withWitness :: (Typeable a, Show a, Testable prop) => a -> prop -> Property +withWitness a = a `seq` mapTotalResult (\res -> res{ theWitnesses = Cex a : theWitnesses res }) #endif -- | Check that all coverage requirements defined by 'cover' and 'coverTable' @@ -1001,7 +1001,7 @@ disjoin ps = testCase = testCase result1 ++ testCase result2 - COUNTEREXAMPLES(= theCounterexamples result1 ++ theCounterexamples result2) + WITNESSES(= theWitnesses result1 ++ theWitnesses result2) } Nothing -> result2 -- The "obvious" semantics of .||. has: diff --git a/src/Test/QuickCheck/Test.hs b/src/Test/QuickCheck/Test.hs index 1034eb65..ed90784b 100644 --- a/src/Test/QuickCheck/Test.hs +++ b/src/Test/QuickCheck/Test.hs @@ -145,8 +145,8 @@ data Result , failingClasses :: Set String -- ^ The test case's classes (see 'classify') #ifndef NO_TYPEABLE - , counterexamples :: [Counterexample] - -- ^ The existentially quantified counterexamples provided by 'withCounterexample' + , counterexamples :: [Witness] + -- ^ The existentially quantified counterexamples provided by 'withWitness' #endif } -- | A property that should have failed did not @@ -207,17 +207,17 @@ quickCheckWithResult a p = -- | Test a property and get counterexamples as a result. Can be used like: -- -- @ --- $> x :! _ <- quickCheckCounterexample $ \ x -> withCounterexample (x :: Int) (x > 0) +-- $> x :! _ <- quickCheckWitness $ \ x -> withWitness (x :: Int) (x > 0) -- *** Failed! Falsified (after 1 test): -- 0 -- $> x -- 0 -quickCheckCounterexample :: Testable prop => prop -> IO Counterexamples -quickCheckCounterexample = quickCheckWithCounterexample stdArgs +quickCheckWitness :: Testable prop => prop -> IO Witnesses +quickCheckWitness = quickCheckWithWitness stdArgs -- | Test a property, using test arguments, and get counterexamples as a result. -quickCheckWithCounterexample :: Testable prop => Args -> prop -> IO Counterexamples -quickCheckWithCounterexample args p = toCounterexamples . counterexamples <$> quickCheckWithResult args p +quickCheckWithWitness :: Testable prop => Args -> prop -> IO Witnesses +quickCheckWithWitness args p = toWitnesses . counterexamples <$> quickCheckWithResult args p #endif -- | Re-run a property with the seed and size that failed in a run of 'quickCheckResult'. @@ -508,7 +508,7 @@ runATest st prop = , failingLabels = P.labels res , failingClasses = Set.fromList (map fst $ filter snd $ P.classes res) #ifndef NO_TYPEABLE - , counterexamples = theCounterexamples res + , counterexamples = theWitnesses res #endif } where