From 985cc2b3cc01e8f9716c1fdcc9a813e4f3536b59 Mon Sep 17 00:00:00 2001 From: Jun Huang Date: Sun, 22 Dec 2024 13:40:16 +0800 Subject: [PATCH] Allow passing additional args to cargo test/bench --- src/main.rs | 2 ++ tests/data/script-test-extra-args.rs | 4 ++++ tests/tests/script.rs | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/data/script-test-extra-args.rs diff --git a/src/main.rs b/src/main.rs index 79bb165..8747c08 100644 --- a/src/main.rs +++ b/src/main.rs @@ -477,6 +477,8 @@ impl InputAction { } else { return Err(MainError::OtherOwned("Could not execute cargo".to_string())); } + } else { + cmd.args(script_args.iter()); } Ok(cmd) diff --git a/tests/data/script-test-extra-args.rs b/tests/data/script-test-extra-args.rs new file mode 100644 index 0000000..2fad4ea --- /dev/null +++ b/tests/data/script-test-extra-args.rs @@ -0,0 +1,4 @@ +fn main() {} + +#[test] +fn test() { println!("Hello, world!"); } diff --git a/tests/tests/script.rs b/tests/tests/script.rs index 73bdb51..cddde8e 100644 --- a/tests/tests/script.rs +++ b/tests/tests/script.rs @@ -91,6 +91,20 @@ fn test_script_test() { assert!(out.success()); } +#[test] +fn test_script_test_extra_args_for_cargo() { + let out = rust_script!("--test", "tests/data/script-test-extra-args.rs", "--help").unwrap(); + assert!(out.success()); + assert!(out.stdout.contains("Usage: cargo test ")); +} + +#[test] +fn test_script_test_extra_args_for_test() { + let out = rust_script!("--test", "tests/data/script-test-extra-args.rs", "--", "--nocapture").unwrap(); + assert!(out.success()); + assert!(out.stdout.contains("Hello, world!")); +} + #[test] fn test_script_hyphens() { use scan_rules::scanner::QuotedString;