From ec6eed9a7fb59236ee6a9dbab200931bd1db6aea Mon Sep 17 00:00:00 2001 From: Alain Zscheile Date: Fri, 23 Sep 2022 07:54:00 +0200 Subject: [PATCH] fix(bytecode): make sure the proptest runs long enough --- crates/fogtix-bytecode/src/instr.rs | 11 ++++++++--- crates/fogtix-bytecode/src/value.rs | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/fogtix-bytecode/src/instr.rs b/crates/fogtix-bytecode/src/instr.rs index c51020c..f6f1030 100644 --- a/crates/fogtix-bytecode/src/instr.rs +++ b/crates/fogtix-bytecode/src/instr.rs @@ -93,11 +93,16 @@ mod tests { use super::*; proptest::proptest! { + #![proptest_config(proptest::prelude::ProptestConfig::with_cases(4096))] + #[test] - fn doesnt_crash(inp in proptest::collection::vec(0..=u8::MAX, 0..256)) { - if let Ok((_, v)) = >::parse(&inp[..]) { - let mut buf = alloc::vec::Vec::with_capacity(inp.len()); + fn doesnt_crash(inp in proptest::collection::vec(0..=u8::MAX, 0..1024)) { + let mut inp = &inp[..]; + while let Ok((xinp, v)) = >::parse(&inp[..]) { + let mut buf = alloc::vec::Vec::with_capacity(inp.len() - xinp.len()); v.write_to(&mut buf).unwrap(); + assert_eq!(buf[..], inp[..inp.len() - xinp.len()]); + inp = xinp; } } } diff --git a/crates/fogtix-bytecode/src/value.rs b/crates/fogtix-bytecode/src/value.rs index 3efc280..534f673 100644 --- a/crates/fogtix-bytecode/src/value.rs +++ b/crates/fogtix-bytecode/src/value.rs @@ -110,11 +110,16 @@ mod tests { use super::*; proptest::proptest! { + #![proptest_config(proptest::prelude::ProptestConfig::with_cases(4096))] + #[test] - fn doesnt_crash(inp in proptest::collection::vec(0..=u8::MAX, 0..256)) { - if let Ok((_, v)) = >::parse(&inp[..]) { - let mut buf = alloc::vec::Vec::with_capacity(inp.len()); + fn doesnt_crash(inp in proptest::collection::vec(0..=u8::MAX, 0..1024)) { + let mut inp = &inp[..]; + while let Ok((xinp, v)) = >::parse(&inp[..]) { + let mut buf = alloc::vec::Vec::with_capacity(inp.len() - xinp.len()); v.write_to(&mut buf).unwrap(); + assert_eq!(buf[..], inp[..inp.len() - xinp.len()]); + inp = xinp; } } }