From f88aff3a962345479ca56c3d691c91d98478ddc2 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 15 Mar 2024 14:54:43 -0700 Subject: [PATCH] Allow shell runnables to define test commands with substitution in arguments --- crates/project-model/src/project_json.rs | 1 + crates/rust-analyzer/src/target_spec.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/project-model/src/project_json.rs b/crates/project-model/src/project_json.rs index e3a004043701..137f2dfc2f55 100644 --- a/crates/project-model/src/project_json.rs +++ b/crates/project-model/src/project_json.rs @@ -272,6 +272,7 @@ pub struct ShellRunnableArgs { pub enum ShellRunnableKind { Check, Run, + TestOne, } #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Deserialize)] diff --git a/crates/rust-analyzer/src/target_spec.rs b/crates/rust-analyzer/src/target_spec.rs index 5565562f93f3..3dafd75bc19b 100644 --- a/crates/rust-analyzer/src/target_spec.rs +++ b/crates/rust-analyzer/src/target_spec.rs @@ -78,7 +78,24 @@ impl ProjectJsonTargetSpec { None } - RunnableKind::Test { .. } => None, + RunnableKind::Test { test_id, .. } => { + for runnable in &self.shell_runnables { + if matches!(runnable.kind, ShellRunnableKind::TestOne) { + let mut runnable = runnable.clone(); + + let replaced_args: Vec<_> = runnable + .args + .iter() + .map(|arg| arg.replace("$$TEST_NAME$$", &test_id.to_string())) + .collect(); + runnable.args = replaced_args; + + return Some(runnable); + } + } + + None + } RunnableKind::TestMod { .. } => None, RunnableKind::Bench { .. } => None, RunnableKind::DocTest { .. } => None,