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

Cleanup #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions libtest/formatters/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ impl<T: Write> JsonFormatter<T> {
extra: Option<String>,
) -> io::Result<()> {
if let Some(extras) = extra {
self.write_message(&*format!(
self.write_message(&format!(
r#"{{ "type": "{}", "name": "{}", "event": "{}", {} }}"#,
ty,
EscapedString(name),
evt,
extras
))
} else {
self.write_message(&*format!(
self.write_message(&format!(
r#"{{ "type": "{}", "name": "{}", "event": "{}" }}"#,
ty,
EscapedString(name),
Expand All @@ -44,14 +44,14 @@ impl<T: Write> JsonFormatter<T> {

impl<T: Write> OutputFormatter for JsonFormatter<T> {
fn write_run_start(&mut self, test_count: usize) -> io::Result<()> {
self.write_message(&*format!(
self.write_message(&format!(
r#"{{ "type": "suite", "event": "started", "test_count": {} }}"#,
test_count
))
}

fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
self.write_message(&*format!(
self.write_message(&format!(
r#"{{ "type": "test", "event": "started", "name": "{}" }}"#,
EscapedString(desc.name.as_slice())
))
Expand All @@ -63,7 +63,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
result: &TestResult,
stdout: &[u8],
) -> io::Result<()> {
match *result {
match result {
TestResult::TrOk => {
self.write_event("test", desc.name.as_slice(), "ok", None)
}
Expand All @@ -86,7 +86,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
)
}

TestResult::TrFailedMsg(ref m) => self.write_event(
TestResult::TrFailedMsg(m) => self.write_event(
"test",
desc.name.as_slice(),
"failed",
Expand All @@ -104,7 +104,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
None,
),

TestResult::TrBench(ref bs) => {
TestResult::TrBench(bs) => {
let median = bs.ns_iter_summ.median as usize;
let deviation =
(bs.ns_iter_summ.max - bs.ns_iter_summ.min) as usize;
Expand All @@ -123,13 +123,13 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
desc.name, median, deviation, mbps
);

self.write_message(&*line)
self.write_message(&line)
}
}
}

fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()> {
self.write_message(&*format!(
self.write_message(&format!(
r#"{{ "type": "test", "event": "timeout", "name": "{}" }}"#,
desc.name
))
Expand All @@ -139,7 +139,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
&mut self,
state: &ConsoleTestState,
) -> io::Result<bool> {
self.write_message(&*format!(
self.write_message(&format!(
"{{ \"type\": \"suite\", \
\"event\": \"{}\", \
\"passed\": {}, \
Expand Down
14 changes: 7 additions & 7 deletions libtest/formatters/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ impl<T: Write> PrettyFormatter<T> {
word: &str,
color: term::color::Color,
) -> io::Result<()> {
match self.out {
OutputLocation::Pretty(ref mut term) => {
match &mut self.out {
OutputLocation::Pretty(term) => {
if self.use_color {
term.fg(color)?;
}
Expand All @@ -75,7 +75,7 @@ impl<T: Write> PrettyFormatter<T> {
}
term.flush()
}
OutputLocation::Raw(ref mut stdout) => {
OutputLocation::Raw(stdout) => {
stdout.write_all(word.as_bytes())?;
stdout.flush()
}
Expand All @@ -95,7 +95,7 @@ impl<T: Write> PrettyFormatter<T> {
self.write_plain("\nsuccesses:\n")?;
let mut successes = Vec::new();
let mut stdouts = String::new();
for &(ref f, ref stdout) in &state.not_failures {
for (f, stdout) in &state.not_failures {
successes.push(f.name.to_string());
if !stdout.is_empty() {
stdouts.push_str(&format!("---- {} stdout ----\n", f.name));
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<T: Write> PrettyFormatter<T> {
self.write_plain("\nfailures:\n")?;
let mut failures = Vec::new();
let mut fail_out = String::new();
for &(ref f, ref stdout) in &state.failures {
for (f, stdout) in &state.failures {
failures.push(f.name.to_string());
if !stdout.is_empty() {
fail_out.push_str(&format!("---- {} stdout ----\n", f.name));
Expand Down Expand Up @@ -182,14 +182,14 @@ impl<T: Write> OutputFormatter for PrettyFormatter<T> {
self.write_test_name(desc)?;
}

match *result {
match result {
TestResult::TrOk => self.write_ok(),
TestResult::TrFailed | TestResult::TrFailedMsg(_) => {
self.write_failed()
}
TestResult::TrIgnored => self.write_ignored(),
TestResult::TrAllowedFail => self.write_allowed_fail(),
TestResult::TrBench(ref bs) => {
TestResult::TrBench(bs) => {
self.write_bench()?;
self.write_plain(&format!(": {}\n", fmt_bench_samples(bs)))
}
Expand Down
14 changes: 7 additions & 7 deletions libtest/formatters/terse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl<T: Write> TerseFormatter<T> {
word: &str,
color: term::color::Color,
) -> io::Result<()> {
match self.out {
OutputLocation::Pretty(ref mut term) => {
match &mut self.out {
OutputLocation::Pretty(term) => {
if self.use_color {
term.fg(color)?;
}
Expand All @@ -87,7 +87,7 @@ impl<T: Write> TerseFormatter<T> {
}
term.flush()
}
OutputLocation::Raw(ref mut stdout) => {
OutputLocation::Raw(stdout) => {
stdout.write_all(word.as_bytes())?;
stdout.flush()
}
Expand All @@ -107,7 +107,7 @@ impl<T: Write> TerseFormatter<T> {
self.write_plain("\nsuccesses:\n")?;
let mut successes = Vec::new();
let mut stdouts = String::new();
for &(ref f, ref stdout) in &state.not_failures {
for (f, stdout) in &state.not_failures {
successes.push(f.name.to_string());
if !stdout.is_empty() {
stdouts.push_str(&format!("---- {} stdout ----\n", f.name));
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<T: Write> TerseFormatter<T> {
self.write_plain("\nfailures:\n")?;
let mut failures = Vec::new();
let mut fail_out = String::new();
for &(ref f, ref stdout) in &state.failures {
for (f, stdout) in &state.failures {
failures.push(f.name.to_string());
if !stdout.is_empty() {
fail_out.push_str(&format!("---- {} stdout ----\n", f.name));
Expand Down Expand Up @@ -193,14 +193,14 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
result: &TestResult,
_: &[u8],
) -> io::Result<()> {
match *result {
match result {
TestResult::TrOk => self.write_ok(),
TestResult::TrFailed | TestResult::TrFailedMsg(_) => {
self.write_failed()
}
TestResult::TrIgnored => self.write_ignored(),
TestResult::TrAllowedFail => self.write_allowed_fail(),
TestResult::TrBench(ref bs) => {
TestResult::TrBench(bs) => {
if self.is_multithreaded {
self.write_test_name(desc)?;
}
Expand Down
Loading