Skip to content

Commit

Permalink
Merge pull request #318 from tzemanovic/tomas/env-vars-config-override
Browse files Browse the repository at this point in the history
allow env vars to override non-default config
  • Loading branch information
rex-remind101 committed May 22, 2023
2 parents 18ca1af + 22672a6 commit b88e9ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions proptest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

### Breaking Changes

- `PROPTEST_` environment variables now take precedence over tests' non-default
configuration.

### Bug Fixes

- Don't implement Arbitrary for NonZeroU128 and NonZeroI128 on wasm targets where
Expand Down
12 changes: 6 additions & 6 deletions proptest/src/sugar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
} };
Expand Down
7 changes: 5 additions & 2 deletions proptest/src/test_runner/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: FromStr + fmt::Display>(
src: &OsString,
dst: &mut T,
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit b88e9ff

Please sign in to comment.