Implementing "<test_binary> --list --format json" for use by IDE test explorers / runners #107307
Description
[consider the default output of cargo new a --lib
]
Issue
Test explorers in editors (e.g. VSCode, see pic below) are unable to navigate to test location in the editor from the test explorer.
Cause
cargo test --list -q
used by the editors to get list of tests do not have the source and line / column info.
Description
Currently cargo test --list -q
shows the following output
tests::it_works: test
This is used by editor extensions e.g. vscode rust test adapter to show & run tests from the tests pane in VS Code. e.g.
While it is possible to run and debug the tests from the test explorer, it is not possible to navigate back to the test location as output above is missing that information. E.g. you cannot double click on a test on the test explorer to navigate to its definition in the editor.
Suggestion is to add the source info to the output of --list as follows
tests::it_works: test,<path>|<start_line>|<start_col>|<end_line>|<end_col>
Fix proposal
Proposal for fix (& I only have a plan A, happy to receive further guidance) is to update test::TestDescAndFn
as follows
// https://github.com/rust-lang/rust/blob/master/library/test/src/types.rs#L118
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct TestDesc {
pub name: TestName,
pub ignore: bool,
pub ignore_message: Option<&'static str>,
pub should_panic: options::ShouldPanic,
pub compile_fail: bool,
pub no_run: bool,
pub test_type: TestType,
pub source_path: &'static str, // <- Added
pub start_line: i32, // <- Added
pub start_column: i32, // <- Added
pub end_line: i32, // <- Added
pub end_column: i32, // <- Added
}
Once this is available, the corresponding changes can be made to compiler/rustc_builtin_macros/src/test.rs to emit the above info and then in library/test/src/console.rs to write it out.
Activity