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 23, 2024
1 parent f3ffff9 commit 8cfe7ae
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 @@ -18,6 +18,8 @@

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

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

## 24.3.0

- Fixed: `cargo install cargo-mutants` without `--locked` was failing due to breaking API changes in some unstable dependencies.
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,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 8cfe7ae

Please sign in to comment.