Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow env vars to override non-default config #318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

### New Features
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