macro_rules! check {
() => { ... };
($fun:path) => { ... };
(| $input:ident $(: &[u8])? | $impl:expr) => { ... };
(| $input:ident : $ty:ty | $impl:expr) => { ... };
(name = $target_name:expr) => { ... };
}
Expand description
Execute tests for a given target
This should be executed in a separate test target, for example
tests/my_test_target/main.rs
.
Examples
By default, input
is a &[u8]
.
This mode is generally used when testing an implementation that handles raw bytes, e.g. a parser.
use bolero::check;
check!().for_each(|input| {
// implement checks here
});
Calling with_type::<Type>()
will generate random values of Type
to be tested. Type
is required to implement generator::TypeGenerator
in order to use this method.
This mode is used for testing an implementation that requires structured input.
use bolero::check;
check!()
.with_type::<(u8, u16)>()
.for_each(|(a, b)| {
// implement checks here
});
The function with_generator::<Generator>(generator)
will use the provided Generator
,
which implements generator::ValueGenerator
, to generate input
values of type Generator::Output
.
This mode is used for testing an implementation that requires structured input with specific constraints applied to the type. In the following example, we are only interested in generating two values, one being between 0 and 100, the other: 10 and 50.
use bolero::check;
check!()
.with_generator((0..100, 10..50))
.for_each(|(a, b)| {
// implement checks here
});
For compatibility purposes, bolero
also supports the same interface as
rust-fuzz/afl.rs. This usage
has a few downsides:
- The test cannot be configured
- The test code will be contained inside a macro which can trip up some editors and IDEs.
use bolero::check;
check!(|input| {
// implement checks here
});