diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2024-05-22 14:16:33 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2024-11-19 18:54:20 +0100 |
| commit | ef9055f3eef409e99e1e786f6a90a1684fde810d (patch) | |
| tree | 83c68e06b52891d7dad7355fe9d263eec013ab16 /library/test | |
| parent | 7ac4c04731ecb6eedd63a1f899a0c6207679cbf9 (diff) | |
| download | rust-ef9055f3eef409e99e1e786f6a90a1684fde810d.tar.gz rust-ef9055f3eef409e99e1e786f6a90a1684fde810d.zip | |
Use add_spawn_hook for libtest's output capturing.
Diffstat (limited to 'library/test')
| -rw-r--r-- | library/test/src/lib.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 30ccfe2af8d..00a0b55c6a9 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -24,6 +24,7 @@ #![feature(process_exitcode_internals)] #![feature(panic_can_unwind)] #![feature(test)] +#![feature(thread_spawn_hook)] #![allow(internal_features)] #![warn(rustdoc::unescaped_backticks)] @@ -134,6 +135,16 @@ pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Option<Opt } }); panic::set_hook(hook); + // Use a thread spawning hook to make new threads inherit output capturing. + std::thread::add_spawn_hook(|_| { + // Get and clone the output capture of the current thread. + let output_capture = io::set_output_capture(None); + io::set_output_capture(output_capture.clone()); + // Set the output capture of the new thread. + Ok(|| { + io::set_output_capture(output_capture); + }) + }); } let res = console::run_tests_console(&opts, tests); // Prevent Valgrind from reporting reachable blocks in users' unit tests. |
