Skip to content

Commit

Permalink
Make CLI timeout multipliers have precedence over config equivalents
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneduffield committed Apr 24, 2024
1 parent 282611f commit cb7ac6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- New: `--build-timeout` and `--build-timeout-multiplier` options for setting timeouts for the `build` and `check` cargo phases.

- Changed: `--timeout-multiplier` now overrides `timeout_multiplier` from `.cargo/mutants.toml`.

## 24.4.0

- Changes: Baselines and mutants are now built with `cargo test --no-run` rather than `cargo build --tests` as previously. This avoids wasted build effort if the `dev` and `test` Cargo profiles are not the same, and may better distinguish build failures from test failures. With `--test-tool=nextest`, the corresponding `cargo nextest run --no-run` is used.
Expand Down
26 changes: 23 additions & 3 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ impl Options {
show_times: !args.no_times,
show_all_logs: args.all_logs,
test_timeout: args.timeout.map(Duration::from_secs_f64),
test_timeout_multiplier: config.timeout_multiplier.or(args.timeout_multiplier),
test_timeout_multiplier: args.timeout_multiplier.or(config.timeout_multiplier),
build_timeout: args.build_timeout.map(Duration::from_secs_f64),
build_timeout_multiplier: config
build_timeout_multiplier: args
.build_timeout_multiplier
.or(args.build_timeout_multiplier),
.or(config.build_timeout_multiplier),
test_tool: args.test_tool.or(config.test_tool).unwrap_or_default(),
};
options.error_values.iter().for_each(|e| {
Expand Down Expand Up @@ -317,6 +317,26 @@ mod test {
assert_eq!(options.build_timeout_multiplier, Some(3.5));
}

#[test]
fn cli_timeout_multiplier_overrides_config() {
let config = indoc! { r#"
timeout_multiplier = 1.0
build_timeout_multiplier = 2.0
"#};
let mut config_file = NamedTempFile::new().unwrap();
config_file.write_all(config.as_bytes()).unwrap();
let args = Args::parse_from([
"mutants",
"--timeout-multiplier=2.0",
"--build-timeout-multiplier=1.0",
]);
let config = Config::read_file(config_file.path()).unwrap();
let options = Options::new(&args, &config).unwrap();

assert_eq!(options.test_timeout_multiplier, Some(2.0));
assert_eq!(options.build_timeout_multiplier, Some(1.0));
}

#[test]
fn test_tool_from_config() {
let config = indoc! { r#"
Expand Down

0 comments on commit cb7ac6e

Please sign in to comment.