From dda61d821761730e4ca346aea6546d0ea7c804a9 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Tue, 7 Feb 2023 21:41:28 -0500 Subject: [PATCH 01/10] #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 --- .gitignore | 1 + compiler/rustc_builtin_macros/src/test.rs | 11 +++++++++++ compiler/rustc_span/src/source_map.rs | 5 +++++ library/test/src/console.rs | 6 +++--- library/test/src/types.rs | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e5ca3e503130f..f2e22cc800c05 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ Session.vim .project .favorites.json .settings/ +.vs/ ## Tool .valgrindrc diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 729ae4071e200..4a07763aedf8c 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -280,6 +280,11 @@ pub fn expand_test_or_bench( cx.expr_none(sp) }, ), + // location_info: ::: : + field( + "location_info", + cx.expr_str(sp, item_location_info(cx, &item)), + ), // compile_fail: true | false field("compile_fail", cx.expr_bool(sp, false)), // no_run: true | false @@ -396,6 +401,12 @@ fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option { } } +fn item_location_info(cx: &ExtCtxt<'_>, item: &ast::Item) -> Symbol { + let ident_sp = cx.with_def_site_ctxt(item.ident.span); + let li = cx.sess.source_map().span_to_location_info_string(ident_sp); + Symbol::intern(&li) +} + fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic { match cx.sess.find_by_name(&i.attrs, sym::should_panic) { Some(attr) => { diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 2e339a9d2d2b0..a5a9f50d988c8 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -467,6 +467,11 @@ impl SourceMap { self.span_to_string(sp, FileNameDisplayPreference::Remapped) } + /// Format the span's location information into string + pub fn span_to_location_info_string(&self, sp: Span) -> String { + self.span_to_string(sp, FileNameDisplayPreference::Local) + } + /// Format the span location suitable for pretty printing anotations with relative line numbers pub fn span_to_relative_line_string(&self, sp: Span, relative_to: Span) -> String { if self.files.borrow().source_files.is_empty() || sp.is_dummy() || relative_to.is_dummy() { diff --git a/library/test/src/console.rs b/library/test/src/console.rs index 1ee68c8540bcc..57f5465b4b8bb 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -152,7 +152,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res for test in filter_tests(opts, tests).into_iter() { use crate::TestFn::*; - let TestDescAndFn { desc: TestDesc { name, .. }, testfn } = test; + let TestDescAndFn { desc: TestDesc { name, ignore, location_info, .. }, testfn } = test; let fntype = match testfn { StaticTestFn(..) | DynTestFn(..) => { @@ -165,8 +165,8 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res } }; - writeln!(output, "{name}: {fntype}")?; - st.write_log(|| format!("{fntype} {name}\n"))?; + writeln!(output, "{name}: {fntype} | {ignore} | {location_info}")?; + st.write_log(|| format!("{fntype} {name} {ignore} {location_info}\n"))?; } fn plural(count: u32, s: &str) -> String { diff --git a/library/test/src/types.rs b/library/test/src/types.rs index 6f2e033095a37..2c3e1054729c9 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -119,6 +119,7 @@ pub struct TestDesc { pub name: TestName, pub ignore: bool, pub ignore_message: Option<&'static str>, + pub location_info: &'static str, pub should_panic: options::ShouldPanic, pub compile_fail: bool, pub no_run: bool, From 5c9c7a1a4b3af6e11f891dccd5c3073975db3973 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Tue, 7 Feb 2023 22:00:29 -0500 Subject: [PATCH 02/10] #107307 Adding additional information to "cargo test --list" output fixing build break --- library/test/src/tests.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/test/src/tests.rs b/library/test/src/tests.rs index 44776fb0a316d..393295ba7e5d7 100644 --- a/library/test/src/tests.rs +++ b/library/test/src/tests.rs @@ -63,6 +63,7 @@ fn one_ignored_one_unignored_test() -> Vec { name: StaticTestName("1"), ignore: true, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -75,6 +76,7 @@ fn one_ignored_one_unignored_test() -> Vec { name: StaticTestName("2"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -95,6 +97,7 @@ pub fn do_not_run_ignored_tests() { name: StaticTestName("whatever"), ignore: true, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -118,6 +121,7 @@ pub fn ignored_tests_result_in_ignored() { name: StaticTestName("whatever"), ignore: true, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -143,6 +147,7 @@ fn test_should_panic() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::Yes, compile_fail: false, no_run: false, @@ -168,6 +173,7 @@ fn test_should_panic_good_message() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::YesWithMessage("error message"), compile_fail: false, no_run: false, @@ -198,6 +204,7 @@ fn test_should_panic_bad_message() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::YesWithMessage(expected), compile_fail: false, no_run: false, @@ -232,6 +239,7 @@ fn test_should_panic_non_string_message_type() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::YesWithMessage(expected), compile_fail: false, no_run: false, @@ -260,6 +268,7 @@ fn test_should_panic_but_succeeds() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic, compile_fail: false, no_run: false, @@ -288,6 +297,7 @@ fn report_time_test_template(report_time: bool) -> Option { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -325,6 +335,7 @@ fn time_test_failure_template(test_type: TestType) -> TestResult { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -364,6 +375,7 @@ fn typed_test_desc(test_type: TestType) -> TestDesc { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -476,6 +488,7 @@ pub fn exclude_should_panic_option() { name: StaticTestName("3"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::Yes, compile_fail: false, no_run: false, @@ -500,6 +513,7 @@ pub fn exact_filter_match() { name: StaticTestName(name), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -591,6 +605,7 @@ fn sample_tests() -> Vec { name: DynTestName((*name).clone()), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -720,6 +735,7 @@ pub fn test_bench_no_iter() { name: StaticTestName("f"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -743,6 +759,7 @@ pub fn test_bench_iter() { name: StaticTestName("f"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -759,6 +776,7 @@ fn should_sort_failures_before_printing_them() { name: StaticTestName("a"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -769,6 +787,7 @@ fn should_sort_failures_before_printing_them() { name: StaticTestName("b"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -816,6 +835,7 @@ fn test_dyn_bench_returning_err_fails_when_run_as_test() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, From 6a13a85b9957001612a6ca026b3c9676ca2501a7 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Tue, 7 Feb 2023 23:14:15 -0500 Subject: [PATCH 03/10] #107307 Adding additional information to "cargo test --list" output fixing build break --- src/librustdoc/doctest.rs | 1 + src/tools/compiletest/src/header.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 37a1005cba1fc..12c634151c205 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1063,6 +1063,7 @@ impl Tester for Collector { }, ignore_message: None, // compiler failures are test failures + location_info: "src\\lib.rs:10:10: 10:20", should_panic: test::ShouldPanic::No, compile_fail: config.compile_fail, no_run, diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 45fd87bea9bb5..e93e9ae3445fe 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -1043,6 +1043,7 @@ pub fn make_test_description( name, ignore, ignore_message, + location_info: "src\\lib.rs:10:10: 10:20", should_panic, compile_fail: false, no_run: false, From 13b0560305d9cae3d19fb5677b94e4dd007b8a63 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Tue, 7 Feb 2023 23:52:03 -0500 Subject: [PATCH 04/10] #107307 Adding additional information to "cargo test --list" output attempting to fix ordering issue --- library/test/src/console.rs | 13 ++++++++++--- library/test/src/tests.rs | 20 ++++++++++++++++++++ src/librustdoc/doctest.rs | 1 + src/tools/compiletest/src/header.rs | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/library/test/src/console.rs b/library/test/src/console.rs index 57f5465b4b8bb..c8aa2297f62d6 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -152,7 +152,14 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res for test in filter_tests(opts, tests).into_iter() { use crate::TestFn::*; - let TestDescAndFn { desc: TestDesc { name, ignore, location_info, .. }, testfn } = test; + let TestDescAndFn { + desc: TestDesc { + name, + ignore, + #[cfg(not(bootstrap))] + location_info, + .. + }, testfn } = test; let fntype = match testfn { StaticTestFn(..) | DynTestFn(..) => { @@ -165,8 +172,8 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res } }; - writeln!(output, "{name}: {fntype} | {ignore} | {location_info}")?; - st.write_log(|| format!("{fntype} {name} {ignore} {location_info}\n"))?; + writeln!(output, "{name}: {fntype} | {ignore} | ")?; + st.write_log(|| format!("{fntype} {name} {ignore} \n"))?; } fn plural(count: u32, s: &str) -> String { diff --git a/library/test/src/tests.rs b/library/test/src/tests.rs index 393295ba7e5d7..018c9c9f0034a 100644 --- a/library/test/src/tests.rs +++ b/library/test/src/tests.rs @@ -63,6 +63,7 @@ fn one_ignored_one_unignored_test() -> Vec { name: StaticTestName("1"), ignore: true, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -76,6 +77,7 @@ fn one_ignored_one_unignored_test() -> Vec { name: StaticTestName("2"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -97,6 +99,7 @@ pub fn do_not_run_ignored_tests() { name: StaticTestName("whatever"), ignore: true, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -121,6 +124,7 @@ pub fn ignored_tests_result_in_ignored() { name: StaticTestName("whatever"), ignore: true, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -147,6 +151,7 @@ fn test_should_panic() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::Yes, compile_fail: false, @@ -173,6 +178,7 @@ fn test_should_panic_good_message() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::YesWithMessage("error message"), compile_fail: false, @@ -204,6 +210,7 @@ fn test_should_panic_bad_message() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::YesWithMessage(expected), compile_fail: false, @@ -239,6 +246,7 @@ fn test_should_panic_non_string_message_type() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::YesWithMessage(expected), compile_fail: false, @@ -268,6 +276,7 @@ fn test_should_panic_but_succeeds() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic, compile_fail: false, @@ -297,6 +306,7 @@ fn report_time_test_template(report_time: bool) -> Option { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -335,6 +345,7 @@ fn time_test_failure_template(test_type: TestType) -> TestResult { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -375,6 +386,7 @@ fn typed_test_desc(test_type: TestType) -> TestDesc { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -488,6 +500,7 @@ pub fn exclude_should_panic_option() { name: StaticTestName("3"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::Yes, compile_fail: false, @@ -513,6 +526,7 @@ pub fn exact_filter_match() { name: StaticTestName(name), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -605,6 +619,7 @@ fn sample_tests() -> Vec { name: DynTestName((*name).clone()), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -735,6 +750,7 @@ pub fn test_bench_no_iter() { name: StaticTestName("f"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -759,6 +775,7 @@ pub fn test_bench_iter() { name: StaticTestName("f"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -776,6 +793,7 @@ fn should_sort_failures_before_printing_them() { name: StaticTestName("a"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -787,6 +805,7 @@ fn should_sort_failures_before_printing_them() { name: StaticTestName("b"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, @@ -835,6 +854,7 @@ fn test_dyn_bench_returning_err_fails_when_run_as_test() { name: StaticTestName("whatever"), ignore: false, ignore_message: None, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: ShouldPanic::No, compile_fail: false, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 12c634151c205..5d3a7bd3fde85 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1063,6 +1063,7 @@ impl Tester for Collector { }, ignore_message: None, // compiler failures are test failures + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic: test::ShouldPanic::No, compile_fail: config.compile_fail, diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index e93e9ae3445fe..a666acf0546e4 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -1043,6 +1043,7 @@ pub fn make_test_description( name, ignore, ignore_message, + #[cfg(not(bootstrap))] location_info: "src\\lib.rs:10:10: 10:20", should_panic, compile_fail: false, From 37a78c809f8bf9afcf5005102dfb60c7ecf070f6 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Tue, 7 Feb 2023 23:58:56 -0500 Subject: [PATCH 05/10] #107307 Adding additional information to "cargo test --list" output wtf am i doing? --- library/test/src/types.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/test/src/types.rs b/library/test/src/types.rs index 2c3e1054729c9..194cdcb65fdb0 100644 --- a/library/test/src/types.rs +++ b/library/test/src/types.rs @@ -119,6 +119,7 @@ pub struct TestDesc { pub name: TestName, pub ignore: bool, pub ignore_message: Option<&'static str>, + #[cfg(not(bootstrap))] pub location_info: &'static str, pub should_panic: options::ShouldPanic, pub compile_fail: bool, From 801c86bf439cd4685df838c0a9c07fda95178f1d Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Wed, 8 Feb 2023 00:42:23 -0500 Subject: [PATCH 06/10] #107307 Adding additional information to "cargo test --list" output wtf am i doing (redux)? --- library/test/src/console.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/library/test/src/console.rs b/library/test/src/console.rs index c8aa2297f62d6..5d11a188e1fa0 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -153,13 +153,16 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res use crate::TestFn::*; let TestDescAndFn { - desc: TestDesc { - name, - ignore, - #[cfg(not(bootstrap))] - location_info, - .. - }, testfn } = test; + desc: + TestDesc { + name, + ignore, + #[cfg(not(bootstrap))] + location_info, + .. + }, + testfn, + } = test; let fntype = match testfn { StaticTestFn(..) | DynTestFn(..) => { @@ -172,8 +175,11 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res } }; - writeln!(output, "{name}: {fntype} | {ignore} | ")?; - st.write_log(|| format!("{fntype} {name} {ignore} \n"))?; + #[cfg(bootstrap)] + let location_info = "location_info_tbd_during_bootstrap"; + + writeln!(output, "{name}: {fntype} | {ignore} | {location_info}")?; + st.write_log(|| format!("{fntype} {name} {ignore} {location_info}\n"))?; } fn plural(count: u32, s: &str) -> String { From a0839e46e0b046e6c54d84e53b455e3e362bc225 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Wed, 8 Feb 2023 01:03:06 -0500 Subject: [PATCH 07/10] #107307 Adding additional information to "cargo test --list" output fixing tests --- tests/pretty/tests-are-sorted.pp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/pretty/tests-are-sorted.pp b/tests/pretty/tests-are-sorted.pp index 15dcd4ed97df4..58203dc6e59cd 100644 --- a/tests/pretty/tests-are-sorted.pp +++ b/tests/pretty/tests-are-sorted.pp @@ -18,6 +18,7 @@ name: test::StaticTestName("m_test"), ignore: false, ignore_message: ::core::option::Option::None, + location_info: "/checkout/tests/pretty/tests-are-sorted.rs:7:4: 7:10", compile_fail: false, no_run: false, should_panic: test::ShouldPanic::No, @@ -36,6 +37,7 @@ name: test::StaticTestName("z_test"), ignore: false, ignore_message: ::core::option::Option::None, + location_info: "/checkout/tests/pretty/tests-are-sorted.rs:10:4: 10:10", compile_fail: false, no_run: false, should_panic: test::ShouldPanic::No, @@ -54,6 +56,7 @@ name: test::StaticTestName("a_test"), ignore: false, ignore_message: ::core::option::Option::None, + location_info: "/checkout/tests/pretty/tests-are-sorted.rs:13:4: 13:10", compile_fail: false, no_run: false, should_panic: test::ShouldPanic::No, From 75883605de93d0628c6a6ac633bd5075c502e401 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Wed, 8 Feb 2023 08:49:44 -0500 Subject: [PATCH 08/10] #107307 Adding additional information to "cargo test --list" output taking in PR comments. --- compiler/rustc_builtin_macros/src/test.rs | 3 +- compiler/rustc_span/src/source_map.rs | 5 --- library/test/src/console.rs | 6 ++-- library/test/src/tests.rs | 40 +++++++++++------------ src/librustdoc/doctest.rs | 2 +- src/tools/compiletest/src/header.rs | 2 +- 6 files changed, 27 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 4a07763aedf8c..17d80fbac6e21 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -402,8 +402,7 @@ fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option { } fn item_location_info(cx: &ExtCtxt<'_>, item: &ast::Item) -> Symbol { - let ident_sp = cx.with_def_site_ctxt(item.ident.span); - let li = cx.sess.source_map().span_to_location_info_string(ident_sp); + let li = cx.sess.source_map().span_to_string(item.ident.span, FileNameDisplayPreference::Local); Symbol::intern(&li) } diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index a5a9f50d988c8..2e339a9d2d2b0 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -467,11 +467,6 @@ impl SourceMap { self.span_to_string(sp, FileNameDisplayPreference::Remapped) } - /// Format the span's location information into string - pub fn span_to_location_info_string(&self, sp: Span) -> String { - self.span_to_string(sp, FileNameDisplayPreference::Local) - } - /// Format the span location suitable for pretty printing anotations with relative line numbers pub fn span_to_relative_line_string(&self, sp: Span, relative_to: Span) -> String { if self.files.borrow().source_files.is_empty() || sp.is_dummy() || relative_to.is_dummy() { diff --git a/library/test/src/console.rs b/library/test/src/console.rs index 5d11a188e1fa0..df10ce0ca94ca 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -178,8 +178,10 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res #[cfg(bootstrap)] let location_info = "location_info_tbd_during_bootstrap"; - writeln!(output, "{name}: {fntype} | {ignore} | {location_info}")?; - st.write_log(|| format!("{fntype} {name} {ignore} {location_info}\n"))?; + let state_str = if ignore { "ignored" } else { "active" }; + + writeln!(output, "{name}: {fntype} | {state_str} | {location_info}")?; + st.write_log(|| format!("{fntype} {name} {state_str} {location_info}\n"))?; } fn plural(count: u32, s: &str) -> String { diff --git a/library/test/src/tests.rs b/library/test/src/tests.rs index 018c9c9f0034a..bd52502157b14 100644 --- a/library/test/src/tests.rs +++ b/library/test/src/tests.rs @@ -64,7 +64,7 @@ fn one_ignored_one_unignored_test() -> Vec { ignore: true, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -78,7 +78,7 @@ fn one_ignored_one_unignored_test() -> Vec { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -100,7 +100,7 @@ pub fn do_not_run_ignored_tests() { ignore: true, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -125,7 +125,7 @@ pub fn ignored_tests_result_in_ignored() { ignore: true, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -152,7 +152,7 @@ fn test_should_panic() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::Yes, compile_fail: false, no_run: false, @@ -179,7 +179,7 @@ fn test_should_panic_good_message() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::YesWithMessage("error message"), compile_fail: false, no_run: false, @@ -211,7 +211,7 @@ fn test_should_panic_bad_message() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::YesWithMessage(expected), compile_fail: false, no_run: false, @@ -247,7 +247,7 @@ fn test_should_panic_non_string_message_type() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::YesWithMessage(expected), compile_fail: false, no_run: false, @@ -277,7 +277,7 @@ fn test_should_panic_but_succeeds() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic, compile_fail: false, no_run: false, @@ -307,7 +307,7 @@ fn report_time_test_template(report_time: bool) -> Option { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -346,7 +346,7 @@ fn time_test_failure_template(test_type: TestType) -> TestResult { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -387,7 +387,7 @@ fn typed_test_desc(test_type: TestType) -> TestDesc { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -501,7 +501,7 @@ pub fn exclude_should_panic_option() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::Yes, compile_fail: false, no_run: false, @@ -527,7 +527,7 @@ pub fn exact_filter_match() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -620,7 +620,7 @@ fn sample_tests() -> Vec { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -751,7 +751,7 @@ pub fn test_bench_no_iter() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -776,7 +776,7 @@ pub fn test_bench_iter() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -794,7 +794,7 @@ fn should_sort_failures_before_printing_them() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -806,7 +806,7 @@ fn should_sort_failures_before_printing_them() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, @@ -855,7 +855,7 @@ fn test_dyn_bench_returning_err_fails_when_run_as_test() { ignore: false, ignore_message: None, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: ShouldPanic::No, compile_fail: false, no_run: false, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 5d3a7bd3fde85..05d44716b22b2 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -1064,7 +1064,7 @@ impl Tester for Collector { ignore_message: None, // compiler failures are test failures #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic: test::ShouldPanic::No, compile_fail: config.compile_fail, no_run, diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index a666acf0546e4..238bfa2506c15 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -1044,7 +1044,7 @@ pub fn make_test_description( ignore, ignore_message, #[cfg(not(bootstrap))] - location_info: "src\\lib.rs:10:10: 10:20", + location_info: "", should_panic, compile_fail: false, no_run: false, From 6dffee4cb43571af455974ccf11008440d1b020f Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Wed, 8 Feb 2023 08:54:39 -0500 Subject: [PATCH 09/10] #107307 Adding additional information to "cargo test --list" output fixing build break. --- compiler/rustc_builtin_macros/src/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 17d80fbac6e21..ae9f7ed046af2 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -8,7 +8,7 @@ use rustc_errors::Applicability; use rustc_expand::base::*; use rustc_session::Session; use rustc_span::symbol::{sym, Ident, Symbol}; -use rustc_span::Span; +use rustc_span::{FileNameDisplayPreference, Span}; use std::iter; use thin_vec::thin_vec; From 6a3ccf5a21a67f2f2c2f8def8d06676476a2b080 Mon Sep 17 00:00:00 2001 From: "Partha P. Das" Date: Wed, 8 Feb 2023 09:51:13 -0500 Subject: [PATCH 10/10] #107307 Adding additional information to "cargo test --list" output making the delimiter consistent. --- library/test/src/console.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/test/src/console.rs b/library/test/src/console.rs index df10ce0ca94ca..91c235a5c75d2 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -180,7 +180,7 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec) -> io::Res let state_str = if ignore { "ignored" } else { "active" }; - writeln!(output, "{name}: {fntype} | {state_str} | {location_info}")?; + writeln!(output, "{name} | {fntype} | {state_str} | {location_info}")?; st.write_log(|| format!("{fntype} {name} {state_str} {location_info}\n"))?; }