Open
Description
If a test writes to stdout on a thread created outside of Rust (e.g. directly via pthread_create
on Linux or CreateThread
on Windows), then that output will not be captured but will go straight to stdout when run with cargo test
. This is problematic for tests that need to run code on threads created by non-Rust components.
Repro:
#![cfg(test)]
#[test]
fn foo() {
unsafe {
let mut n = std::mem::zeroed();
assert_eq!(
0,
libc::pthread_create(&mut n, std::ptr::null(), print_thread, std::ptr::null_mut())
);
assert_eq!(0, libc::pthread_join(n, std::ptr::null_mut()));
}
}
extern "C" fn print_thread(_: *mut std::ffi::c_void) -> *mut std::ffi::c_void {
println!("should be captured");
std::ptr::null_mut()
}
Expected (output is captured):
Finished test [unoptimized + debuginfo] target(s) in 0.11s
Running unittests (target/debug/deps/repro-4d64f2a51a952b52)
running 1 test
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Actual (output is not captured):
Finished test [unoptimized + debuginfo] target(s) in 0.11s
Running unittests (target/debug/deps/repro-4d64f2a51a952b52)
running 1 test
should be captured
test foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Meta
rustc --version --verbose
:
rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-musl
release: 1.56.0
LLVM version: 13.0.0
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status