From c1a6fac068cf595f5a3899e5e9904f474d07526e Mon Sep 17 00:00:00 2001 From: Nick Marino Date: Mon, 10 Jul 2023 11:47:24 -0400 Subject: [PATCH] proptest-stateful: Add macro for using better failure persistence defaults 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 --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c9b7632..dfc76b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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() + } + }; +}