Skip to content

Commit

Permalink
Abort tests where coverage cannot be reached
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmulder committed May 11, 2019
1 parent e5ce474 commit 8dbbdf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions hedgehog-example/src/Test/Example/Confidence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import qualified Hedgehog.Internal.Gen as Gen
-- Example 0: This test will certify that it is impossible to get 100%
-- coverage for the property label "number == 1"
--
-- Note that it will abort running once it knows its task is
-- impossible - it will not run 1000000 tests
--
prop_without_confidence :: Property
prop_without_confidence =
withConfidence (10^9) . withTests 100 . property $ do
withConfidence (10^9) . withTests 1000000 . property $ do
number <- forAll (Gen.int $ Range.linear 1 10)
cover 100 "number == 1" $ number == 1
cover 60 "number == 1" $ number == 1

------------------------------------------------------------------------
tests :: IO Bool
Expand Down
18 changes: 14 additions & 4 deletions hedgehog/src/Hedgehog/Internal/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ checkReport cfg size0 seed0 test0 updateUI =
-- size has reached limit, reset to 0
loop tests discards 0 seed coverage0

else if failureVerified tests coverage0 then
-- tests have been verified to not reach coverage for at least one label
pure . Report tests discards coverage0 . Failed $
mkFailure
size
seed
0
(Just coverage0)
Nothing
"Test coverage cannot be reached, aborted"
Nothing
[]

else if tests >= fromIntegral (propertyTestLimit cfg) then
-- we've hit the test limit
if successVerified tests coverage0 then
Expand All @@ -207,10 +220,7 @@ checkReport cfg size0 seed0 test0 updateUI =
0
(Just coverage0)
Nothing
(if failureVerified tests coverage0 then
"Could not meet confidence criteria."
else
"Insufficient coverage.")
"Insufficient coverage."
Nothing
[]

Expand Down

0 comments on commit 8dbbdf0

Please sign in to comment.