From 8f502640d1d1bacf0955346a23a395825d489f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 18 Apr 2023 09:38:10 +0100 Subject: [PATCH 1/3] make the config's `fn contextualize_config` public --- proptest/src/test_runner/config.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proptest/src/test_runner/config.rs b/proptest/src/test_runner/config.rs index 4934b1ba..04940abc 100644 --- a/proptest/src/test_runner/config.rs +++ b/proptest/src/test_runner/config.rs @@ -49,8 +49,10 @@ const RNG_ALGORITHM: &str = "PROPTEST_RNG_ALGORITHM"; const DISABLE_FAILURE_PERSISTENCE: &str = "PROPTEST_DISABLE_FAILURE_PERSISTENCE"; +/// Override the config fields from environment variables, if any are set. +/// Without the `std` feature this function returns config unchanged. #[cfg(feature = "std")] -fn contextualize_config(mut result: Config) -> Config { +pub fn contextualize_config(mut result: Config) -> Config { fn parse_or_warn( src: &OsString, dst: &mut T, @@ -141,8 +143,9 @@ fn contextualize_config(mut result: Config) -> Config { result } +/// Without the `std` feature this function returns config unchanged. #[cfg(not(feature = "std"))] -fn contextualize_config(result: Config) -> Config { +pub fn contextualize_config(result: Config) -> Config { result } From be301e6821e44ea2a72bb8ffc876a2ed2b24054b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 18 Apr 2023 09:38:41 +0100 Subject: [PATCH 2/3] contextualize the non-default config in `proptest!` macro --- proptest/src/sugar.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/proptest/src/sugar.rs b/proptest/src/sugar.rs index 42ba5c19..e16d2dda 100644 --- a/proptest/src/sugar.rs +++ b/proptest/src/sugar.rs @@ -157,7 +157,7 @@ macro_rules! proptest { $( $(#[$meta])* fn $test_name() { - let mut config = $config.clone(); + let mut config = $crate::test_runner::contextualize_config($config.clone()); config.test_name = Some( concat!(module_path!(), "::", stringify!($test_name))); $crate::proptest_helper!(@_BODY config ($($parm in $strategy),+) [] $body); @@ -172,7 +172,7 @@ macro_rules! proptest { $( $(#[$meta])* fn $test_name() { - let mut config = $config.clone(); + let mut config = $crate::test_runner::contextualize_config($config.clone()); config.test_name = Some( concat!(module_path!(), "::", stringify!($test_name))); $crate::proptest_helper!(@_BODY2 config ($($arg)+) [] $body); @@ -223,25 +223,25 @@ macro_rules! proptest { }; ($config:expr, |($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { { - let mut config = $config.__sugar_to_owned(); + let mut config = $crate::test_runner::contextualize_config($config.__sugar_to_owned()); $crate::sugar::force_no_fork(&mut config); $crate::proptest_helper!(@_BODY config ($($parm in $strategy),+) [] $body) } }; ($config:expr, move |($($parm:pat in $strategy:expr),+ $(,)?)| $body:expr) => { { - let mut config = $config.__sugar_to_owned(); + let mut config = $crate::test_runner::contextualize_config($config.__sugar_to_owned()); $crate::sugar::force_no_fork(&mut config); $crate::proptest_helper!(@_BODY config ($($parm in $strategy),+) [move] $body) } }; ($config:expr, |($($arg:tt)+)| $body:expr) => { { - let mut config = $config.__sugar_to_owned(); + let mut config = $crate::test_runner::contextualize_config($config.__sugar_to_owned()); $crate::sugar::force_no_fork(&mut config); $crate::proptest_helper!(@_BODY2 config ($($arg)+) [] $body); } }; ($config:expr, move |($($arg:tt)+)| $body:expr) => { { - let mut config = $config.__sugar_to_owned(); + let mut config = $crate::test_runner::contextualize_config($config.__sugar_to_owned()); $crate::sugar::force_no_fork(&mut config); $crate::proptest_helper!(@_BODY2 config ($($arg)+) [move] $body); } }; From 22672a6230a8a018e124b5abd775491f118c7605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Tue, 2 May 2023 08:29:54 +0200 Subject: [PATCH 3/3] changelog: add #318 --- proptest/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/proptest/CHANGELOG.md b/proptest/CHANGELOG.md index 0be9988c..300cf262 100644 --- a/proptest/CHANGELOG.md +++ b/proptest/CHANGELOG.md @@ -1,5 +1,10 @@ ## Unreleased +### Breaking Changes + +- `PROPTEST_` environment variables now take precedence over tests' non-default + configuration. + ### Bug Fixes ### New Features