BurntSushi / quickcheck

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

Negating an integer leads to stack overflow #301

Open Heroglyph opened 2 years ago

Heroglyph commented 2 years ago

MWE:

use quickcheck::quickcheck;

#[test]
fn negate_value() {
    fn prop(i: i8) -> bool {
        -i;
        true
    }

    quickcheck(prop as fn(i8) -> bool);
}

I think that quickcheck tests this function with the smallest integer, which panics because it cannot be negated due to two's complement. So far, so correct. The resulting panic is then caught and correctly interpreted to be caused by a failed test. However, attempting to shrink the value causes another panic, which causes another attempt at shrinking, causing another panic and so on, ultimately resulting in a stack overflow as the shrinking functions pile on top of each other. This seems to be a bug in the way that shrinking is done (because it keeps testing the same value). How do we proceed?

neithernut commented 2 years ago

The endless recursion is likely a symptom of i8's shrinker yielding the original value. See #295 for a related issue.Could you check whether #296 resolves your issue?

Heroglyph commented 2 years ago

I checked by trying the current BurntShushi:master and neithernut:i32min-shrink-bound (revision 0c279d6). The latter revision (yours), fixed the issue, so merging the pull request should resolve my problem. Thank you!