Skip to content

Commit

Permalink
Deduplicate success and failure path
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 21, 2024
1 parent f25efb8 commit 5158d79
Showing 1 changed file with 45 additions and 57 deletions.
102 changes: 45 additions & 57 deletions src/status_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl StatusEmitter for Text {

fn finalize(
&self,
failures: usize,
_failures: usize,
succeeded: usize,
ignored: usize,
filtered: usize,
Expand All @@ -428,76 +428,64 @@ impl StatusEmitter for Text {
println!();
}
// Print all errors in a single thread to show reliable output
if failures == 0 {
println!();
print!("test result: {}.", "ok".green());
if succeeded > 0 {
print!(" {} passed;", succeeded.to_string().green());
}
if ignored > 0 {
print!(" {} ignored;", ignored.to_string().yellow());
}
if filtered > 0 {
print!(" {} filtered out;", filtered.to_string().yellow());
}
println!();
println!();
Box::new(())
} else {
struct Summarizer {
failures: Vec<String>,
succeeded: usize,
ignored: usize,
filtered: usize,
}

impl Summary for Summarizer {
fn test_failure(&mut self, status: &dyn TestStatus, errors: &Errors) {
for error in errors {
print_error(error, status.path());
}
struct Summarizer {
failures: Vec<String>,
succeeded: usize,
ignored: usize,
filtered: usize,
}

self.failures.push(if status.revision().is_empty() {
format!(" {}", status.path().display())
} else {
format!(
" {} (revision {})",
status.path().display(),
status.revision()
)
});
impl Summary for Summarizer {
fn test_failure(&mut self, status: &dyn TestStatus, errors: &Errors) {
for error in errors {
print_error(error, status.path());
}

self.failures.push(if status.revision().is_empty() {
format!(" {}", status.path().display())
} else {
format!(
" {} (revision {})",
status.path().display(),
status.revision()
)
});
}
}

impl Drop for Summarizer {
fn drop(&mut self) {
impl Drop for Summarizer {
fn drop(&mut self) {
if self.failures.is_empty() {
println!();
print!("test result: {}.", "ok".green());
} else {
println!("{}", "FAILURES:".bright_red().underline().bold());
for line in &self.failures {
println!("{line}");
}
println!();
print!("test result: {}.", "FAIL".bright_red());
print!(" {} failed;", self.failures.len().to_string().green());
if self.succeeded > 0 {
print!(" {} passed;", self.succeeded.to_string().green());
}
if self.ignored > 0 {
print!(" {} ignored;", self.ignored.to_string().yellow());
}
if self.filtered > 0 {
print!(" {} filtered out;", self.filtered.to_string().yellow());
}
println!();
println!();
}
if self.succeeded > 0 {
print!(" {} passed;", self.succeeded.to_string().green());
}
if self.ignored > 0 {
print!(" {} ignored;", self.ignored.to_string().yellow());
}
if self.filtered > 0 {
print!(" {} filtered out;", self.filtered.to_string().yellow());
}
println!();
println!();
}
Box::new(Summarizer {
failures: vec![],
succeeded,
ignored,
filtered,
})
}
Box::new(Summarizer {
failures: vec![],
succeeded,
ignored,
filtered,
})
}
}

Expand Down

0 comments on commit 5158d79

Please sign in to comment.