Skip to content

Commit

Permalink
Allow shell runnables to define test commands with substitution in ar…
Browse files Browse the repository at this point in the history
…guments
  • Loading branch information
Wilfred committed Mar 19, 2024
1 parent 719a84e commit f88aff3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/project-model/src/project_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ pub struct ShellRunnableArgs {
pub enum ShellRunnableKind {
Check,
Run,
TestOne,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Deserialize)]
Expand Down
19 changes: 18 additions & 1 deletion crates/rust-analyzer/src/target_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f88aff3

Please sign in to comment.