Skip to content

Commit c0f14d3

Browse files
authored
Merge pull request #91 from fraser-iohk/fraser-iohk/support-QuickCheck-2.16
support QuickCheck-2.16
2 parents 6a4b08a + e033b7b commit c0f14d3

File tree

5 files changed

+30
-27
lines changed

5 files changed

+30
-27
lines changed

quickcheck-dynamic/src/Test/QuickCheck/DynamicLogic/Internal.hs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import Control.Applicative
44
import Control.Arrow (second)
55
import Control.Monad
66
import Data.Typeable
7-
import Test.QuickCheck hiding (generate)
7+
import Test.QuickCheck (Gen, Property, Testable)
8+
import Test.QuickCheck qualified as QC
89
import Test.QuickCheck.DynamicLogic.CanGenerate
910
import Test.QuickCheck.DynamicLogic.Quantify
1011
import Test.QuickCheck.DynamicLogic.SmartShrinking
@@ -359,8 +360,8 @@ forAllUniqueScripts s f k =
359360
let d = unDynFormula f sz
360361
n = unsafeNextVarIndex $ vars s
361362
in case generate chooseUniqueNextStep d n s 500 of
362-
Nothing -> counterexample "Generating Non-unique script in forAllUniqueScripts" False
363-
Just test -> validDLTest test . applyMonitoring d test . property $ k (scriptFromDL test)
363+
Nothing -> QC.counterexample "Generating Non-unique script in forAllUniqueScripts" False
364+
Just test -> validDLTest test . applyMonitoring d test . QC.property $ k (scriptFromDL test)
364365

365366
-- | Creates a `Property` from `DynFormula` with some specialised isomorphism for shrinking purpose.
366367
forAllMappedScripts
@@ -373,22 +374,22 @@ forAllMappedScripts
373374
forAllMappedScripts to from f k =
374375
QC.withSize $ \n ->
375376
let d = unDynFormula f n
376-
in forAllShrinkBlind
377-
(Smart 0 <$> sized ((from <$>) . generateDLTest d))
377+
in QC.forAllShrinkBlind
378+
(QC.Smart 0 <$> QC.sized ((from <$>) . generateDLTest d))
378379
(shrinkSmart ((from <$>) . shrinkDLTest d . to))
379-
$ \(Smart _ script) ->
380+
$ \(QC.Smart _ script) ->
380381
withDLScript d k (to script)
381382

382383
withDLScript :: (DynLogicModel s, Testable a) => DynLogic s -> (Actions s -> a) -> DynLogicTest s -> Property
383384
withDLScript d k test =
384-
validDLTest test . applyMonitoring d test . property $ k (scriptFromDL test)
385+
validDLTest test . applyMonitoring d test . QC.property $ k (scriptFromDL test)
385386

