Skip to content

Commit c34a6fd

Browse files
authored
fix: make all structured input unbounded by default (#301)
1 parent 18e0a9b commit c34a6fd

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

lib/bolero/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ impl<G, Engine, InputOwnership> TestTarget<G, Engine, InputOwnership> {
289289
self.driver_options.set_exhaustive(true);
290290
self
291291
}
292+
293+
fn as_unbounded_options(&self) -> bolero_generator::driver::Options {
294+
let mut options = self.driver_options.clone();
295+
if options.max_len().is_none() {
296+
options.set_max_len(usize::MAX);
297+
}
298+
options
299+
}
292300
}
293301

294302
impl<G: generator::ValueGenerator, Engine, InputOwnership> TestTarget<G, Engine, InputOwnership> {
@@ -439,8 +447,9 @@ where
439447
E: Engine<bolero_engine::BorrowedGeneratorTest<F, G, G::Output>>,
440448
bolero_engine::BorrowedGeneratorTest<F, G, G::Output>: Test,
441449
{
450+
let options = self.as_unbounded_options();
442451
let test = bolero_engine::BorrowedGeneratorTest::new(test, self.generator);
443-
self.engine.run(test, self.driver_options)
452+
self.engine.run(test, options)
444453
}
445454
}
446455

@@ -454,8 +463,9 @@ where
454463
E: Engine<bolero_engine::ClonedGeneratorTest<F, G, G::Output>>,
455464
bolero_engine::ClonedGeneratorTest<F, G, G::Output>: Test,
456465
{
466+
let options = self.as_unbounded_options();
457467
let test = bolero_engine::ClonedGeneratorTest::new(test, self.generator);
458-
self.engine.run(test, self.driver_options)
468+
self.engine.run(test, options)
459469
}
460470
}
461471

@@ -478,7 +488,8 @@ impl<E> TestTarget<ByteSliceGenerator, E, BorrowedInput> {
478488
R: bolero_engine::IntoResult,
479489
E: bolero_engine::ScopedEngine,
480490
{
481-
self.engine.run(test, self.driver_options)
491+
let options = self.as_unbounded_options();
492+
self.engine.run(test, options)
482493
}
483494
}
484495

lib/bolero/src/tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,37 @@ fn scope_exhaustive_panic_test() {
197197
assert!(any::<bool>(), "oops");
198198
});
199199
}
200+
201+
/// This test verifies that run() uses unbounded entropy by default (max_len = usize::MAX)
202+
#[test]
203+
fn scope_unbounded_entropy_test() {
204+
check!().with_iterations(1).run(|| {
205+
// Generate 1000 u64 values, which requires 8000 bytes of entropy
206+
// This exceeds the default max_len of 4096 bytes
207+
for _ in 0..1000 {
208+
let _: u64 = any();
209+
}
210+
211+
for _ in 0..1000 {
212+
if any() {
213+
return;
214+
}
215+
}
216+
217+
panic!("did not generate non-empty entropy as expected");
218+
});
219+
}
220+
221+
/// Verify that when max_len is explicitly set, it is still respected
222+
#[test]
223+
fn scope_explicit_max_len_test() {
224+
check!().with_max_len(100).with_iterations(5).run(|| {
225+
for _ in 0..1000 {
226+
let _: u64 = any();
227+
}
228+
229+
for _ in 0..1000 {
230+
assert_eq!(any::<u8>(), 0u8);
231+
}
232+
});
233+
}

0 commit comments

Comments
 (0)