Skip to content

Commit

Permalink
conformance-tester: Print a summary after running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-hamester committed Oct 30, 2023
1 parent a85a99e commit 71ae2a1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
35 changes: 35 additions & 0 deletions conformance-tester/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,38 @@ pub fn finish_report(mut output: impl WriteColor, res: Result<Duration, RunError
writeln!(output)?;
Ok(())
}

pub fn summary(mut output: impl WriteColor, passed: usize, total: usize) -> Result<()> {
writeln!(output)?;

output.set_color(&STYLE_TEST_NAME)?;
write!(output, "Summary")?;
output.set_color(&STYLE_REGULAR)?;
writeln!(output, ":")?;

print_seperator(&mut output)?;
if passed > 0 {
output.set_color(&STYLE_PASSED)?;
write!(output, "passed")?;
output.set_color(&STYLE_REGULAR)?;
} else {
write!(output, "passed")?;
}
writeln!(output, ": {} test(s)", passed)?;

print_seperator(&mut output)?;
if (total - passed) > 0 {
output.set_color(&STYLE_FAILED)?;
write!(output, "failed")?;
output.set_color(&STYLE_REGULAR)?;
} else {
write!(output, "failed")?;
}
writeln!(output, ": {} test(s)", total - passed)?;

print_seperator(&mut output)?;
writeln!(output, "total: {} test(s)", total)?;

output.flush()?;
Ok(())
}
21 changes: 14 additions & 7 deletions conformance-tester/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ pub fn run(args: RunArgs, mut output: impl WriteColor, tests: Vec<Test>) -> Resu

let runtime = Runtime::new()?;
let mut queue: VecDeque<(String, _)> = VecDeque::with_capacity(jobs);
let mut at_least_one = false;
let mut all_passed = true;

let mut total = 0;
let mut passed = 0;

for test in tests.into_iter().filter(|test| args.filter.matches(test)) {
at_least_one = true;
total += 1;

if queue.len() >= jobs {
let (name, join) = queue.pop_front().unwrap();
all_passed &= report(&mut output, &name, join, &runtime)?;

if report(&mut output, &name, join, &runtime)? {
passed += 1;
}
}

let args = args.broker.clone();
Expand All @@ -43,11 +47,14 @@ pub fn run(args: RunArgs, mut output: impl WriteColor, tests: Vec<Test>) -> Resu
}

for (name, join) in queue {
all_passed &= report(&mut output, &name, join, &runtime)?;
if report(&mut output, &name, join, &runtime)? {
passed += 1;
}
}

if at_least_one {
Ok(all_passed)
if total > 0 {
output::summary(&mut output, passed, total)?;
Ok(passed == total)
} else {
println!("No test was selected by the supplied filters (-n,--name and -m,--message).");
Ok(false)
Expand Down

0 comments on commit 71ae2a1

Please sign in to comment.