Skip to content

Commit

Permalink
Make CLI timeout options conflict with corresponding timeout-multipli…
Browse files Browse the repository at this point in the history
…er options
  • Loading branch information
zaneduffield committed Apr 24, 2024
1 parent cb7ac6e commit da6443d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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

- Changed: `--timeout` and `--timeout-multiplier` are now conflicting options.

## 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
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ pub struct Args {
timeout: Option<f64>,

/// Test timeout multiplier (relative to base test time).
#[arg(long, help_heading = "Execution")]
#[arg(long, help_heading = "Execution", conflicts_with = "timeout")]
timeout_multiplier: Option<f64>,

/// Maximum run time for cargo build command, in seconds.
#[arg(long, help_heading = "Execution")]
build_timeout: Option<f64>,

/// Build timeout multiplier (relative to base build time).
#[arg(long, help_heading = "Execution")]
#[arg(long, help_heading = "Execution", conflicts_with = "build_timeout")]
build_timeout_multiplier: Option<f64>,

/// Print mutations that failed to check or build.
Expand Down
20 changes: 20 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,26 @@ mod test {
assert_eq!(options.build_timeout_multiplier, Some(1.0));
}

#[test]
fn conflicting_timeout_options() {
let args = Args::try_parse_from(["mutants", "--timeout=1", "--timeout-multiplier=1"])
.expect_err("--timeout and --timeout-multiplier should conflict");
let rendered = format!("{}", args.render());
assert!(rendered.contains("error: the argument '--timeout <TIMEOUT>' cannot be used with '--timeout-multiplier <TIMEOUT_MULTIPLIER>'"));
}

#[test]
fn conflicting_build_timeout_options() {
let args = Args::try_parse_from([
"mutants",
"--build-timeout=1",
"--build-timeout-multiplier=1",
])
.expect_err("--build-timeout and --build-timeout-multiplier should conflict");
let rendered = format!("{}", args.render());
assert!(rendered.contains("error: the argument '--build-timeout <BUILD_TIMEOUT>' cannot be used with '--build-timeout-multiplier <BUILD_TIMEOUT_MULTIPLIER>'"));
}

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

0 comments on commit da6443d

Please sign in to comment.