
Closes #28002 This PR updates the `runnabless.scm` for Rust to improve detection of test modules with non-standard names. Instead of matching on the module name, we now check for the `#[cfg(test)]`-attribute above test modules. This allows for generic matching whilst not regressing the previous behaviour. | `main` | <img width="922" alt="main" src="https://github.com/user-attachments/assets/34fc4443-13a2-4e18-b806-7e14771c3df4" /> | | --- | --- | | This PR | <img width="922" alt="PR" src="https://github.com/user-attachments/assets/13e6a6d8-e177-4a83-89ab-24c0a69ade27" /> | Release Notes: - Improved runnable detection for test modules in Rust.
92 lines
1.9 KiB
Scheme
92 lines
1.9 KiB
Scheme
; Rust mod test
|
|
(
|
|
(attribute_item (attribute
|
|
(
|
|
(identifier) @_attribute)
|
|
arguments: (
|
|
(token_tree (identifier) @_test)
|
|
(#eq? @_test "test")
|
|
)
|
|
)
|
|
(#eq? @_attribute "cfg")
|
|
)
|
|
.
|
|
(mod_item
|
|
name: (_) @run
|
|
)
|
|
(#set! tag rust-mod-test)
|
|
)
|
|
|
|
; Rust test
|
|
(
|
|
(
|
|
(attribute_item (attribute
|
|
[((identifier) @_attribute)
|
|
(scoped_identifier (identifier) @_attribute)
|
|
])
|
|
(#match? @_attribute "test")
|
|
) @_start
|
|
.
|
|
(attribute_item) *
|
|
.
|
|
[(line_comment) (block_comment)] *
|
|
.
|
|
(function_item
|
|
name: (_) @run @_test_name
|
|
body: _
|
|
) @_end
|
|
)
|
|
(#set! tag rust-test)
|
|
)
|
|
|
|
; Rust doc test
|
|
(
|
|
(
|
|
(line_comment) *
|
|
(line_comment
|
|
doc: (_) @_comment_content
|
|
) @_start @run
|
|
(#match? @_comment_content "```")
|
|
.
|
|
(line_comment) *
|
|
.
|
|
(line_comment
|
|
doc: (_) @_end_comment_content
|
|
) @_end_code_block
|
|
(#match? @_end_comment_content "```")
|
|
.
|
|
(line_comment) *
|
|
(attribute_item) *
|
|
.
|
|
[(function_item
|
|
name: (_) @_doc_test_name
|
|
body: _
|
|
) (function_signature_item
|
|
name: (_) @_doc_test_name
|
|
) (struct_item
|
|
name: (_) @_doc_test_name
|
|
) (enum_item
|
|
name: (_) @_doc_test_name
|
|
body: _
|
|
) (
|
|
(attribute_item) ?
|
|
(macro_definition
|
|
name: (_) @_doc_test_name)
|
|
) (mod_item
|
|
name: (_) @_doc_test_name
|
|
)] @_end
|
|
)
|
|
(#set! tag rust-doc-test)
|
|
)
|
|
|
|
; Rust main function
|
|
(
|
|
(
|
|
(function_item
|
|
name: (_) @run
|
|
body: _
|
|
) @_rust_main_function_end
|
|
(#eq? @run "main")
|
|
)
|
|
(#set! tag rust-main)
|
|
)
|