#[check]Expand description
Turns a function into a property test.
It takes a list of generators as input, which are used to produce random arguments for the function it’s attached to.
The function can return (), bool, or Result to indicate whether the
property holds. Any panic within the function is also treated as a test
failure.
§Arguments
- Generators: The first arguments to the macro are a comma-separated
list of generators. The values produced by these generators will be passed
as arguments to the test function. You can use
_to infer the default generator for a type. verbose: A boolean (trueorfalse) to enable or disable verbose output, which shows every generation and shrink step. Defaults tofalse.color: A boolean (trueorfalse) to enable or disable colored output. Defaults totrue.debug: A boolean (trueorfalse) that controls the output format. Iftrue, the fullDebugrepresentation of test results is printed. Iffalse, a more minimal output is used. Defaults totrue.
§Examples
A simple test with a range generator:
#[check(0..100)]
fn is_less_than_100(x: i32) {
assert!(x < 100);
}Using multiple generators and inferring a type:
#[check(.., 0.0..1.0, _)]
fn complex_test(x: i32, y: f64, z: bool) {
// ...
}Disabling color and enabling verbose output:
#[check(0..10, color = false, verbose = true)]
#[should_panic]
fn failing_test(x: i32) {
assert!(x > 5);
}An in-place replacement for the #[test] attribute that allows adding
parameters to test functions and providing Generate expressions as
arguments to this attribute. See examples::cheats. for usage examples.