Skip to content

Commit 6e7e910

Browse files
Initial stab at parallel actions
1 parent 252826f commit 6e7e910

File tree

11 files changed

+658
-159
lines changed

11 files changed

+658
-159
lines changed

quickcheck-dynamic/quickcheck-dynamic.cabal

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ source-repository head
2727
type: git
2828
location: https://github.com/input-output-hk/quickcheck-dynamic
2929

30+
flag dev
31+
default: False
32+
3033
common lang
3134
default-language: Haskell2010
3235
default-extensions:
@@ -62,6 +65,7 @@ common lang
6265
-Wall -Wnoncanonical-monad-instances -Wunused-packages
6366
-Wincomplete-uni-patterns -Wincomplete-record-updates
6467
-Wredundant-constraints -Widentities -Wno-unused-do-bind
68+
-Wno-name-shadowing -Wno-x-partial
6569

6670
library
6771
import: lang
@@ -76,6 +80,23 @@ library
7680
Test.QuickCheck.Extras
7781
Test.QuickCheck.StateModel
7882
Test.QuickCheck.StateModel.Variables
83+
Test.QuickCheck.ParallelActions
84+
85+
if flag(dev)
86+
hs-source-dirs: test
87+
exposed-modules:
88+
Spec.DynamicLogic.Counters
89+
Spec.DynamicLogic.Registry
90+
Spec.DynamicLogic.RegistryModel
91+
Test.QuickCheck.DynamicLogic.QuantifySpec
92+
Test.QuickCheck.StateModelSpec
93+
build-depends:
94+
, io-classes
95+
, io-sim
96+
, stm
97+
, tasty
98+
, tasty-hunit
99+
, tasty-quickcheck
79100

80101
build-depends:
81102
, base >=4.7 && <5
@@ -100,6 +121,8 @@ test-suite quickcheck-dynamic-test
100121
build-depends:
101122
, base
102123
, containers
124+
, io-classes
125+
, io-sim
103126
, mtl
104127
, QuickCheck
105128
, quickcheck-dynamic

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ instance Monad (DL s) where
6060
instance MonadFail (DL s) where
6161
fail = errorDL
6262

63-
action :: (Typeable a, Eq (Action s a), Show (Action s a)) => Action s a -> DL s (Var a)
63+
action :: (Typeable a, Show a, Eq (Action s a), Show (Action s a)) => Action s a -> DL s (Var a)
6464
action cmd = DL $ \_ k -> DL.after cmd k
6565

66-
failingAction :: (Typeable a, Eq (Action s a), Show (Action s a)) => Action s a -> DL s ()
66+
failingAction :: (Typeable a, Show a, Eq (Action s a), Show (Action s a)) => Action s a -> DL s ()
6767
failingAction cmd = DL $ \_ k -> DL.afterNegative cmd (k ())
6868

6969
anyAction :: DL s ()
@@ -96,7 +96,7 @@ getModelStateDL = DL $ \s k -> k (underlyingState s) s
9696
getVarContextDL :: DL s VarContext
9797
getVarContextDL = DL $ \s k -> k (vars s) s
9898

99-
forAllVar :: forall a s. Typeable a => DL s (Var a)
99+
forAllVar :: forall a s. (Typeable a, Show a) => DL s (Var a)
100100
forAllVar = do
101101
xs <- ctxAtType <$> getVarContextDL
102102
forAllQ $ elementsQ xs

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data DynLogic s
3333
Stopping (DynLogic s)
3434
| -- | After a specific action the predicate should hold
3535
forall a.
36-
(Eq (Action s a), Show (Action s a), Typeable a) =>
36+
(Eq (Action s a), Show (Action s a), Typeable a, Show a) =>
3737
After (ActionWithPolarity s a) (Var a -> DynPred s)
3838
| Error String (DynPred s)
3939
| -- | Adjust the probability of picking a branch
@@ -66,7 +66,7 @@ afterAny :: (Annotated s -> DynFormula s) -> DynFormula s
6666
afterAny f = DynFormula $ \n -> AfterAny $ \s -> unDynFormula (f s) n
6767

