From 14782ad6874b768ce208f76a6998e2175ffce755 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 6 May 2025 18:17:48 +0200 Subject: [PATCH] Add new `test_main_with_exit_callback` public function in `libtest` to allow a callback to be called before exiting --- library/test/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index acaf026c679b..7f56d1e36269 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -98,6 +98,15 @@ const SECONDARY_TEST_BENCH_BENCHMARKS_VAR: &str = "__RUST_TEST_BENCH_BENCHMARKS" // The default console test runner. It accepts the command line // arguments and a vector of test_descs. pub fn test_main(args: &[String], tests: Vec, options: Option) { + test_main_with_exit_callback(args, tests, options, || {}) +} + +pub fn test_main_with_exit_callback( + args: &[String], + tests: Vec, + options: Option, + exit_callback: F, +) { let mut opts = match cli::parse_opts(args) { Some(Ok(o)) => o, Some(Err(msg)) => { @@ -151,6 +160,7 @@ pub fn test_main(args: &[String], tests: Vec, options: Option {} Ok(false) => process::exit(ERROR_EXIT_CODE),