@@ -339,8 +339,7 @@ restrictedPolar (ActionWithPolarity a _) = restricted a
339339
340340-- | Simplest "execution" function for `DynFormula`.
341341-- Turns a given a `DynFormula` paired with an interpreter function to produce some result from an
342-
343- --- `Actions` sequence into a proper `Property` than can then be run by QuickCheck.
342+ -- `Actions` sequence into a proper `Property` that can be run by QuickCheck.
344343forAllScripts
345344 :: (DynLogicModel s , Testable a )
346345 => DynFormula s
@@ -361,7 +360,7 @@ forAllUniqueScripts s f k =
361360 n = unsafeNextVarIndex $ vars s
362361 in case generate chooseUniqueNextStep d n s 500 of
363362 Nothing -> counterexample " Generating Non-unique script in forAllUniqueScripts" False
364- Just test -> validDLTest d test . applyMonitoring d test . property $ k (scriptFromDL test)
363+ Just test -> validDLTest test . applyMonitoring d test . property $ k (scriptFromDL test)
365364
366365-- | Creates a `Property` from `DynFormula` with some specialised isomorphism for shrinking purpose.
367366forAllMappedScripts
@@ -382,14 +381,29 @@ forAllMappedScripts to from f k =
382381
383382withDLScript :: (DynLogicModel s , Testable a ) => DynLogic s -> (Actions s -> a ) -> DynLogicTest s -> Property
384383withDLScript d k test =
385- validDLTest d test . applyMonitoring d test . property $ k (scriptFromDL test)
384+ validDLTest test . applyMonitoring d test . property $ k (scriptFromDL test)
386385
387386withDLScriptPrefix :: (DynLogicModel s , Testable a ) => DynFormula s -> (Actions s -> a ) -> DynLogicTest s -> Property
388387withDLScriptPrefix f k test =
389388 QC. withSize $ \ n ->
390389 let d = unDynFormula f n
391390 test' = unfailDLTest d test
392- in validDLTest d test' . applyMonitoring d test' . property $ k (scriptFromDL test')
391+ in validDLTest test' . applyMonitoring d test' . property $ k (scriptFromDL test')
392+
393+ -- | Validate generated test case.
394+ --
395+ -- Test case generation does not always produce a valid test case. In
396+ -- some cases, we did not find a suitable test case matching some
397+ -- `DynFormula` and we are `Stuck`, hence we want to discard the test
398+ -- case and start over ; in other cases we found a genuine issue with
399+ -- the formula leading to the impossibility of producing a valid test
400+ -- case.
401+ validDLTest :: StateModel s => DynLogicTest s -> Property -> Property
402+ validDLTest test prop =
403+ case test of
404+ DLScript {} -> counterexample (show test) prop
405+ Stuck {} -> property Discard
406+ _other -> counterexample (show test) False
393407
394408generateDLTest :: DynLogicModel s => DynLogic s -> Int -> Gen (DynLogicTest s )
395409generateDLTest d size = generate chooseNextStep d 0 (initialStateFor d) size
@@ -763,11 +777,6 @@ stuck (Weight w d) s = w < never || stuck d s
763777stuck (ForAll _ _) _ = False
764778stuck (Monitor _ d) s = stuck d s
765779
766- validDLTest :: StateModel s => DynLogic s -> DynLogicTest s -> Property -> Property
767- validDLTest _ Stuck {} _ = False ==> False
768- validDLTest _ test@ DLScript {} p = counterexample (show test) p
769- validDLTest _ test _ = counterexample (show test) False
770-
771780scriptFromDL :: DynLogicTest s -> Actions s
772781scriptFromDL (DLScript s) = Actions $ sequenceSteps s
773782scriptFromDL _ = Actions []
0 commit comments