From 71ae2a12720af6927816aeccf276d63ea4cc165a Mon Sep 17 00:00:00 2001 From: Dennis Hamester Date: Mon, 30 Oct 2023 09:52:20 +0100 Subject: [PATCH] conformance-tester: Print a summary after running tests --- conformance-tester/src/output.rs | 35 ++++++++++++++++++++++++++++++++ conformance-tester/src/run.rs | 21 ++++++++++++------- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/conformance-tester/src/output.rs b/conformance-tester/src/output.rs index 22d2332a0..9b058e8e4 100644 --- a/conformance-tester/src/output.rs +++ b/conformance-tester/src/output.rs @@ -182,3 +182,38 @@ pub fn finish_report(mut output: impl WriteColor, res: Result 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(()) +} diff --git a/conformance-tester/src/run.rs b/conformance-tester/src/run.rs index 9079e1cc6..48973b55d 100644 --- a/conformance-tester/src/run.rs +++ b/conformance-tester/src/run.rs @@ -24,15 +24,19 @@ pub fn run(args: RunArgs, mut output: impl WriteColor, tests: Vec) -> 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(); @@ -43,11 +47,14 @@ pub fn run(args: RunArgs, mut output: impl WriteColor, tests: Vec) -> 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)