6868
afterPolar
69-
:: (Typeable a, Eq (Action s a), Show (Action s a))
69+
:: (Typeable a, Show a, Eq (Action s a), Show (Action s a))
7070
=> ActionWithPolarity s a
7171
-> (Var a -> Annotated s -> DynFormula s)
7272
-> DynFormula s
@@ -75,7 +75,7 @@ afterPolar act f = DynFormula $ \n -> After act $ \x s -> unDynFormula (f x s) n
7575
-- | Given `f` must be `True` after /some/ action.
7676
-- `f` is passed the state resulting from executing the `Action`.
7777
after
78-
:: (Typeable a, Eq (Action s a), Show (Action s a))
78+
:: (Typeable a, Show a, Eq (Action s a), Show (Action s a))
7979
=> Action s a
8080
-> (Var a -> Annotated s -> DynFormula s)
8181
-> DynFormula s
@@ -85,7 +85,7 @@ after act f = afterPolar (ActionWithPolarity act PosPolarity) f
8585
-- `f` is passed the state resulting from executing the `Action`
8686
-- as a negative action.
8787
afterNegative
88-
:: (Typeable a, Eq (Action s a), Show (Action s a))
88+
:: (Typeable a, Show a, Eq (Action s a), Show (Action s a))
8989
=> Action s a
9090
-> (Annotated s -> DynFormula s)
9191
-> DynFormula s
@@ -592,9 +592,11 @@ keepTryingUntil n g p = do
592592
shrinkDLTest :: DynLogicModel s => DynLogic s -> DynLogicTest s -> [DynLogicTest s]
593593
shrinkDLTest _ (Looping _) = []
594594
shrinkDLTest d tc =
595-
[ test | as' <- shrinkScript d (getScript tc), let pruned = pruneDLTest d as'
596-
test = makeTestFromPruned d pruned,
597-
-- Don't shrink a non-executable test case to an executable one.
595+
[ test
596+
| as' <- shrinkScript d (getScript tc)
597+
, let pruned = pruneDLTest d as'
598+
test = makeTestFromPruned d pruned
599+
, -- Don't shrink a non-executable test case to an executable one.
598600
case (tc, test) of
599601
(DLScript _, _) -> True
600602
(_, DLScript _) -> False
@@ -619,10 +621,10 @@ shrinkScript = shrink' initialAnnotatedState
619621
[TestSeqStep (unsafeCoerceVar var := act') ss | Some act'@ActionWithPolarity{} <- computeShrinkAction s act]
620622
++ [ TestSeqStep step ss'
621623
| ss' <-
622-
shrink'
623-
(nextStateStep step s)
624-
(stepDLStep d s step)
625-
ss
624+
shrink'
625+
(nextStateStep step s)
626+
(stepDLStep d s step)
627+
ss
626628
]
627629
nonstructural _ _ TestSeqStop = []
628630

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Test.QuickCheck.Extras where
22

33
import Control.Monad.Reader
44
import Control.Monad.State
5+
import Test.QuickCheck
56
import Test.QuickCheck.Monadic
67

78
runPropertyStateT :: Monad m => PropertyM (StateT s m) a -> s -> PropertyM m (a, s)
@@ -13,3 +14,9 @@ runPropertyReaderT :: Monad m => PropertyM (ReaderT e m) a -> e -> PropertyM m a
1314
runPropertyReaderT p e = MkPropertyM $ \k -> do
1415
m <- unPropertyM p $ fmap lift . k
1516
return $ runReaderT m e
17+
18+
sometimes :: Testable p => Int -> p -> Property
19+
sometimes i = disjoin . replicate i
20+
21+
always :: Testable p => Int -> p -> Property
22+
always i = conjoin . replicate i

0 commit comments

Comments
 (0)