Skip to content

Commit dda61d8

Browse files
committed
rust-lang#107307 Adding additional information to "cargo test --list" output
earlier: p2dchecks::fibonacci_test::case_1: test now: // test test_type | ignored_or_not | location_info p2dchecks::fibonacci_test::case_1: test | false | src\lib.rs:57:8: 57:19
1 parent 3f059f6 commit dda61d8

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Session.vim
2121
.project
2222
.favorites.json
2323
.settings/
24+
.vs/
2425

2526
## Tool
2627
.valgrindrc

compiler/rustc_builtin_macros/src/test.rs

+11
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ pub fn expand_test_or_bench(
280280
cx.expr_none(sp)
281281
},
282282
),
283+
// location_info: <relative_path_of_source>:<start_line>:<start_col>: <end_line>:<end_col>
284+
field(
285+
"location_info",
286+
cx.expr_str(sp, item_location_info(cx, &item)),
287+
),
283288
// compile_fail: true | false
284289
field("compile_fail", cx.expr_bool(sp, false)),
285290
// no_run: true | false
@@ -396,6 +401,12 @@ fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
396401
}
397402
}
398403

404+
fn item_location_info(cx: &ExtCtxt<'_>, item: &ast::Item) -> Symbol {
405+
let ident_sp = cx.with_def_site_ctxt(item.ident.span);
406+
let li = cx.sess.source_map().span_to_location_info_string(ident_sp);
407+
Symbol::intern(&li)
408+
}
409+
399410
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
400411
match cx.sess.find_by_name(&i.attrs, sym::should_panic) {
401412
Some(attr) => {

compiler/rustc_span/src/source_map.rs

+5
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ impl SourceMap {
467467
self.span_to_string(sp, FileNameDisplayPreference::Remapped)
468468
}
469469

470+
/// Format the span's location information into string
471+
pub fn span_to_location_info_string(&self, sp: Span) -> String {
472+
self.span_to_string(sp, FileNameDisplayPreference::Local)
473+
}
474+
470475
/// Format the span location suitable for pretty printing anotations with relative line numbers
471476
pub fn span_to_relative_line_string(&self, sp: Span, relative_to: Span) -> String {
472477
if self.files.borrow().source_files.is_empty() || sp.is_dummy() || relative_to.is_dummy() {

library/test/src/console.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
152152
for test in filter_tests(opts, tests).into_iter() {
153153
use crate::TestFn::*;
154154

155-
let TestDescAndFn { desc: TestDesc { name, .. }, testfn } = test;
155+
let TestDescAndFn { desc: TestDesc { name, ignore, location_info, .. }, testfn } = test;
156156

157157
let fntype = match testfn {
158158
StaticTestFn(..) | DynTestFn(..) => {
@@ -165,8 +165,8 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
165165
}
166166
};
167167

168-
writeln!(output, "{name}: {fntype}")?;
169-
st.write_log(|| format!("{fntype} {name}\n"))?;
168+
writeln!(output, "{name}: {fntype} | {ignore} | {location_info}")?;
169+
st.write_log(|| format!("{fntype} {name} {ignore} {location_info}\n"))?;
170170
}
171171

172172
fn plural(count: u32, s: &str) -> String {

library/test/src/types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub struct TestDesc {
119119
pub name: TestName,
120120
pub ignore: bool,
121121
pub ignore_message: Option<&'static str>,
122+
pub location_info: &'static str,
122123
pub should_panic: options::ShouldPanic,
123124
pub compile_fail: bool,
124125
pub no_run: bool,

0 commit comments

Comments
 (0)