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

Commit ace0e6f

Browse files
committed
Fix clippy issues
1 parent 182d9b7 commit ace0e6f

File tree

5 files changed

+357
-340
lines changed

5 files changed

+357
-340
lines changed

libtest/formatters/json.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
5959
stdout: &[u8],
6060
) -> io::Result<()> {
6161
match *result {
62-
TrOk => self.write_event("test", desc.name.as_slice(), "ok", None),
62+
TestResult::TrOk => {
63+
self.write_event("test", desc.name.as_slice(), "ok", None)
64+
}
6365

64-
TrFailed => {
65-
let extra_data = if stdout.len() > 0 {
66+
TestResult::TrFailed => {
67+
let extra_data = if stdout.is_empty() {
68+
None
69+
} else {
6670
Some(format!(
6771
r#""stdout": "{}""#,
6872
EscapedString(String::from_utf8_lossy(stdout))
6973
))
70-
} else {
71-
None
7274
};
7375

7476
self.write_event(
@@ -79,25 +81,25 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
7981
)
8082
}
8183

82-
TrFailedMsg(ref m) => self.write_event(
84+
TestResult::TrFailedMsg(ref m) => self.write_event(
8385
"test",
8486
desc.name.as_slice(),
8587
"failed",
8688
Some(format!(r#""message": "{}""#, EscapedString(m))),
8789
),
8890

89-
TrIgnored => {
91+
TestResult::TrIgnored => {
9092
self.write_event("test", desc.name.as_slice(), "ignored", None)
9193
}
9294

93-
TrAllowedFail => self.write_event(
95+
TestResult::TrAllowedFail => self.write_event(
9496
"test",
9597
desc.name.as_slice(),
9698
"allowed_failure",
9799
None,
98100
),
99101

100-
TrBench(ref bs) => {
102+
TestResult::TrBench(ref bs) => {
101103
let median = bs.ns_iter_summ.median as usize;
102104
let deviation =
103105
(bs.ns_iter_summ.max - bs.ns_iter_summ.min) as usize;

libtest/formatters/pretty.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<T: Write> PrettyFormatter<T> {
1717
max_name_len: usize,
1818
is_multithreaded: bool,
1919
) -> Self {
20-
PrettyFormatter {
20+
Self {
2121
out,
2222
use_color,
2323
max_name_len,
@@ -65,7 +65,7 @@ impl<T: Write> PrettyFormatter<T> {
6565
color: term::color::Color,
6666
) -> io::Result<()> {
6767
match self.out {
68-
Pretty(ref mut term) => {
68+
OutputLocation::Pretty(ref mut term) => {
6969
if self.use_color {
7070
term.fg(color)?;
7171
}
@@ -75,7 +75,7 @@ impl<T: Write> PrettyFormatter<T> {
7575
}
7676
term.flush()
7777
}
78-
Raw(ref mut stdout) => {
78+
OutputLocation::Raw(ref mut stdout) => {
7979
stdout.write_all(word.as_bytes())?;
8080
stdout.flush()
8181
}
@@ -156,7 +156,7 @@ impl<T: Write> PrettyFormatter<T> {
156156

157157
impl<T: Write> OutputFormatter for PrettyFormatter<T> {
158158
fn write_run_start(&mut self, test_count: usize) -> io::Result<()> {
159-
let noun = if test_count != 1 { "tests" } else { "test" };
159+
let noun = if test_count == 1 { "test" } else { "tests" };
160160
self.write_plain(&format!("\nrunning {} {}\n", test_count, noun))
161161
}
162162

@@ -183,11 +183,13 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
183183
}
184184

185185
match *result {
186-
TrOk => self.write_ok(),
187-
TrFailed | TrFailedMsg(_) => self.write_failed(),
188-
TrIgnored => self.write_ignored(),
189-
TrAllowedFail => self.write_allowed_fail(),
190-
TrBench(ref bs) => {
186+
TestResult::TrOk => self.write_ok(),
187+
TestResult::TrFailed | TestResult::TrFailedMsg(_) => {
188+
self.write_failed()
189+
}
190+
TestResult::TrIgnored => self.write_ignored(),
191+
TestResult::TrAllowedFail => self.write_allowed_fail(),
192+
TestResult::TrBench(ref bs) => {
191193
self.write_bench()?;
192194
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))
193195
}

libtest/formatters/terse.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<T: Write> TerseFormatter<T> {
1818
max_name_len: usize,
1919
is_multithreaded: bool,
2020
) -> Self {
21-
TerseFormatter {
21+
Self {
2222
out,
2323
use_color,
2424
max_name_len,
@@ -77,7 +77,7 @@ impl<T: Write> TerseFormatter<T> {
7777
color: term::color::Color,
7878
) -> io::Result<()> {
7979
match self.out {
80-
Pretty(ref mut term) => {
80+
OutputLocation::Pretty(ref mut term) => {
8181
if self.use_color {
8282
term.fg(color)?;
8383
}
@@ -87,7 +87,7 @@ impl<T: Write> TerseFormatter<T> {
8787
}
8888
term.flush()
8989
}
90-
Raw(ref mut stdout) => {
90+
OutputLocation::Raw(ref mut stdout) => {
9191
stdout.write_all(word.as_bytes())?;
9292
stdout.flush()
9393
}
@@ -169,7 +169,7 @@ impl<T: Write> TerseFormatter<T> {
169169
impl<T: Write> OutputFormatter for TerseFormatter<T> {
170170
fn write_run_start(&mut self, test_count: usize) -> io::Result<()> {
171171
self.total_test_count = test_count;
172-
let noun = if test_count != 1 { "tests" } else { "test" };
172+
let noun = if test_count == 1 { "test" } else { "tests" };
173173
self.write_plain(&format!("\nrunning {} {}\n", test_count, noun))
174174
}
175175

@@ -178,7 +178,9 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
178178
// in order to indicate benchmarks.
179179
// When running benchmarks, terse-mode should still print their name as if
180180
// it is the Pretty formatter.
181-
if !self.is_multithreaded && desc.name.padding() == PadOnRight {
181+
if !self.is_multithreaded
182+
&& desc.name.padding() == NamePadding::PadOnRight
183+
{
182184
self.write_test_name(desc)?;
183185
}
184186

@@ -192,11 +194,13 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
192194
_: &[u8],
193195
) -> io::Result<()> {
194196
match *result {
195-
TrOk => self.write_ok(),
196-
TrFailed | TrFailedMsg(_) => self.write_failed(),
197-
TrIgnored => self.write_ignored(),
198-
TrAllowedFail => self.write_allowed_fail(),
199-
TrBench(ref bs) => {
197+
TestResult::TrOk => self.write_ok(),
198+
TestResult::TrFailed | TestResult::TrFailedMsg(_) => {
199+
self.write_failed()
200+
}
201+
TestResult::TrIgnored => self.write_ignored(),
202+
TestResult::TrAllowedFail => self.write_allowed_fail(),
203+
TestResult::TrBench(ref bs) => {
200204
if self.is_multithreaded {
201205
self.write_test_name(desc)?;
202206
}

0 commit comments

Comments
 (0)