rust: Fix test/doctest tasks showing up outside of tests (#25787)

Closes #ISSUE

Release Notes:

- Fixes Rust test tasks showing up outside of tests
This commit is contained in:
Piotr Osiewicz 2025-02-28 00:48:19 +01:00 committed by GitHub
parent 62fb555e18
commit b15aa5e018
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 16 deletions

View file

@ -472,6 +472,12 @@ const RUST_BIN_KIND_TASK_VARIABLE: VariableName =
const RUST_TEST_FRAGMENT_TASK_VARIABLE: VariableName = const RUST_TEST_FRAGMENT_TASK_VARIABLE: VariableName =
VariableName::Custom(Cow::Borrowed("RUST_TEST_FRAGMENT")); VariableName::Custom(Cow::Borrowed("RUST_TEST_FRAGMENT"));
const RUST_DOC_TEST_NAME_TASK_VARIABLE: VariableName =
VariableName::Custom(Cow::Borrowed("RUST_DOC_TEST_NAME"));
const RUST_TEST_NAME_TASK_VARIABLE: VariableName =
VariableName::Custom(Cow::Borrowed("RUST_TEST_NAME"));
impl ContextProvider for RustContextProvider { impl ContextProvider for RustContextProvider {
fn build_context( fn build_context(
&self, &self,
@ -516,6 +522,16 @@ impl ContextProvider for RustContextProvider {
let fragment = test_fragment(&variables, path, stem); let fragment = test_fragment(&variables, path, stem);
variables.insert(RUST_TEST_FRAGMENT_TASK_VARIABLE, fragment); variables.insert(RUST_TEST_FRAGMENT_TASK_VARIABLE, fragment);
}; };
if let Some(test_name) =
task_variables.get(&VariableName::Custom(Cow::Borrowed("_test_name")))
{
variables.insert(RUST_TEST_NAME_TASK_VARIABLE, test_name.into());
}
if let Some(doc_test_name) =
task_variables.get(&VariableName::Custom(Cow::Borrowed("_doc_test_name")))
{
variables.insert(RUST_DOC_TEST_NAME_TASK_VARIABLE, doc_test_name.into());
}
Task::ready(Ok(variables)) Task::ready(Ok(variables))
} }
@ -569,7 +585,7 @@ impl ContextProvider for RustContextProvider {
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"Test '{}' (package: {})", "Test '{}' (package: {})",
VariableName::Symbol.template_value(), RUST_TEST_NAME_TASK_VARIABLE.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(), RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),
command: "cargo".into(), command: "cargo".into(),
@ -577,7 +593,7 @@ impl ContextProvider for RustContextProvider {
"test".into(), "test".into(),
"-p".into(), "-p".into(),
RUST_PACKAGE_TASK_VARIABLE.template_value(), RUST_PACKAGE_TASK_VARIABLE.template_value(),
VariableName::Symbol.template_value(), RUST_TEST_NAME_TASK_VARIABLE.template_value(),
"--".into(), "--".into(),
"--nocapture".into(), "--nocapture".into(),
], ],
@ -587,8 +603,8 @@ impl ContextProvider for RustContextProvider {
}, },
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"DocTest '{}' (package: {})", "Doc test '{}' (package: {})",
VariableName::Symbol.template_value(), RUST_DOC_TEST_NAME_TASK_VARIABLE.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(), RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),
command: "cargo".into(), command: "cargo".into(),
@ -597,7 +613,7 @@ impl ContextProvider for RustContextProvider {
"--doc".into(), "--doc".into(),
"-p".into(), "-p".into(),
RUST_PACKAGE_TASK_VARIABLE.template_value(), RUST_PACKAGE_TASK_VARIABLE.template_value(),
VariableName::Symbol.template_value(), RUST_DOC_TEST_NAME_TASK_VARIABLE.template_value(),
"--".into(), "--".into(),
"--nocapture".into(), "--nocapture".into(),
], ],
@ -607,7 +623,7 @@ impl ContextProvider for RustContextProvider {
}, },
TaskTemplate { TaskTemplate {
label: format!( label: format!(
"Test '{}' (package: {})", "Test mod '{}' (package: {})",
VariableName::Stem.template_value(), VariableName::Stem.template_value(),
RUST_PACKAGE_TASK_VARIABLE.template_value(), RUST_PACKAGE_TASK_VARIABLE.template_value(),
), ),

View file

@ -22,7 +22,7 @@
[(line_comment) (block_comment)] * [(line_comment) (block_comment)] *
. .
(function_item (function_item
name: (_) @run name: (_) @run @_test_name
body: _ body: _
) @_end ) @_end
) )
@ -35,34 +35,35 @@
(line_comment) * (line_comment) *
(line_comment (line_comment
doc: (_) @_comment_content doc: (_) @_comment_content
) @start ) @_start @run
(#match? @_comment_content "```") (#match? @_comment_content "```")
.
(line_comment) * (line_comment) *
.
(line_comment (line_comment
doc: (_) @_end_comment_content doc: (_) @_end_comment_content
) @_end_code_block ) @_end_code_block
(#match? @_end_comment_content "```") (#match? @_end_comment_content "```")
. .
(line_comment) *
(attribute_item) * (attribute_item) *
. .
[(line_comment) (block_comment)] *
.
[(function_item [(function_item
name: (_) @run name: (_) @_doc_test_name
body: _ body: _
) (function_signature_item ) (function_signature_item
name: (_) @run name: (_) @_doc_test_name
) (struct_item ) (struct_item
name: (_) @run name: (_) @_doc_test_name
) (enum_item ) (enum_item
name: (_) @run name: (_) @_doc_test_name
body: _ body: _
) ( ) (
(attribute_item) ? (attribute_item) ?
(macro_definition (macro_definition
name: (_) @run) name: (_) @_doc_test_name)
) (mod_item ) (mod_item
name: (_) @run name: (_) @_doc_test_name
)] @_end )] @_end
) )
(#set! tag rust-doc-test) (#set! tag rust-doc-test)