From 74a3512038a1ddb00b9033f330059c983a8a4e73 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 14 Oct 2023 17:38:53 -0400 Subject: [PATCH] Report whether all the tests passed. --- src/bin_foreign_document_test.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/bin_foreign_document_test.rs b/src/bin_foreign_document_test.rs index c9477efd..ad9665c1 100644 --- a/src/bin_foreign_document_test.rs +++ b/src/bin_foreign_document_test.rs @@ -2,6 +2,7 @@ #![feature(exact_size_is_empty)] use std::path::Path; use std::path::PathBuf; +use std::process::ExitCode; use futures::future::BoxFuture; use futures::future::FutureExt; @@ -18,7 +19,7 @@ use crate::init_tracing::shutdown_telemetry; mod init_tracing; #[cfg(not(feature = "tracing"))] -fn main() -> Result<(), Box> { +fn main() -> Result> { let rt = tokio::runtime::Runtime::new()?; let result = rt.block_on(async { let main_body_result = main_body().await; @@ -28,7 +29,7 @@ fn main() -> Result<(), Box> { } #[cfg(feature = "tracing")] -fn main() -> Result<(), Box> { +fn main() -> Result> { let rt = tokio::runtime::Runtime::new()?; let result = rt.block_on(async { init_telemetry()?; @@ -40,7 +41,7 @@ fn main() -> Result<(), Box> { } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] -async fn main_body() -> Result<(), Box> { +async fn main_body() -> Result> { let layer = compare_group("org-mode", || { compare_all_org_document("/foreign_documents/org-mode") }); @@ -56,12 +57,30 @@ async fn main_body() -> Result<(), Box> { })); let running_tests: Vec<_> = layer.map(|c| tokio::spawn(c.run_test())).collect(); + let mut any_failed = false; for test in running_tests.into_iter() { let test_result = test.await??; + if test_result.is_immediately_bad() || test_result.has_bad_children() { + any_failed = true; + } test_result.print(); } - Ok(()) + if any_failed { + println!( + "{color}Some tests failed.{reset}", + color = TestResult::foreground_color(255, 0, 0), + reset = TestResult::reset_color(), + ); + Ok(ExitCode::FAILURE) + } else { + println!( + "{color}All tests passed.{reset}", + color = TestResult::foreground_color(0, 255, 0), + reset = TestResult::reset_color(), + ); + Ok(ExitCode::SUCCESS) + } } fn compare_howard_abrams() -> impl Iterator {