From da6443d9455d23b26e17fc001b0d493d3c8757bd Mon Sep 17 00:00:00 2001 From: Zane Duffield Date: Mon, 22 Apr 2024 20:21:02 +1000 Subject: [PATCH] Make CLI timeout options conflict with corresponding timeout-multiplier options --- NEWS.md | 2 ++ src/main.rs | 4 ++-- src/options.rs | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index ae0fc974..b2bb48f3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/src/main.rs b/src/main.rs index bc96de1d..e5ccbcb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -289,7 +289,7 @@ pub struct Args { timeout: Option, /// Test timeout multiplier (relative to base test time). - #[arg(long, help_heading = "Execution")] + #[arg(long, help_heading = "Execution", conflicts_with = "timeout")] timeout_multiplier: Option, /// Maximum run time for cargo build command, in seconds. @@ -297,7 +297,7 @@ pub struct Args { build_timeout: Option, /// 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, /// Print mutations that failed to check or build. diff --git a/src/options.rs b/src/options.rs index 90bef6f9..6902eccd 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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 ' cannot be used with '--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 ' cannot be used with '--build-timeout-multiplier '")); + } + #[test] fn test_tool_from_config() { let config = indoc! { r#"