Skip to content

Commit 14daf47

Browse files
yangantoMark-Simulacrum
authored andcommitted
Show ignore message in console and json output
1 parent f58d51b commit 14daf47

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
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

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

123123
TestResult::TrIgnored => {
124+
#[cfg(not(bootstrap))]
125+
if let Some(msg) = desc.ignore_message {
126+
self.write_event(
127+
"test",
128+
desc.name.as_slice(),
129+
"ignored",
130+
exec_time,
131+
stdout,
132+
Some(&*format!(r#""message": "{}""#, EscapedString(msg))),
133+
)
134+
} else {
135+
self.write_event(
136+
"test",
137+
desc.name.as_slice(),
138+
"ignored",
139+
exec_time,
140+
stdout,
141+
None,
142+
)
143+
}
144+
#[cfg(bootstrap)]
124145
self.write_event("test", desc.name.as_slice(), "ignored", exec_time, stdout, None)
125146
}
126147

library/test/src/formatters/pretty.rs

+14-5
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, may_message: Option<&'static str>) -> io::Result<()> {
49+
if let Some(message) = may_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<()> {
@@ -59,10 +63,10 @@ impl<T: Write> PrettyFormatter<T> {
5963

6064
pub fn write_short_result(
6165
&mut self,
62-
result: &str,
66+
result: impl AsRef<str>,
6367
color: term::color::Color,
6468
) -> io::Result<()> {
65-
self.write_pretty(result, color)
69+
self.write_pretty(result.as_ref(), color)
6670
}
6771

6872
pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> 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)))?;

0 commit comments

Comments
 (0)