diff --git a/.changelog/2026/06/19/native-test-expression-passthrough.md b/.changelog/2026/06/19/native-test-expression-passthrough.md new file mode 100644 index 0000000000..c76a46143d --- /dev/null +++ b/.changelog/2026/06/19/native-test-expression-passthrough.md @@ -0,0 +1,19 @@ +# Native Test Expression Passthrough + +Date: 2026-06-19 + +## Changed + +- Route `rtk test -d ...` and similar native `test` expressions to the system `test` command instead of `sh -c`. + +## Files + +- `src/main.rs`: detects native `test` expressions before using the RTK test-output wrapper. + +## Validation + +- `rtk cargo +1.91.0 fmt --all && rtk cargo +1.91.0 clippy --all-targets && rtk cargo +1.91.0 test --all` +- `rtk cargo +1.91.0 build` +- `rtk proxy ./target/debug/rtk test -d .` +- `rtk proxy ./target/debug/rtk test -d graphify-out` +- `rtk proxy ./target/debug/rtk test true` diff --git a/src/main.rs b/src/main.rs index 114c78714e..314b89ef59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1460,6 +1460,12 @@ where } } +fn is_native_test_expression(command: &[String]) -> bool { + command + .first() + .is_some_and(|arg| arg == "!" || arg == "(" || arg.starts_with('-')) +} + fn run_cli() -> Result { // Fire-and-forget telemetry ping (1/day, non-blocking) core::telemetry::maybe_ping(); @@ -1726,8 +1732,13 @@ fn run_cli() -> Result { } Commands::Test { command } => { - let cmd = command.join(" "); - runner::run_test(&cmd, cli.verbose)? + if is_native_test_expression(&command) { + let args: Vec = command.into_iter().map(OsString::from).collect(); + core::runner::run_passthrough("test", &args, cli.verbose)? + } else { + let cmd = command.join(" "); + runner::run_test(&cmd, cli.verbose)? + } } Commands::Json { @@ -2852,6 +2863,18 @@ mod tests { } } + #[test] + fn test_dash_d_routes_to_native_test_expression() { + let command = vec!["-d".to_string(), "graphify-out".to_string()]; + assert!(is_native_test_expression(&command)); + } + + #[test] + fn test_cargo_test_stays_test_runner() { + let command = vec!["cargo".to_string(), "test".to_string()]; + assert!(!is_native_test_expression(&command)); + } + #[test] fn test_try_parse_git_with_dash_c_succeeds() { let result = Cli::try_parse_from(["rtk", "git", "-C", "/path", "status"]);