[−][src]Macro bolero::check
Execute property checks for a given target
Examples
By default, input
is a &[u8]
.
This mode is generally used when testing an implementation that handles raw bytes, e.g. a parser.
#[test] fn bytes_test() { bolero::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.
#[test] fn type_generator_test() { bolero::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.
#[test] fn value_generator_test() { bolero::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.
#[test] fn compatibility_test() { bolero::check!(|input| { // implement checks here }); }