Skip to content

Commit 14782ad

Browse files
Add new test_main_with_exit_callback public function in libtest to allow a callback to be called before exiting
1 parent 651e9cf commit 14782ad

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/test/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ const SECONDARY_TEST_BENCH_BENCHMARKS_VAR: &str = "__RUST_TEST_BENCH_BENCHMARKS"
9898
// The default console test runner. It accepts the command line
9999
// arguments and a vector of test_descs.
100100
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Option<Options>) {
101+
test_main_with_exit_callback(args, tests, options, || {})
102+
}
103+
104+
pub fn test_main_with_exit_callback<F: FnOnce()>(
105+
args: &[String],
106+
tests: Vec<TestDescAndFn>,
107+
options: Option<Options>,
108+
exit_callback: F,
109+
) {
101110
let mut opts = match cli::parse_opts(args) {
102111
Some(Ok(o)) => o,
103112
Some(Err(msg)) => {
@@ -151,6 +160,7 @@ pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Option<Opt
151160
let res = console::run_tests_console(&opts, tests);
152161
// Prevent Valgrind from reporting reachable blocks in users' unit tests.
153162
drop(panic::take_hook());
163+
exit_callback();
154164
match res {
155165
Ok(true) => {}
156166
Ok(false) => process::exit(ERROR_EXIT_CODE),

0 commit comments

Comments
 (0)