Skip to content

Commit

Permalink
A monitoring callback called when a positive action fails
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAlgehed committed Dec 15, 2023
1 parent b712579 commit fb036f5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import Data.List
import Data.Monoid (Endo (..))
import Data.Set qualified as Set
import GHC.Generics
import GHC.Stack
import Test.QuickCheck as QC
import Test.QuickCheck.DynamicLogic.SmartShrinking
import Test.QuickCheck.Monadic
Expand Down Expand Up @@ -211,6 +210,10 @@ class (forall a e. Show (Action state e a), Monad m) => RunModel state m where
monitoring :: (state, state) -> Action state e a -> LookUp m -> Either (Realized m e) (Realized m a) -> Property -> Property
monitoring _ _ _ _ prop = prop

-- | Allows the user to attach additional information to the `Property` if a positive action fails.
monitoringFailure :: state -> Action state e a -> LookUp m -> Realized m e -> Property -> Property
monitoringFailure _ _ _ _ prop = prop

computePostcondition
:: forall m state e a
. RunModel state m
Expand Down Expand Up @@ -500,6 +503,10 @@ runActions (Actions_ rejected (Smart _ actions)) = loop initialAnnotatedState []
| otherwise = env
monitor $ tabulate "Action polarity" [show $ polarity act]
monitor $ monitoring @state @m (underlyingState s, underlyingState s') (polarAction act) (lookUpVar env') ret
when (polarity act == PosPolarity) $ do
case ret of
Left e -> monitor $ monitoringFailure @state @m (underlyingState s) (polarAction act) (lookUpVar env') e
_ -> pure ()
(b, (Endo mon, Endo onFail)) <-
run
. runWriterT
Expand Down

0 comments on commit fb036f5

Please sign in to comment.