[][src]Attribute Macro propfuzz::propfuzz

#[propfuzz]

The core macro, used to annotate test methods.

Annotate a function with this in order to have it run as a property-based test using the proptest framework. In the future, such tests will also be available as fuzz targets.

Examples

// The prelude imports the `propfuzz` macro.

use propfuzz::prelude::*;
use proptest::collection::vec;

/// Reversing a list twice produces the same result.
#[propfuzz]
fn reverse(
    #[propfuzz(strategy = "vec(any::<u32>(), 0..64)")]
    mut list: Vec<u32>,
) {
    let list2 = list.clone();
    list.reverse();
    list.reverse();
    prop_assert_eq!(list, list2);
}

Arguments

propfuzz supports a number of arguments which can be used to customize test behavior.

Attributes can be broken up with commas and split up across multiple lines like so:

use propfuzz::prelude::*;
use proptest::collection::vec;

/// Options broken up across multiple lines.
#[propfuzz(cases = 1024, max_local_rejects = 10000)]
#[propfuzz(fork = true)]
fn reverse(
    #[propfuzz(strategy = "vec(any::<u32>(), 0..64)")]
    mut list: Vec<u32>,
) {
    let list2 = list.clone();
    list.reverse();
    list.reverse();
    prop_assert_eq!(list, list2);
}

Fuzzing configuration

These arguments are currently unused but may be set. They will be used in the future once fuzzing support is available.

  • fuzz_default: whether to fuzz this target by default. Defaults to false.

Proptest configuration

The following proptest configuration options are supported:

  • cases
  • max_local_rejects
  • max_global_rejects
  • max_flat_map_regens
  • fork
  • timeout
  • max_shrink_time
  • max_shrink_iters
  • verbose

Argument configuration

The following configuration options are supported on individual arguments:

  • strategy: A strategy to generate and shrink values of the given type. The value must be a string that parses as a Rust expression which evaluates to an implementation of Strategy for the given type. Defaults to the canonical strategy for the type.