Skip to content

Commit 6ec5b05

Browse files
authored
Rollup merge of #92714 - yanganto:ignore-message, r=Mark-Simulacrum
Provide ignore message in the result of test Provide ignore the message in the result of the test. This PR does not need RFC, because it is about the presentation of the report of `cargo test`. However, the following document listed here helps you to know about PR. - [RFC](rust-lang/rfcs#3217) - [Rendered](https://github.com/yanganto/rfcs/blob/ignore-test-message/text/0000-ignore-test-message.md) - [Previous discussion on IRLO](https://internals.rust-lang.org/t/pre-rfc-provide-ignore-message-when-the-test-ignored/15904) If there is something improper, please let me know. Thanks.
2 parents f6a7993 + bb3b557 commit 6ec5b05

File tree

7 files changed

+90
-2
lines changed

7 files changed

+90
-2
lines changed

compiler/rustc_builtin_macros/src/test.rs

+23
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ pub fn expand_test_or_bench(
262262
"ignore",
263263
cx.expr_bool(sp, should_ignore(&cx.sess, &item)),
264264
),
265+
// ignore_message: Some("...") | None
266+
field(
267+
"ignore_message",
268+
if let Some(msg) = should_ignore_message(cx, &item) {
269+
cx.expr_some(sp, cx.expr_str(sp, msg))
270+
} else {
271+
cx.expr_none(sp)
272+
},
273+
),
265274
// compile_fail: true | false
266275
field("compile_fail", cx.expr_bool(sp, false)),
267276
// no_run: true | false
@@ -364,6 +373,20 @@ fn should_ignore(sess: &Session, i: &ast::Item) -> bool {
364373
sess.contains_name(&i.attrs, sym::ignore)
365374
}
366375

376+
fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
377+
match cx.sess.find_by_name(&i.attrs, sym::ignore) {
378+
Some(attr) => {
379+
match attr.meta_item_list() {
380+
// Handle #[ignore(bar = "foo")]
381+
Some(_) => None,
382+
// Handle #[ignore] and #[ignore = "message"]
383+
None => attr.value_str(),
384+
}
385+
}
386+
None => None,
387+
}
388+
}
389+
367390
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
368391
match cx.sess.find_by_name(&i.attrs, sym::should_panic) {
369392
Some(attr) => {

compiler/rustc_expand/src/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ impl<'a> ExtCtxt<'a> {
329329
self.expr_call_global(sp, some, vec![expr])
330330
}
331331

332+
pub fn expr_none(&self, sp: Span) -> P<ast::Expr> {
333+
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
334+
self.expr_path(self.path_global(sp, none))
335+
}
332336
pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
333337
self.expr(sp, ast::ExprKind::Tup(exprs))
334338
}

library/test/src/console.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,32 @@ impl ConsoleTestState {
103103
exec_time: Option<&TestExecTime>,
104104
) -> io::Result<()> {
105105
self.write_log(|| {
106+
let TestDesc {
107+
name,
108+
#[cfg(not(bootstrap))]
109+
ignore_message,
110+
..
111+
} = test;
106112
format!(
107113
"{} {}",
108114
match *result {
109115
TestResult::TrOk => "ok".to_owned(),
110116
TestResult::TrFailed => "failed".to_owned(),
111117
TestResult::TrFailedMsg(ref msg) => format!("failed: {}", msg),
112-
TestResult::TrIgnored => "ignored".to_owned(),
118+
TestResult::TrIgnored => {
119+
#[cfg(not(bootstrap))]
120+
if let Some(msg) = ignore_message {
121+
format!("ignored, {}", msg)
122+
} else {
123+
"ignored".to_owned()
124+
}
125+
#[cfg(bootstrap)]
126+
"ignored".to_owned()
127+
}
113128
TestResult::TrBench(ref bs) => fmt_bench_samples(bs),
114129
TestResult::TrTimedFail => "failed (time limit exceeded)".to_owned(),
115130
},
116-
test.name,
131+
name,
117132
)
118133
})?;
119134
if let Some(exec_time) = exec_time {

library/test/src/tests.rs

+38
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
6161
desc: TestDesc {
6262
name: StaticTestName("1"),
6363
ignore: true,
64+
#[cfg(not(bootstrap))]
65+
ignore_message: None,
6466
should_panic: ShouldPanic::No,
6567
compile_fail: false,
6668
no_run: false,
@@ -74,6 +76,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
7476
desc: TestDesc {
7577
name: StaticTestName("2"),
7678
ignore: false,
79+
#[cfg(not(bootstrap))]
80+
ignore_message: None,
7781
should_panic: ShouldPanic::No,
7882
compile_fail: false,
7983
no_run: false,
@@ -95,6 +99,8 @@ pub fn do_not_run_ignored_tests() {
9599
desc: TestDesc {
96100
name: StaticTestName("whatever"),
97101
ignore: true,
102+
#[cfg(not(bootstrap))]
103+
ignore_message: None,
98104
should_panic: ShouldPanic::No,
99105
compile_fail: false,
100106
no_run: false,
@@ -117,6 +123,8 @@ pub fn ignored_tests_result_in_ignored() {
117123
desc: TestDesc {
118124
name: StaticTestName("whatever"),
119125
ignore: true,
126+
#[cfg(not(bootstrap))]
127+
ignore_message: None,
120128
should_panic: ShouldPanic::No,
121129
compile_fail: false,
122130
no_run: false,
@@ -143,6 +151,8 @@ fn test_should_panic() {
143151
desc: TestDesc {
144152
name: StaticTestName("whatever"),
145153
ignore: false,
154+
#[cfg(not(bootstrap))]
155+
ignore_message: None,
146156
should_panic: ShouldPanic::Yes,
147157
compile_fail: false,
148158
no_run: false,
@@ -169,6 +179,8 @@ fn test_should_panic_good_message() {
169179
desc: TestDesc {
170180
name: StaticTestName("whatever"),
171181
ignore: false,
182+
#[cfg(not(bootstrap))]
183+
ignore_message: None,
172184
should_panic: ShouldPanic::YesWithMessage("error message"),
173185
compile_fail: false,
174186
no_run: false,
@@ -200,6 +212,8 @@ fn test_should_panic_bad_message() {
200212
desc: TestDesc {
201213
name: StaticTestName("whatever"),
202214
ignore: false,
215+
#[cfg(not(bootstrap))]
216+
ignore_message: None,
203217
should_panic: ShouldPanic::YesWithMessage(expected),
204218
compile_fail: false,
205219
no_run: false,
@@ -235,6 +249,8 @@ fn test_should_panic_non_string_message_type() {
235249
desc: TestDesc {
236250
name: StaticTestName("whatever"),
237251
ignore: false,
252+
#[cfg(not(bootstrap))]
253+
ignore_message: None,
238254
should_panic: ShouldPanic::YesWithMessage(expected),
239255
compile_fail: false,
240256
no_run: false,
@@ -262,6 +278,8 @@ fn test_should_panic_but_succeeds() {
262278
desc: TestDesc {
263279
name: StaticTestName("whatever"),
264280
ignore: false,
281+
#[cfg(not(bootstrap))]
282+
ignore_message: None,
265283
should_panic,
266284
compile_fail: false,
267285
no_run: false,
@@ -297,6 +315,8 @@ fn report_time_test_template(report_time: bool) -> Option<TestExecTime> {
297315
desc: TestDesc {
298316
name: StaticTestName("whatever"),
299317
ignore: false,
318+
#[cfg(not(bootstrap))]
319+
ignore_message: None,
300320
should_panic: ShouldPanic::No,
301321
compile_fail: false,
302322
no_run: false,
@@ -333,6 +353,8 @@ fn time_test_failure_template(test_type: TestType) -> TestResult {
333353
desc: TestDesc {
334354
name: StaticTestName("whatever"),
335355
ignore: false,
356+
#[cfg(not(bootstrap))]
357+
ignore_message: None,
336358
should_panic: ShouldPanic::No,
337359
compile_fail: false,
338360
no_run: false,
@@ -373,6 +395,8 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
373395
TestDesc {
374396
name: StaticTestName("whatever"),
375397
ignore: false,
398+
#[cfg(not(bootstrap))]
399+
ignore_message: None,
376400
should_panic: ShouldPanic::No,
377401
compile_fail: false,
378402
no_run: false,
@@ -486,6 +510,8 @@ pub fn exclude_should_panic_option() {
486510
desc: TestDesc {
487511
name: StaticTestName("3"),
488512
ignore: false,
513+
#[cfg(not(bootstrap))]
514+
ignore_message: None,
489515
should_panic: ShouldPanic::Yes,
490516
compile_fail: false,
491517
no_run: false,
@@ -511,6 +537,8 @@ pub fn exact_filter_match() {
511537
desc: TestDesc {
512538
name: StaticTestName(name),
513539
ignore: false,
540+
#[cfg(not(bootstrap))]
541+
ignore_message: None,
514542
should_panic: ShouldPanic::No,
515543
compile_fail: false,
516544
no_run: false,
@@ -601,6 +629,8 @@ fn sample_tests() -> Vec<TestDescAndFn> {
601629
desc: TestDesc {
602630
name: DynTestName((*name).clone()),
603631
ignore: false,
632+
#[cfg(not(bootstrap))]
633+
ignore_message: None,
604634
should_panic: ShouldPanic::No,
605635
compile_fail: false,
606636
no_run: false,
@@ -753,6 +783,8 @@ pub fn test_bench_no_iter() {
753783
let desc = TestDesc {
754784
name: StaticTestName("f"),
755785
ignore: false,
786+
#[cfg(not(bootstrap))]
787+
ignore_message: None,
756788
should_panic: ShouldPanic::No,
757789
compile_fail: false,
758790
no_run: false,
@@ -776,6 +808,8 @@ pub fn test_bench_iter() {
776808
let desc = TestDesc {
777809
name: StaticTestName("f"),
778810
ignore: false,
811+
#[cfg(not(bootstrap))]
812+
ignore_message: None,
779813
should_panic: ShouldPanic::No,
780814
compile_fail: false,
781815
no_run: false,
@@ -793,6 +827,8 @@ fn should_sort_failures_before_printing_them() {
793827
let test_a = TestDesc {
794828
name: StaticTestName("a"),
795829
ignore: false,
830+
#[cfg(not(bootstrap))]
831+
ignore_message: None,
796832
should_panic: ShouldPanic::No,
797833
compile_fail: false,
798834
no_run: false,
@@ -804,6 +840,8 @@ fn should_sort_failures_before_printing_them() {
804840
let test_b = TestDesc {
805841
name: StaticTestName("b"),
806842
ignore: false,
843+
#[cfg(not(bootstrap))]
844+
ignore_message: None,
807845
should_panic: ShouldPanic::No,
808846
compile_fail: false,
809847
no_run: false,

library/test/src/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ pub struct TestId(pub usize);
117117
pub struct TestDesc {
118118
pub name: TestName,
119119
pub ignore: bool,
120+
#[cfg(not(bootstrap))]
121+
pub ignore_message: Option<&'static str>,
120122
pub should_panic: options::ShouldPanic,
121123
pub compile_fail: bool,
122124
pub no_run: bool,

src/librustdoc/doctest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ impl Tester for Collector {
946946
Ignore::None => false,
947947
Ignore::Some(ref ignores) => ignores.iter().any(|s| target_str.contains(s)),
948948
},
949+
#[cfg(not(bootstrap))]
950+
ignore_message: None,
949951
// compiler failures are test failures
950952
should_panic: test::ShouldPanic::No,
951953
compile_fail: config.compile_fail,

src/tools/compiletest/src/header.rs

+4
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ pub fn make_test_description<R: Read>(
806806
cfg: Option<&str>,
807807
) -> test::TestDesc {
808808
let mut ignore = false;
809+
#[cfg(not(bootstrap))]
810+
let ignore_message: Option<String> = None;
809811
let mut should_fail = false;
810812

811813
let rustc_has_profiler_support = env::var_os("RUSTC_PROFILER_SUPPORT").is_some();
@@ -877,6 +879,8 @@ pub fn make_test_description<R: Read>(
877879
test::TestDesc {
878880
name,
879881
ignore,
882+
#[cfg(not(bootstrap))]
883+
ignore_message,
880884
should_panic,
881885
compile_fail: false,
882886
no_run: false,

0 commit comments

Comments
 (0)