Expand description
chaos_theory is a modern property-based testing and structure-aware fuzzing library.
You drive tests using Source to get structured pseudo-random values and control flow,
chaos_theory ensures that this exploration is efficient and any failures found
are automatically minimized.
§Quickstart
use chaos_theory::check;
#[test]
fn sort_strings() {
check(|src| {
let mut strings: Vec<String> = src.any("strings");
strings.sort();
assert!(strings.is_sorted(), "unsorted after sort: {strings:?}");
});
}More complete examples:
When a failure happens, chaos_theory prints a CHAOS_THEORY_REPLAY=... string
you can use to reproduce the case.
§Highlights
- Property testing and structure-aware fuzzing in one library
- Efficient state space exploration:
- bias towards small values and edge cases
- structural mutations and crossover
- example-guided generation
- built-in swarm testing
- Macro-free, immediate-mode API: generate values and control flow as the test runs
- Zero unsafe code, zero required dependencies and
no_std-compatible
§Documentation
Modules§
- _docs
- Additional documentation.
- _examples
- Complete examples.
- make
- Collection of built-in generator implementations.
Macros§
- assume
- Mark the current test case as invalid if the expression is false.
- fuzz_
target_ libfuzzer - Define a
libfuzzer_sysfuzz target compatible withcargo-fuzz. - vdbg
dbgwrapper that only outputs values for visible test case runs.- veprintln
eprintlnwrapper that only outputs values for visible test case runs.- vprintln
printlnwrapper that only outputs values for visible test case runs.
Structs§
- Config
- Builder for a customized
Env. - Env
- Structural pseudo-random generation and property-checking environment.
- Gen
- Type-erased generator of
T, implemented as a boxed trait object. - GenShared
- Thread-safe type-erased generator of
T, implemented as a boxed trait object. - Source
- Primary interface for working with pseudo-random data and control flow.
- Source
Ex - Lower-level variant of
Sourcewith explicit example threading and structural control.
Enums§
- Effect
- Result of the
Source::repeatorSourceEx::repeatstep. - Maybe
Owned - Type that represents either owned or borrowed values.
Traits§
- Arbitrary
- A trait for types that have a default
Generatorimplementation. - Generator
- A trait for types that describe composable generation of values.
- Option
Ext - Utility trait to give
OptionanOptionExt::assume_somehelper.
Functions§
- check
std - Check that property holds (does not panic).
- should_
log - Determine whether debug output should be emitted for the current test-case run.
Derive Macros§
- Arbitrary
derive - Derives an implementation of
chaos_theory::Arbitrary.