Description
I tried this code:
#[test]
fn foo() {
println!("hello");
std::process::Command::new("echo").arg("world").status().unwrap();
}
I expected to see this happen: nothing should be printed to STDOUT for cargo test
, while "hello" and "world" should be printed to STDOUT with cargo test -- --nocapture
.
Instead, this happened: "world" is always printed to STDOUT (playground).
Meta
rustc --version --verbose
:
rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-apple-darwin
release: 1.57.0
LLVM version: 13.0.0
The issue also occurs on nightly.
Notes
This happens because the output capture hook used by libtest only affects things that go through print_to
:
rust/library/std/src/io/stdio.rs
Line 1167 in 442248d
It's already known that libtest output capturing has some... inconsistencies (e.g., #12309, #90785, #35136), but in this particular case I wonder if it's possible to do something about it since std
controls the defaults for Command
. Specifically, it might make sense to have Command
default to a capturing .stdout
and .stderr
when those aren't overwritten in the builder.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status