about summary refs log tree commit diff
path: root/library/test
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-06 18:17:48 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-06 18:17:48 +0200
commit14782ad6874b768ce208f76a6998e2175ffce755 (patch)
treebeab12f960a0c5a3925716f0042c61fade9489e5 /library/test
parent651e9cf327358b28db7e37a2ae61727f4a2ef232 (diff)
downloadrust-14782ad6874b768ce208f76a6998e2175ffce755.tar.gz
rust-14782ad6874b768ce208f76a6998e2175ffce755.zip
Add new `test_main_with_exit_callback` public function in `libtest` to allow a callback to be called before exiting
Diffstat (limited to 'library/test')
-rw-r--r--library/test/src/lib.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs
index acaf026c679..7f56d1e3626 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<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),