386387
withDLScriptPrefix :: (DynLogicModel s, Testable a) => DynFormula s -> (Actions s -> a) -> DynLogicTest s -> Property
387388
withDLScriptPrefix f k test =
388389
QC.withSize $ \n ->
389390
let d = unDynFormula f n
390391
test' = unfailDLTest d test
391-
in validDLTest test' . applyMonitoring d test' . property $ k (scriptFromDL test')
392+
in validDLTest test' . applyMonitoring d test' . QC.property $ k (scriptFromDL test')
392393

393394
-- | Validate generated test case.
394395
--
@@ -401,9 +402,9 @@ withDLScriptPrefix f k test =
401402
validDLTest :: StateModel s => DynLogicTest s -> Property -> Property
402403
validDLTest test prop =
403404
case test of
404-
DLScript{} -> counterexample (show test) prop
405-
Stuck{} -> property Discard
406-
_other -> counterexample (show test) False
405+
DLScript{} -> QC.counterexample (show test) prop
406+
Stuck{} -> QC.property QC.Discard
407+
_other -> QC.counterexample (show test) False
407408

408409
generateDLTest :: DynLogicModel s => DynLogic s -> Int -> Gen (DynLogicTest s)
409410
generateDLTest d size = generate chooseNextStep d 0 (initialStateFor d) size
@@ -516,7 +517,7 @@ nextSteps' gen (ForAll q f) = do
516517
nextSteps' gen (Monitor _f d) = nextSteps' gen d
517518

518519
chooseOneOf :: [(Double, a)] -> Gen a
519-
chooseOneOf steps = frequency [(round (w / never), return s) | (w, s) <- steps]
520+
chooseOneOf steps = QC.frequency [(round (w / never), return s) | (w, s) <- steps]
520521

521522
never :: Double
522523
never = 1.0e-9
@@ -586,7 +587,7 @@ keepTryingUntil :: Int -> Gen a -> (a -> Bool) -> Gen (Maybe a)
586587
keepTryingUntil 0 _ _ = return Nothing
587588
keepTryingUntil n g p = do
588589
x <- g
589-
if p x then return $ Just x else scale (+ 1) $ keepTryingUntil (n - 1) g p
590+
if p x then return $ Just x else QC.scale (+ 1) $ keepTryingUntil (n - 1) g p
590591

591592
shrinkDLTest :: DynLogicModel s => DynLogic s -> DynLogicTest s -> [DynLogicTest s]
592593
shrinkDLTest _ (Looping _) = []
@@ -710,7 +711,7 @@ demonicAlt ds = foldr1 (Alt Demonic) ds
710711

711712
propPruningGeneratedScriptIsNoop :: DynLogicModel s => DynLogic s -> Property
712713
propPruningGeneratedScriptIsNoop d =
713-
forAll (sized $ \n -> choose (1, max 1 n) >>= generateDLTest d) $ \test ->
714+
QC.forAll (QC.sized $ \n -> QC.choose (1, max 1 n) >>= generateDLTest d) $ \test ->
714715
let script = case test of
715716
BadPrecondition s _ _ -> s
716717
Looping s -> s

quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ import Data.Monoid (Endo (..))
5656
import Data.Set qualified as Set
5757
import Data.Void
5858
import GHC.Generics
59-
import Test.QuickCheck as QC
59+
import Test.QuickCheck (Arbitrary, Gen, Property, Smart (..), Testable, counterexample, forAllShrink, frequency, property, resize, shrinkList, sized, tabulate)
60+
import Test.QuickCheck qualified as QC
6061
import Test.QuickCheck.DynamicLogic.SmartShrinking
6162
import Test.QuickCheck.Monadic
6263
import Test.QuickCheck.StateModel.Variables

quickcheck-dynamic/src/Test/QuickCheck/StateModel/Variables.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Data.Set qualified as Set
3131
import GHC.Generics
3232
import GHC.TypeLits
3333
import GHC.Word
34-
import Test.QuickCheck as QC
34+
import Test.QuickCheck (Gen, Smart (..), elements)
3535

3636
-- | A symbolic variable for a value of type `a`
3737
newtype Var a = Var Int

quickcheck-dynamic/test/Spec/DynamicLogic/Counters.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Spec.DynamicLogic.Counters where
66

77
import Control.Monad.Reader
88
import Data.IORef
9-
import Test.QuickCheck
9+
import Test.QuickCheck (frequency)
1010
import Test.QuickCheck.StateModel
1111

1212
-- A very simple model with a single action that always succeed in

quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Data.Either
1010
import Data.List
1111
import Data.Map (Map)
1212
import Data.Map qualified as Map
13-
import Test.QuickCheck
13+
import Test.QuickCheck (Gen, Property)
14+
import Test.QuickCheck qualified as QC
1415
import Test.QuickCheck.Monadic hiding (assert)
1516
import Test.QuickCheck.Monadic qualified as QC
1617
import Test.Tasty hiding (after)
@@ -56,7 +57,7 @@ instance StateModel RegState where
5657

5758
arbitraryAction ctx s =
5859
let threadIdCtx = ctxAtType @ThreadId ctx
59-
in frequency $
60+
in QC.frequency $
6061
[
6162
( max 1 $ 10 - length threadIdCtx
6263
, return $ Some Spawn
@@ -135,15 +136,15 @@ instance RunModel RegState RegM where
135136

136137
postconditionOnFailure (s, _) act@Register{} _ res = do
137138
monitorPost $
138-
tabulate
139+
QC.tabulate
139140
"Reason for -Register"
140141
[why s act]
141142
pure $ isLeft res
142143
postconditionOnFailure _s _ _ _ = pure True
143144

144145
monitoring (_s, s') act@(showDictAction -> ShowDict) _ res =
145-
counterexample (show res ++ " <- " ++ show act ++ "\n -- State: " ++ show s')
146-
. tabulate "Registry size" [show $ Map.size (regs s')]
146+
QC.counterexample (show res ++ " <- " ++ show act ++ "\n -- State: " ++ show s')
147+
. QC.tabulate "Registry size" [show $ Map.size (regs s')]
147148

148149
data ShowDict a where
149150
ShowDict :: Show a => ShowDict a
@@ -167,13 +168,13 @@ why s (Register name tid) =
167168
why _ _ = "(impossible)"
168169

169170
arbitraryName :: Gen String
170-
arbitraryName = elements allNames
171+
arbitraryName = QC.elements allNames
171172

172173
probablyRegistered :: RegState -> Gen String
173-
probablyRegistered s = oneof $ map pure (Map.keys $ regs s) ++ [arbitraryName]
174+
probablyRegistered s = QC.oneof $ map pure (Map.keys $ regs s) ++ [arbitraryName]
174175

175176
probablyUnregistered :: RegState -> Gen String
176-
probablyUnregistered s = elements $ allNames ++ (allNames \\ Map.keys (regs s))
177+
probablyUnregistered s = QC.elements $ allNames ++ (allNames \\ Map.keys (regs s))
177178

178179
shrinkName :: String -> [String]
179180
shrinkName name = [n | n <- allNames, n < name]
@@ -184,7 +185,7 @@ allNames = ["a", "b", "c", "d", "e"]
184185
prop_Registry :: Actions RegState -> Property
185186
prop_Registry s =
186187
monadicIO $ do
187-
monitor $ counterexample "\nExecution\n"
188+
monitor $ QC.counterexample "\nExecution\n"
188189
reg <- lift setupRegistry
189190
runPropertyReaderT (runActions s) reg
190191
QC.assert True
@@ -270,5 +271,5 @@ tests =
270271
[ testProperty "prop_Registry" $ prop_Registry
271272
, testProperty "moreActions 10 $ prop_Registry" $ moreActions 10 prop_Registry
272273
, testProperty "canRegister" $ propDL canRegister
273-
, testProperty "canRegisterNoUnregister" $ expectFailure $ propDL canRegisterNoUnregister
274+
, testProperty "canRegisterNoUnregister" $ QC.expectFailure $ propDL canRegisterNoUnregister
274275
]

0 commit comments

Comments
 (0)