To my surprise this test doesn't fail (I ran it ~10 times):
#[test]
fn my_test() {
arbtest::arbtest(|u| {
let x: Vec<u8> = u.arbitrary()?;
assert!(x.len() < 10);
Ok(())
})
.budget_ms(10000) // Try really hard
.size_min(100000) // Provide a lot of bytes
.size_max(100000000);
}
I know, property-based testing is very limited. But this limit seems to be quite small (in comparison to something like quickcheck). And the limit can't be extended easily by increasing the budget or size parameters.
I checked the implementation of Arbitrary for Vec in the arbitrary crate:
impl<'a, A: Arbitrary<'a>> Arbitrary<'a> for Vec<A> {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary_iter()?.collect()
}
...
}
And here the implementation of the Iterator returned by arbitrary_iter:
impl<'a, 'b, ElementType: Arbitrary<'a>> Iterator for ArbitraryIter<'a, 'b, ElementType> {
type Item = Result<ElementType>;
fn next(&mut self) -> Option<Result<ElementType>> {
let keep_going = self.u.arbitrary().unwrap_or(false);
if keep_going {
Some(Arbitrary::arbitrary(self.u))
} else {
None
}
}
}
As far as I know arbtest is using random bytes for Unstructured (instead of using a feedback loop like a fuzzer). Based on the implementation above I can understand why the generated Vecs are so small. But still, it doesn't feel right. Did I do something wrong?
Tested with arbtest 0.3.1 and arbitrary 1.3.2.
To my surprise this test doesn't fail (I ran it ~10 times):
I know, property-based testing is very limited. But this limit seems to be quite small (in comparison to something like quickcheck). And the limit can't be extended easily by increasing the budget or size parameters.
I checked the implementation of
ArbitraryforVecin the arbitrary crate:And here the implementation of the
Iteratorreturned byarbitrary_iter:As far as I know arbtest is using random bytes for
Unstructured(instead of using a feedback loop like a fuzzer). Based on the implementation above I can understand why the generatedVecs are so small. But still, it doesn't feel right. Did I do something wrong?Tested with arbtest 0.3.1 and arbitrary 1.3.2.