Skip to content

Commit 05d2221

Browse files
committed
Auto merge of #94566 - yanganto:show-ignore-message, r=m-ou-se
Show ignore message in console and json output - Provide ignore the message in console and JSON output - Modify the ignore message style in the log file related: #92714
2 parents 11909e3 + b1c3494 commit 05d2221

File tree

9 files changed

+33
-12
lines changed

9 files changed

+33
-12
lines changed

library/test/src/console.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl ConsoleTestState {
118118
TestResult::TrIgnored => {
119119
#[cfg(not(bootstrap))]
120120
if let Some(msg) = ignore_message {
121-
format!("ignored, {msg}")
121+
format!("ignored: {msg}")
122122
} else {
123123
"ignored".to_owned()
124124
}

library/test/src/formatters/json.rs

+13
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
121121
),
122122

123123
TestResult::TrIgnored => {
124+
#[cfg(not(bootstrap))]
125+
return self.write_event(
126+
"test",
127+
desc.name.as_slice(),
128+
"ignored",
129+
exec_time,
130+
stdout,
131+
desc.ignore_message
132+
.map(|msg| format!(r#""message": "{}""#, EscapedString(msg)))
133+
.as_deref(),
134+
);
135+
136+
#[cfg(bootstrap)]
124137
self.write_event("test", desc.name.as_slice(), "ignored", exec_time, stdout, None)
125138
}
126139

library/test/src/formatters/pretty.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ impl<T: Write> PrettyFormatter<T> {
4545
self.write_short_result("FAILED", term::color::RED)
4646
}
4747

48-
pub fn write_ignored(&mut self) -> io::Result<()> {
49-
self.write_short_result("ignored", term::color::YELLOW)
48+
pub fn write_ignored(&mut self, message: Option<&'static str>) -> io::Result<()> {
49+
if let Some(message) = message {
50+
self.write_short_result(&format!("ignored, {}", message), term::color::YELLOW)
51+
} else {
52+
self.write_short_result("ignored", term::color::YELLOW)
53+
}
5054
}
5155

5256
pub fn write_time_failed(&mut self) -> io::Result<()> {
@@ -214,7 +218,12 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
214218
match *result {
215219
TestResult::TrOk => self.write_ok()?,
216220
TestResult::TrFailed | TestResult::TrFailedMsg(_) => self.write_failed()?,
217-
TestResult::TrIgnored => self.write_ignored()?,
221+
TestResult::TrIgnored => {
222+
#[cfg(not(bootstrap))]
223+
self.write_ignored(desc.ignore_message)?;
224+
#[cfg(bootstrap)]
225+
self.write_ignored(None)?;
226+
}
218227
TestResult::TrBench(ref bs) => {
219228
self.write_bench()?;
220229
self.write_plain(&format!(": {}", fmt_bench_samples(bs)))?;

src/test/run-make-fulldeps/libtest-json/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
OUTPUT_FILE_DEFAULT := $(TMPDIR)/libtest-json-output-default.json
66
OUTPUT_FILE_STDOUT_SUCCESS := $(TMPDIR)/libtest-json-output-stdout-success.json
77

8-
all:
8+
all: f.rs validate_json.py output-default.json output-stdout-success.json
99
$(RUSTC) --test f.rs
1010
RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=json > $(OUTPUT_FILE_DEFAULT) || true
1111
RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=json --show-output > $(OUTPUT_FILE_STDOUT_SUCCESS) || true

src/test/run-make-fulldeps/libtest-json/f.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn c() {
1616
}
1717

1818
#[test]
19-
#[ignore]
19+
#[ignore = "msg"]
2020
fn d() {
2121
assert!(false);
2222
}

src/test/run-make-fulldeps/libtest-json/output-default.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
{ "type": "test", "event": "started", "name": "c" }
77
{ "type": "test", "name": "c", "event": "ok" }
88
{ "type": "test", "event": "started", "name": "d" }
9-
{ "type": "test", "name": "d", "event": "ignored" }
9+
{ "type": "test", "name": "d", "event": "ignored", "message": "msg" }
1010
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME }

src/test/run-make-fulldeps/libtest-json/output-stdout-success.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
{ "type": "test", "event": "started", "name": "c" }
77
{ "type": "test", "name": "c", "event": "ok", "stdout": "thread 'main' panicked at 'assertion failed: false', f.rs:15:5\n" }
88
{ "type": "test", "event": "started", "name": "d" }
9-
{ "type": "test", "name": "d", "event": "ignored" }
9+
{ "type": "test", "name": "d", "event": "ignored", "message": "msg" }
1010
{ "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME }

src/test/ui/test-attrs/test-type.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// ignore-emscripten no threads support
66
// run-pass
77

8-
98
#[test]
109
fn test_ok() {
1110
let _a = true;
@@ -18,9 +17,9 @@ fn test_panic() {
1817
}
1918

2019
#[test]
21-
#[ignore]
20+
#[ignore = "msg"]
2221
fn test_no_run() {
23-
loop{
22+
loop {
2423
println!("Hello, world");
2524
}
2625
}

src/test/ui/test-attrs/test-type.run.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 3 tests
3-
test test_no_run ... ignored
3+
test test_no_run ... ignored, msg
44
test test_ok ... ok
55
test test_panic - should panic ... ok
66

0 commit comments

Comments
 (0)