fuzz and property testing front-end for Rust
A copy of the Bolero Book can be found here: https://camshaft.github.io/bolero
-
Install subcommand and add a dependency
$ cargo add --dev bolero $ cargo install -f cargo-bolero
-
Write a test using
bolero::check!
macro:pub fn buggy_add(x: u32, y: u32) -> u32 { if x == 12976 && y == 14867 { return x.wrapping_sub(y); } return x.wrapping_add(y); } #[test] fn fuzz_add() { bolero::check!() .with_type() .cloned() .for_each(|(a, b)| buggy_add(a, b) == a.wrapping_add(b)); }
-
Run the test with
cargo bolero
$ cargo bolero test fuzz_add # ... some moments later ... ======================== Test Failure ======================== Input: ( 12976, 14867, ) Error: test returned `false` ==============================================================
cargo-bolero
needs a couple of libraries installed to compile. If these libraries aren't
available the requirement can be relaxed by executing cargo install cargo-bolero --no-default-features -f
$ sudo apt install binutils-dev libunwind-dev