Merge pull request #21395 from dfireBird/push-sqrmpnzrzwpt

feat: change test_name placeholder to executable_arg
This commit is contained in:
Chayim Refael Friedman
2026-03-22 21:24:07 +00:00
committed by GitHub
4 changed files with 76 additions and 39 deletions
@@ -948,18 +948,18 @@ pub enum MaxSubstitutionLength {
/// Override the command used for bench runnables.
/// The first element of the array should be the program to execute (for example, `cargo`).
///
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
/// the test name (name of test function or test mod path).
/// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
runnables_bench_overrideCommand: Option<Vec<String>> = None,
/// Command to be executed instead of 'cargo' for runnables.
runnables_command: Option<String> = None,
/// Override the command used for bench runnables.
/// The first element of the array should be the program to execute (for example, `cargo`).
///
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
/// the test name (name of test function or test mod path).
/// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
runnables_doctest_overrideCommand: Option<Vec<String>> = None,
/// Additional arguments to be passed to cargo for runnables such as
/// tests or binaries. For example, it may be `--release`.
@@ -977,9 +977,9 @@ pub enum MaxSubstitutionLength {
/// Override the command used for test runnables.
/// The first element of the array should be the program to execute (for example, `cargo`).
///
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
/// Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
/// replace the package name, target option (such as `--bin` or `--example`), the target name and
/// the test name (name of test function or test mod path).
/// the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
runnables_test_overrideCommand: Option<Vec<String>> = None,
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
@@ -129,38 +129,21 @@ pub(crate) fn runnable_args(
let extra_test_binary_args = config.extra_test_binary_args;
let mut cargo_args = Vec::new();
let mut executable_args = Vec::new();
let executable_args = Self::executable_args_for(kind, extra_test_binary_args);
match kind {
RunnableKind::Test { test_id, attr } => {
RunnableKind::Test { .. } => {
cargo_args.push(config.test_command);
executable_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
executable_args.push("--exact".to_owned());
}
executable_args.extend(extra_test_binary_args);
if attr.ignore {
executable_args.push("--ignored".to_owned());
}
}
RunnableKind::TestMod { path } => {
RunnableKind::TestMod { .. } => {
cargo_args.push(config.test_command);
executable_args.push(path.clone());
executable_args.extend(extra_test_binary_args);
}
RunnableKind::Bench { test_id } => {
RunnableKind::Bench { .. } => {
cargo_args.push(config.bench_command);
executable_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
executable_args.push("--exact".to_owned());
}
executable_args.extend(extra_test_binary_args);
}
RunnableKind::DocTest { test_id } => {
RunnableKind::DocTest { .. } => {
cargo_args.push("test".to_owned());
cargo_args.push("--doc".to_owned());
executable_args.push(test_id.to_string());
executable_args.extend(extra_test_binary_args);
}
RunnableKind::Bin => {
let subcommand = match spec {
@@ -253,16 +236,70 @@ pub(crate) fn override_command(
TargetKind::BuildScript | TargetKind::Other => "",
};
let target = |kind, target| match kind {
TargetKind::Bin | TargetKind::Test | TargetKind::Bench | TargetKind::Example => target,
_ => "",
};
let replace_placeholders = |arg: String| match &spec {
Some(spec) => arg
.replace("${package}", &spec.package)
.replace("${target_arg}", target_arg(spec.target_kind))
.replace("${target}", &spec.target)
.replace("${target}", target(spec.target_kind, &spec.target))
.replace("${test_name}", &test_name),
_ => arg,
};
args.map(|args| args.into_iter().map(replace_placeholders).collect())
let extra_test_binary_args = config.extra_test_binary_args;
let executable_args = Self::executable_args_for(kind, extra_test_binary_args);
args.map(|mut args| {
let exec_args_idx = args.iter().position(|a| a == "${executable_args}");
if let Some(idx) = exec_args_idx {
args.splice(idx..idx + 1, executable_args);
}
args.into_iter().map(replace_placeholders).filter(|a| !a.trim().is_empty()).collect()
})
}
fn executable_args_for(
kind: &RunnableKind,
extra_test_binary_args: impl IntoIterator<Item = String>,
) -> Vec<String> {
let mut executable_args = Vec::new();
match kind {
RunnableKind::Test { test_id, attr } => {
executable_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
executable_args.push("--exact".to_owned());
}
executable_args.extend(extra_test_binary_args);
if attr.ignore {
executable_args.push("--ignored".to_owned());
}
}
RunnableKind::TestMod { path } => {
executable_args.push(path.clone());
executable_args.extend(extra_test_binary_args);
}
RunnableKind::Bench { test_id } => {
executable_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
executable_args.push("--exact".to_owned());
}
executable_args.extend(extra_test_binary_args);
}
RunnableKind::DocTest { test_id } => {
executable_args.push(test_id.to_string());
executable_args.extend(extra_test_binary_args);
}
RunnableKind::Bin => {}
}
executable_args
}
pub(crate) fn push_to(self, buf: &mut Vec<String>, kind: &RunnableKind) {
@@ -1380,9 +1380,9 @@ Default: `null`
Override the command used for bench runnables.
The first element of the array should be the program to execute (for example, `cargo`).
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
replace the package name, target option (such as `--bin` or `--example`), the target name and
the test name (name of test function or test mod path).
the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
## rust-analyzer.runnables.command {#runnables.command}
@@ -1399,9 +1399,9 @@ Default: `null`
Override the command used for bench runnables.
The first element of the array should be the program to execute (for example, `cargo`).
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
replace the package name, target option (such as `--bin` or `--example`), the target name and
the test name (name of test function or test mod path).
the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
## rust-analyzer.runnables.extraArgs {#runnables.extraArgs}
@@ -1444,9 +1444,9 @@ Default: `null`
Override the command used for test runnables.
The first element of the array should be the program to execute (for example, `cargo`).
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically
Use the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically
replace the package name, target option (such as `--bin` or `--example`), the target name and
the test name (name of test function or test mod path).
the arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).
## rust-analyzer.rustc.source {#rustc.source}
@@ -2865,7 +2865,7 @@
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.bench.overrideCommand": {
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe test name (name of test function or test mod path).",
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
"default": null,
"type": [
"null",
@@ -2894,7 +2894,7 @@
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.doctest.overrideCommand": {
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe test name (name of test function or test mod path).",
"markdownDescription": "Override the command used for bench runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
"default": null,
"type": [
"null",
@@ -2948,7 +2948,7 @@
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.test.overrideCommand": {
"markdownDescription": "Override the command used for test runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${test_name}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe test name (name of test function or test mod path).",
"markdownDescription": "Override the command used for test runnables.\nThe first element of the array should be the program to execute (for example, `cargo`).\n\nUse the placeholders `${package}`, `${target_arg}`, `${target}`, `${executable_args}` to dynamically\nreplace the package name, target option (such as `--bin` or `--example`), the target name and\nthe arguments passed to test binary args (includes `rust-analyzer.runnables.extraTestBinaryArgs`).",
"default": null,
"type": [
"null",