@@ -11,7 +11,6 @@ module Test.QuickCheck.StateModel (
11
11
module Test.QuickCheck.StateModel.Variables ,
12
12
StateModel (.. ),
13
13
RunModel (.. ),
14
- PostconditionM (.. ),
15
14
WithUsedVars (.. ),
16
15
Annotated (.. ),
17
16
Step (.. ),
@@ -25,8 +24,6 @@ module Test.QuickCheck.StateModel (
25
24
Env ,
26
25
Generic ,
27
26
IsPerformResult ,
28
- monitorPost ,
29
- counterexamplePost ,
30
27
stateAfter ,
31
28
runActions ,
32
29
lookUpVar ,
@@ -40,16 +37,14 @@ module Test.QuickCheck.StateModel (
40
37
) where
41
38
42
39
import Control.Monad
43
- import Control.Monad.Reader
44
- import Control.Monad.Writer (WriterT , runWriterT , tell )
45
40
import Data.Data
46
41
import Data.List
47
- import Data.Monoid (Endo (.. ))
48
42
import Data.Set qualified as Set
49
43
import Data.Void
50
44
import GHC.Generics
51
45
import Test.QuickCheck as QC
52
46
import Test.QuickCheck.DynamicLogic.SmartShrinking
47
+ import Test.QuickCheck.Extras (liftProperty )
53
48
import Test.QuickCheck.Monadic
54
49
import Test.QuickCheck.StateModel.Variables
55
50
@@ -174,29 +169,6 @@ instance {-# OVERLAPPING #-} IsPerformResult Void a where
174
169
instance {-# OVERLAPPABLE #-} (PerformResult e a ~ Either e a ) => IsPerformResult e a where
175
170
performResultToEither = id
176
171
177
- newtype PostconditionM m a = PostconditionM { runPost :: WriterT (Endo Property , Endo Property ) m a }
178
- deriving (Functor , Applicative , Monad )
179
-
180
- instance MonadTrans PostconditionM where
181
- lift = PostconditionM . lift
182
-
183
- evaluatePostCondition :: Monad m => PostconditionM m Bool -> PropertyM m ()
184
- evaluatePostCondition post = do
185
- (b, (Endo mon, Endo onFail)) <- run . runWriterT . runPost $ post
186
- monitor mon
187
- unless b $ monitor onFail
188
- assert b
189
-
190
- -- | Apply the property transformation to the property after evaluating
191
- -- the postcondition. Useful for collecting statistics while avoiding
192
- -- duplication between `monitoring` and `postcondition`.
193
- monitorPost :: Monad m => (Property -> Property ) -> PostconditionM m ()
194
- monitorPost m = PostconditionM $ tell (Endo m, mempty )
195
-
196
- -- | Acts as `Test.QuickCheck.counterexample` if the postcondition fails.
197
- counterexamplePost :: Monad m => String -> PostconditionM m ()
198
- counterexamplePost c = PostconditionM $ tell (mempty , Endo $ counterexample c)
199
-
200
172
class (forall a . Show (Action state a ), Monad m ) => RunModel state m where
201
173
-- | Perform an `Action` in some `state` in the `Monad` `m`. This
202
174
-- is the function that's used to exercise the actual stateful
@@ -213,15 +185,15 @@ class (forall a. Show (Action state a), Monad m) => RunModel state m where
213
185
-- | Postcondition on the `a` value produced at some step.
214
186
-- The result is `assert`ed and will make the property fail should it be `False`. This is useful
215
187
-- to check the implementation produces expected values.
216
- postcondition :: (state , state ) -> Action state a -> LookUp -> a -> PostconditionM m Bool
217
- postcondition _ _ _ _ = pure True
188
+ postcondition :: (state , state ) -> Action state a -> LookUp -> a -> Property
189
+ postcondition _ _ _ _ = property True
218
190
219
191
-- | Postcondition on the result of running a _negative_ `Action`.
220
192
-- The result is `assert`ed and will make the property fail should it be `False`. This is useful
221
193
-- to check the implementation produces e.g. the expected errors or to check that the SUT hasn't
222
194
-- been updated during the execution of the negative action.
223
- postconditionOnFailure :: (state , state ) -> Action state a -> LookUp -> Either (Error state ) a -> PostconditionM m Bool
224
- postconditionOnFailure _ _ _ _ = pure True
195
+ postconditionOnFailure :: (state , state ) -> Action state a -> LookUp -> Either (Error state ) a -> Property
196
+ postconditionOnFailure _ _ _ _ = property True
225
197
226
198
-- | Allows the user to attach additional information to the `Property` at each step of the process.
227
199
-- This function is given the full transition that's been executed, including the start and ending
@@ -545,8 +517,8 @@ runSteps s env ((v := act) : as) = do
545
517
546
518
positiveActionSucceeded ret val = do
547
519
(s', env', stateTransition) <- computeNewState ret
548
- evaluatePostCondition $
549
- postcondition
520
+ liftProperty $
521
+ postcondition @ state @ m
550
522
stateTransition
551
523
action
552
524
(lookUpVar env)
@@ -555,8 +527,8 @@ runSteps s env ((v := act) : as) = do
555
527
556
528
negativeActionResult ret = do
557
529
(s', env', stateTransition) <- computeNewState ret
558
- evaluatePostCondition $
559
- postconditionOnFailure
530
+ liftProperty $
531
+ postconditionOnFailure @ state @ m
560
532
stateTransition
561
533
action
562
534
(lookUpVar env)
0 commit comments