Skip to content

Commit

Permalink
proptest-stateful: Add macro for using better failure persistence def…
Browse files Browse the repository at this point in the history
…aults

This is a convenience macro that is useful for creating ProptestConfig
structs with failure persistence fields that match the current source
file. This is useful for stateful property tests because leaving these
fields at their default values causes them to be set by the proptest
macros invoked in proptest_stateful::test, which is not typically what
one would actually want.

Change-Id: I02c4327b3cc955ca24e4dfb0c5750353e71eb0a8
Reviewed-on: https://gerrit.readyset.name/c/readyset/+/5373
Tested-by: Buildkite CI
Reviewed-by: Aspen Smith <[email protected]>
  • Loading branch information
nickelization committed Jul 10, 2023
1 parent 8b0f4b1 commit c1a6fac
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,25 @@ where
Err(e) => panic!("{}\n{}", e, runner),
}
}

/// Return a [`ProptestConfig`] struct with default values for everything except `source_file` and
/// `failure_persistence`, which will be set up with sane defaults for the current source file.
///
/// This is a useful macro for proptest-stateful tests because they are generally invoked by
/// calling [`test`], which results in the proptest macros being used from within the
/// proptest-stateful source files. Those macros use `file!()` to get the current source file, and
/// use that to set some defaults for where we save the regressions, but generally a stateful
/// property test suite would probably prefer to save regressions in the same place as the stateful
/// property test source.
#[macro_export]
macro_rules! proptest_config_with_local_failure_persistence {
() => {
ProptestConfig {
failure_persistence: Some(Box::new(
proptest::test_runner::FileFailurePersistence::WithSource("proptest-regressions"),
)),
source_file: Some(file!()),
..ProptestConfig::default()
}
};
}

0 comments on commit c1a6fac

Please sign in to comment.