Add new `test_main_with_exit_callback` public function in `libtest` to allow a callback to be called before exiting
diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs
index acaf026..7f56d1e 100644
--- a/library/test/src/lib.rs
+++ b/library/test/src/lib.rs
@@ -98,6 +98,15 @@ pub mod test {
// 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<TestDescAndFn>, options: Option<Options>) {
+ test_main_with_exit_callback(args, tests, options, || {})
+}
+
+pub fn test_main_with_exit_callback<F: FnOnce()>(
+ args: &[String],
+ tests: Vec<TestDescAndFn>,
+ options: Option<Options>,
+ 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<TestDescAndFn>, options: Option<Opt
let res = console::run_tests_console(&opts, tests);
// Prevent Valgrind from reporting reachable blocks in users' unit tests.
drop(panic::take_hook());
+ exit_callback();
match res {
Ok(true) => {}
Ok(false) => process::exit(ERROR_EXIT_CODE),