1
Fork 0

Include ignore message in libtest output

As an example:

    #[test]
    #[ignore = "not yet implemented"]
    fn test_ignored() {
        ...
    }

Will now render as:

    running 2 tests
    test tests::test_ignored ... ignored, not yet implemented

    test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s
This commit is contained in:
Antonio Yang 2022-01-10 14:01:12 +08:00 committed by Mark Rousskov
parent 3d127e2040
commit bb3b5574cd
7 changed files with 90 additions and 2 deletions

View file

@ -262,6 +262,15 @@ pub fn expand_test_or_bench(
"ignore", "ignore",
cx.expr_bool(sp, should_ignore(&cx.sess, &item)), cx.expr_bool(sp, should_ignore(&cx.sess, &item)),
), ),
// ignore_message: Some("...") | None
field(
"ignore_message",
if let Some(msg) = should_ignore_message(cx, &item) {
cx.expr_some(sp, cx.expr_str(sp, msg))
} else {
cx.expr_none(sp)
},
),
// compile_fail: true | false // compile_fail: true | false
field("compile_fail", cx.expr_bool(sp, false)), field("compile_fail", cx.expr_bool(sp, false)),
// no_run: true | false // no_run: true | false
@ -364,6 +373,20 @@ fn should_ignore(sess: &Session, i: &ast::Item) -> bool {
sess.contains_name(&i.attrs, sym::ignore) sess.contains_name(&i.attrs, sym::ignore)
} }
fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
match cx.sess.find_by_name(&i.attrs, sym::ignore) {
Some(attr) => {
match attr.meta_item_list() {
// Handle #[ignore(bar = "foo")]
Some(_) => None,
// Handle #[ignore] and #[ignore = "message"]
None => attr.value_str(),
}
}
None => None,
}
}
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic { fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
match cx.sess.find_by_name(&i.attrs, sym::should_panic) { match cx.sess.find_by_name(&i.attrs, sym::should_panic) {
Some(attr) => { Some(attr) => {

View file

@ -329,6 +329,10 @@ impl<'a> ExtCtxt<'a> {
self.expr_call_global(sp, some, vec![expr]) self.expr_call_global(sp, some, vec![expr])
} }
pub fn expr_none(&self, sp: Span) -> P<ast::Expr> {
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
self.expr_path(self.path_global(sp, none))
}
pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
self.expr(sp, ast::ExprKind::Tup(exprs)) self.expr(sp, ast::ExprKind::Tup(exprs))
} }

View file

@ -103,17 +103,32 @@ impl ConsoleTestState {
exec_time: Option<&TestExecTime>, exec_time: Option<&TestExecTime>,
) -> io::Result<()> { ) -> io::Result<()> {
self.write_log(|| { self.write_log(|| {
let TestDesc {
name,
#[cfg(not(bootstrap))]
ignore_message,
..
} = test;
format!( format!(
"{} {}", "{} {}",
match *result { match *result {
TestResult::TrOk => "ok".to_owned(), TestResult::TrOk => "ok".to_owned(),
TestResult::TrFailed => "failed".to_owned(), TestResult::TrFailed => "failed".to_owned(),
TestResult::TrFailedMsg(ref msg) => format!("failed: {}", msg), TestResult::TrFailedMsg(ref msg) => format!("failed: {}", msg),
TestResult::TrIgnored => "ignored".to_owned(), TestResult::TrIgnored => {
#[cfg(not(bootstrap))]
if let Some(msg) = ignore_message {
format!("ignored, {}", msg)
} else {
"ignored".to_owned()
}
#[cfg(bootstrap)]
"ignored".to_owned()
}
TestResult::TrBench(ref bs) => fmt_bench_samples(bs), TestResult::TrBench(ref bs) => fmt_bench_samples(bs),
TestResult::TrTimedFail => "failed (time limit exceeded)".to_owned(), TestResult::TrTimedFail => "failed (time limit exceeded)".to_owned(),
}, },
test.name, name,
) )
})?; })?;
if let Some(exec_time) = exec_time { if let Some(exec_time) = exec_time {

View file

@ -61,6 +61,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("1"), name: StaticTestName("1"),
ignore: true, ignore: true,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -74,6 +76,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("2"), name: StaticTestName("2"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -95,6 +99,8 @@ pub fn do_not_run_ignored_tests() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: true, ignore: true,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -117,6 +123,8 @@ pub fn ignored_tests_result_in_ignored() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: true, ignore: true,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -143,6 +151,8 @@ fn test_should_panic() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::Yes, should_panic: ShouldPanic::Yes,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -169,6 +179,8 @@ fn test_should_panic_good_message() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::YesWithMessage("error message"), should_panic: ShouldPanic::YesWithMessage("error message"),
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -200,6 +212,8 @@ fn test_should_panic_bad_message() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::YesWithMessage(expected), should_panic: ShouldPanic::YesWithMessage(expected),
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -235,6 +249,8 @@ fn test_should_panic_non_string_message_type() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::YesWithMessage(expected), should_panic: ShouldPanic::YesWithMessage(expected),
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -262,6 +278,8 @@ fn test_should_panic_but_succeeds() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic, should_panic,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -297,6 +315,8 @@ fn report_time_test_template(report_time: bool) -> Option<TestExecTime> {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -333,6 +353,8 @@ fn time_test_failure_template(test_type: TestType) -> TestResult {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -373,6 +395,8 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
TestDesc { TestDesc {
name: StaticTestName("whatever"), name: StaticTestName("whatever"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -486,6 +510,8 @@ pub fn exclude_should_panic_option() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName("3"), name: StaticTestName("3"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::Yes, should_panic: ShouldPanic::Yes,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -511,6 +537,8 @@ pub fn exact_filter_match() {
desc: TestDesc { desc: TestDesc {
name: StaticTestName(name), name: StaticTestName(name),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -601,6 +629,8 @@ fn sample_tests() -> Vec<TestDescAndFn> {
desc: TestDesc { desc: TestDesc {
name: DynTestName((*name).clone()), name: DynTestName((*name).clone()),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -753,6 +783,8 @@ pub fn test_bench_no_iter() {
let desc = TestDesc { let desc = TestDesc {
name: StaticTestName("f"), name: StaticTestName("f"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -776,6 +808,8 @@ pub fn test_bench_iter() {
let desc = TestDesc { let desc = TestDesc {
name: StaticTestName("f"), name: StaticTestName("f"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -793,6 +827,8 @@ fn should_sort_failures_before_printing_them() {
let test_a = TestDesc { let test_a = TestDesc {
name: StaticTestName("a"), name: StaticTestName("a"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,
@ -804,6 +840,8 @@ fn should_sort_failures_before_printing_them() {
let test_b = TestDesc { let test_b = TestDesc {
name: StaticTestName("b"), name: StaticTestName("b"),
ignore: false, ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No, should_panic: ShouldPanic::No,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,

View file

@ -117,6 +117,8 @@ pub struct TestId(pub usize);
pub struct TestDesc { pub struct TestDesc {
pub name: TestName, pub name: TestName,
pub ignore: bool, pub ignore: bool,
#[cfg(not(bootstrap))]
pub ignore_message: Option<&'static str>,
pub should_panic: options::ShouldPanic, pub should_panic: options::ShouldPanic,
pub compile_fail: bool, pub compile_fail: bool,
pub no_run: bool, pub no_run: bool,

View file

@ -949,6 +949,8 @@ impl Tester for Collector {
Ignore::None => false, Ignore::None => false,
Ignore::Some(ref ignores) => ignores.iter().any(|s| target_str.contains(s)), Ignore::Some(ref ignores) => ignores.iter().any(|s| target_str.contains(s)),
}, },
#[cfg(not(bootstrap))]
ignore_message: None,
// compiler failures are test failures // compiler failures are test failures
should_panic: test::ShouldPanic::No, should_panic: test::ShouldPanic::No,
compile_fail: config.compile_fail, compile_fail: config.compile_fail,

View file

@ -806,6 +806,8 @@ pub fn make_test_description<R: Read>(
cfg: Option<&str>, cfg: Option<&str>,
) -> test::TestDesc { ) -> test::TestDesc {
let mut ignore = false; let mut ignore = false;
#[cfg(not(bootstrap))]
let ignore_message: Option<String> = None;
let mut should_fail = false; let mut should_fail = false;
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some(); let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
@ -877,6 +879,8 @@ pub fn make_test_description<R: Read>(
test::TestDesc { test::TestDesc {
name, name,
ignore, ignore,
#[cfg(not(bootstrap))]
ignore_message,
should_panic, should_panic,
compile_fail: false, compile_fail: false,
no_run: false, no_run: false,