BurntSushi / quickcheck

Automated property based testing for Rust (with shrinking).
The Unlicense
2.4k stars 149 forks source link

Add a wrapper for disabling shrinking for an Arbitrary #293

Open neithernut opened 3 years ago

neithernut commented 3 years ago

In some cases, users may want to disable shrinking for a specific test. Consider, for example, some complex recursive data type. Naturally, we'd want values to be shrunk for most tests in order to isolate the specific sub-structure provoking the failure. However, due to the complexity we may end up with a shrinker with a certain complexity in itself. Hence, we may want to test our shrinker. For those specific tests, the very shrinking of input values performed by quickcheck could get in our way or cause failures on its own.

Previously, the only way library users could disable shrinking in such cases was to define a wrapper type (in their own code) which forwarded Arbitrary::arbitrary but not Arbitrary::shrink. We suspect that the possibility of disabling shrinking for selected tests, such as in cases described above, is not too uncommon. The wrapper pattern is easy to understand and blends in well with quickcheck. Shipping one with the library will suit the described use-cases.

The feature was requested in https://github.com/BurntSushi/quickcheck/issues/285#issuecomment-830269716, the wrapper pattern was suggested as a user-side solution in https://github.com/BurntSushi/quickcheck/issues/285#issuecomment-830281502.