Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test output capture does not capture Command output #92370

Open
jonhoo opened this issue Dec 28, 2021 · 0 comments
Open

Test output capture does not capture Command output #92370

jonhoo opened this issue Dec 28, 2021 · 0 comments
Labels
A-libtest Area: `#[test]` / the `test` library C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Dec 28, 2021

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:

fn print_to<T>(args: fmt::Arguments<'_>, global_s: fn() -> T, label: &str)

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.

@jonhoo jonhoo added the C-bug Category: This is a bug. label Dec 28, 2021
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-libtest Area: `#[test]` / the `test` library and removed needs-triage-legacy labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: `#[test]` / the `test` library C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

3 participants