Skip to content

#107307 Adding additional information to "cargo test --list" output #107785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Session.vim
.project
.favorites.json
.settings/
.vs/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you avoid changes to this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the visual studio ide creating the file. like .vscode.

with the extension i have just released (rust-analy - for which this PR is, i do expect windows devs to use visual studio more often.

is it okay to retain it?


## Tool
.valgrindrc
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -280,6 +280,11 @@ pub fn expand_test_or_bench(
cx.expr_none(sp)
},
),
// location_info: <relative_path_of_source>:<start_line>:<start_col>: <end_line>:<end_col>
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
Expand Down Expand Up @@ -396,6 +401,11 @@ fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
}
}

fn item_location_info(cx: &ExtCtxt<'_>, item: &ast::Item) -> Symbol {
let li = cx.sess.source_map().span_to_string(item.ident.span, FileNameDisplayPreference::Local);
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) => {
Expand Down
21 changes: 18 additions & 3 deletions library/test/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,17 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> 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,
#[cfg(not(bootstrap))]
location_info,
..
},
testfn,
} = test;

let fntype = match testfn {
StaticTestFn(..) | DynTestFn(..) => {
Expand All @@ -165,8 +175,13 @@ pub fn list_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Res
}
};

writeln!(output, "{name}: {fntype}")?;
st.write_log(|| format!("{fntype} {name}\n"))?;
#[cfg(bootstrap)]
let location_info = "location_info_tbd_during_bootstrap";

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 {
Expand Down
40 changes: 40 additions & 0 deletions library/test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
name: StaticTestName("1"),
ignore: true,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -75,6 +77,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
name: StaticTestName("2"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -95,6 +99,8 @@ pub fn do_not_run_ignored_tests() {
name: StaticTestName("whatever"),
ignore: true,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -118,6 +124,8 @@ pub fn ignored_tests_result_in_ignored() {
name: StaticTestName("whatever"),
ignore: true,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -143,6 +151,8 @@ fn test_should_panic() {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::Yes,
compile_fail: false,
no_run: false,
Expand All @@ -168,6 +178,8 @@ fn test_should_panic_good_message() {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::YesWithMessage("error message"),
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -198,6 +210,8 @@ fn test_should_panic_bad_message() {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::YesWithMessage(expected),
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -232,6 +246,8 @@ fn test_should_panic_non_string_message_type() {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::YesWithMessage(expected),
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -260,6 +276,8 @@ fn test_should_panic_but_succeeds() {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -288,6 +306,8 @@ fn report_time_test_template(report_time: bool) -> Option<TestExecTime> {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -325,6 +345,8 @@ fn time_test_failure_template(test_type: TestType) -> TestResult {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -364,6 +386,8 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -476,6 +500,8 @@ pub fn exclude_should_panic_option() {
name: StaticTestName("3"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::Yes,
compile_fail: false,
no_run: false,
Expand All @@ -500,6 +526,8 @@ pub fn exact_filter_match() {
name: StaticTestName(name),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -591,6 +619,8 @@ fn sample_tests() -> Vec<TestDescAndFn> {
name: DynTestName((*name).clone()),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -720,6 +750,8 @@ pub fn test_bench_no_iter() {
name: StaticTestName("f"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -743,6 +775,8 @@ pub fn test_bench_iter() {
name: StaticTestName("f"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -759,6 +793,8 @@ fn should_sort_failures_before_printing_them() {
name: StaticTestName("a"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -769,6 +805,8 @@ fn should_sort_failures_before_printing_them() {
name: StaticTestName("b"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -816,6 +854,8 @@ fn test_dyn_bench_returning_err_fails_when_run_as_test() {
name: StaticTestName("whatever"),
ignore: false,
ignore_message: None,
#[cfg(not(bootstrap))]
location_info: "",
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down
2 changes: 2 additions & 0 deletions library/test/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ 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,
pub no_run: bool,
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,8 @@ impl Tester for Collector {
},
ignore_message: None,
// compiler failures are test failures
#[cfg(not(bootstrap))]
location_info: "",
should_panic: test::ShouldPanic::No,
compile_fail: config.compile_fail,
no_run,
Expand Down
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ pub fn make_test_description<R: Read>(
name,
ignore,
ignore_message,
#[cfg(not(bootstrap))]
location_info: "",
should_panic,
compile_fail: false,
no_run: false,
Expand Down
3 changes: 3 additions & 0 deletions tests/pretty/tests-are-sorted.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down