Skip to content

Commit

Permalink
Add regression tests for infinitely looping shrinking of allNull `E…
Browse files Browse the repository at this point in the history
…rrors`.

When `allNull` holds for arbitrarily generated `Errors` and we start shrinking,
the shrinker will loop forever. The cause lies in the `genInfinite` function for
`Stream`s, which generates a finite list even though it is marked as infinite.
The next commit introduces a minimal bug fix.
  • Loading branch information
jorisdral committed Dec 9, 2024
1 parent 2d85d65 commit 4b8b851
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions fs-sim/test/Test/System/FS/Sim/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ tests = testGroup "Test.System.FS.Sim.Error" [
MockFS.fromBuffer mba 0 (fromIntegral $ BS.length bs) >>=
maybe (error "fromOutput: should not fail") pure
in propGetterGetsAll hGetBufSomeAtC get fromOutput p bs

-- Generators and shrinkers

, testProperty "prop_regression_shrinkNotAllNullErrors"
prop_regression_shrinkNotAllNullErrors
, testProperty "prop_regression_shrinkAllNullErrors"
prop_regression_shrinkAllNullErrors
]

instance Arbitrary BS.ByteString where
Expand Down Expand Up @@ -242,3 +249,15 @@ propGetterGetsAll getCounter get fromOutput (SometimesPartialReads errStream) bs
, hGetBufSomeE = errStream
, hGetBufSomeAtE = errStream
}

{-------------------------------------------------------------------------------
Generators and shrinkers
-------------------------------------------------------------------------------}

prop_regression_shrinkNotAllNullErrors :: Errors -> Property
prop_regression_shrinkNotAllNullErrors errs = expectFailure $
not (allNull errs) ==> property False

prop_regression_shrinkAllNullErrors :: Errors -> Property
prop_regression_shrinkAllNullErrors errs = expectFailure $
allNull errs ==> property False

0 comments on commit 4b8b851

Please sign in to comment.