Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

Commit 182d9b7

Browse files
committed
Formatting
1 parent e8e843c commit 182d9b7

File tree

7 files changed

+214
-69
lines changed

7 files changed

+214
-69
lines changed

libtest/formatters/json.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
7171
None
7272
};
7373

74-
self.write_event("test", desc.name.as_slice(), "failed", extra_data)
74+
self.write_event(
75+
"test",
76+
desc.name.as_slice(),
77+
"failed",
78+
extra_data,
79+
)
7580
}
7681

7782
TrFailedMsg(ref m) => self.write_event(
@@ -81,15 +86,21 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
8186
Some(format!(r#""message": "{}""#, EscapedString(m))),
8287
),
8388

84-
TrIgnored => self.write_event("test", desc.name.as_slice(), "ignored", None),
85-
86-
TrAllowedFail => {
87-
self.write_event("test", desc.name.as_slice(), "allowed_failure", None)
89+
TrIgnored => {
90+
self.write_event("test", desc.name.as_slice(), "ignored", None)
8891
}
8992

93+
TrAllowedFail => self.write_event(
94+
"test",
95+
desc.name.as_slice(),
96+
"allowed_failure",
97+
None,
98+
),
99+
90100
TrBench(ref bs) => {
91101
let median = bs.ns_iter_summ.median as usize;
92-
let deviation = (bs.ns_iter_summ.max - bs.ns_iter_summ.min) as usize;
102+
let deviation =
103+
(bs.ns_iter_summ.max - bs.ns_iter_summ.min) as usize;
93104

94105
let mbps = if bs.mb_s == 0 {
95106
String::new()
@@ -117,7 +128,10 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
117128
))
118129
}
119130

120-
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
131+
fn write_run_finish(
132+
&mut self,
133+
state: &ConsoleTestState,
134+
) -> io::Result<bool> {
121135
self.write_message(&*format!(
122136
"{{ \"type\": \"suite\", \
123137
\"event\": \"{}\", \

libtest/formatters/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::*;
22

3-
mod pretty;
43
mod json;
4+
mod pretty;
55
mod terse;
66

7-
pub(crate) use self::pretty::PrettyFormatter;
87
pub(crate) use self::json::JsonFormatter;
8+
pub(crate) use self::pretty::PrettyFormatter;
99
pub(crate) use self::terse::TerseFormatter;
1010

1111
pub(crate) trait OutputFormatter {
@@ -18,5 +18,8 @@ pub(crate) trait OutputFormatter {
1818
result: &TestResult,
1919
stdout: &[u8],
2020
) -> io::Result<()>;
21-
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool>;
21+
fn write_run_finish(
22+
&mut self,
23+
state: &ConsoleTestState,
24+
) -> io::Result<bool>;
2225
}

libtest/formatters/pretty.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ impl<T: Write> PrettyFormatter<T> {
5959
self.write_plain("\n")
6060
}
6161

62-
pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Result<()> {
62+
pub fn write_pretty(
63+
&mut self,
64+
word: &str,
65+
color: term::color::Color,
66+
) -> io::Result<()> {
6367
match self.out {
6468
Pretty(ref mut term) => {
6569
if self.use_color {
@@ -84,7 +88,10 @@ impl<T: Write> PrettyFormatter<T> {
8488
self.out.flush()
8589
}
8690

87-
pub fn write_successes(&mut self, state: &ConsoleTestState) -> io::Result<()> {
91+
pub fn write_successes(
92+
&mut self,
93+
state: &ConsoleTestState,
94+
) -> io::Result<()> {
8895
self.write_plain("\nsuccesses:\n")?;
8996
let mut successes = Vec::new();
9097
let mut stdouts = String::new();
@@ -110,7 +117,10 @@ impl<T: Write> PrettyFormatter<T> {
110117
Ok(())
111118
}
112119

113-
pub fn write_failures(&mut self, state: &ConsoleTestState) -> io::Result<()> {
120+
pub fn write_failures(
121+
&mut self,
122+
state: &ConsoleTestState,
123+
) -> io::Result<()> {
114124
self.write_plain("\nfailures:\n")?;
115125
let mut failures = Vec::new();
116126
let mut fail_out = String::new();
@@ -162,7 +172,12 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
162172
Ok(())
163173
}
164174

165-
fn write_result(&mut self, desc: &TestDesc, result: &TestResult, _: &[u8]) -> io::Result<()> {
175+
fn write_result(
176+
&mut self,
177+
desc: &TestDesc,
178+
result: &TestResult,
179+
_: &[u8],
180+
) -> io::Result<()> {
166181
if self.is_multithreaded {
167182
self.write_test_name(desc)?;
168183
}
@@ -190,7 +205,10 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
190205
))
191206
}
192207

193-
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
208+
fn write_run_finish(
209+
&mut self,
210+
state: &ConsoleTestState,
211+
) -> io::Result<bool> {
194212
if state.options.display_output {
195213
self.write_successes(state)?;
196214
}

libtest/formatters/terse.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,28 @@ impl<T: Write> TerseFormatter<T> {
5454
color: term::color::Color,
5555
) -> io::Result<()> {
5656
self.write_pretty(result, color)?;
57-
if self.test_count % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1 {
57+
if self.test_count % QUIET_MODE_MAX_COLUMN == QUIET_MODE_MAX_COLUMN - 1
58+
{
5859
// we insert a new line every 100 dots in order to flush the
5960
// screen when dealing with line-buffered output (e.g., piping to
6061
// `stamp` in the rust CI).
61-
let out = format!(" {}/{}\n", self.test_count+1, self.total_test_count);
62+
let out = format!(
63+
" {}/{}\n",
64+
self.test_count + 1,
65+
self.total_test_count
66+
);
6267
self.write_plain(&out)?;
6368
}
6469

6570
self.test_count += 1;
6671
Ok(())
6772
}
6873

69-
pub fn write_pretty(&mut self, word: &str, color: term::color::Color) -> io::Result<()> {
74+
pub fn write_pretty(
75+
&mut self,
76+
word: &str,
77+
color: term::color::Color,
78+
) -> io::Result<()> {
7079
match self.out {
7180
Pretty(ref mut term) => {
7281
if self.use_color {
@@ -91,7 +100,10 @@ impl<T: Write> TerseFormatter<T> {
91100
self.out.flush()
92101
}
93102

94-
pub fn write_outputs(&mut self, state: &ConsoleTestState) -> io::Result<()> {
103+
pub fn write_outputs(
104+
&mut self,
105+
state: &ConsoleTestState,
106+
) -> io::Result<()> {
95107
self.write_plain("\nsuccesses:\n")?;
96108
let mut successes = Vec::new();
97109
let mut stdouts = String::new();
@@ -117,7 +129,10 @@ impl<T: Write> TerseFormatter<T> {
117129
Ok(())
118130
}
119131

120-
pub fn write_failures(&mut self, state: &ConsoleTestState) -> io::Result<()> {
132+
pub fn write_failures(
133+
&mut self,
134+
state: &ConsoleTestState,
135+
) -> io::Result<()> {
121136
self.write_plain("\nfailures:\n")?;
122137
let mut failures = Vec::new();
123138
let mut fail_out = String::new();
@@ -170,7 +185,12 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
170185
Ok(())
171186
}
172187

173-
fn write_result(&mut self, desc: &TestDesc, result: &TestResult, _: &[u8]) -> io::Result<()> {
188+
fn write_result(
189+
&mut self,
190+
desc: &TestDesc,
191+
result: &TestResult,
192+
_: &[u8],
193+
) -> io::Result<()> {
174194
match *result {
175195
TrOk => self.write_ok(),
176196
TrFailed | TrFailedMsg(_) => self.write_failed(),
@@ -193,7 +213,10 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
193213
))
194214
}
195215

196-
fn write_run_finish(&mut self, state: &ConsoleTestState) -> io::Result<bool> {
216+
fn write_run_finish(
217+
&mut self,
218+
state: &ConsoleTestState,
219+
) -> io::Result<bool> {
197220
if state.options.display_output {
198221
self.write_outputs(state)?;
199222
}

0 commit comments

Comments
 (0)