nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
717 stars 119 forks source link

`checkCoverage` interacts poorly with discards #382

Closed MaximilianAlgehed closed 6 months ago

MaximilianAlgehed commented 6 months ago

The following has been a thorn in my side in another project and here is a minimal failing example:

prop_discardCoverage :: Property
prop_discardCoverage = forAll (sized $ \ n -> pure n) $ \ x -> cover 10 True "label" $ x /= 99 ==> True

What happens is that we get a failure like:

$> quickCheck $ checkCoverage prop_discardCoverage 
*** Gave up! Passed only 99 tests; 1 discarded tests (100% label).

when we expect the property to succeed. The reason for this is that on the 99th test (with size 98) we run addCoverageCheck which adds a once around the property. In the next test we are "unlucky" (in the real world this test is also flaky!!) and hit the discarded test, causing the whole test to be discarded because we discarded a once.

I have a fix for this in the pipeline.