Skip to content

rustdoc: passing --nocapture to the test runner still captures (and hides) test output #98550

Open
@RalfJung

Description

@RalfJung

I originally reported this against cargo at rust-lang/cargo#10792, but was told this is more of a rustdoc problem.

The goal is that when I have a diverging doctest, like the following silly one:

/// ```rust
/// eprintln!("stderr");
/// println!("stdout");
/// loop {}
/// ```
pub fn uwu() {}

Then I want to be able to use cargo test --doc -- --nocapture to debug what is going on by seeing the output of the test. But that doesn't happen, output is still captured. --nocapture seems to only control whether the output of rustc as it builds the test is captured or printed; it has no effect on the stdout/stderr of the test itself. That is quite inconsistent with regular unit tests where it controls the output of the test itself.

Instead I have to do RUSTDOCFLAGS="-Zunstable-options --nocapture" cargo test --doc, which is rather hard to find.

To make things even more surprising, RUSTDOCFLAGS="-Zunstable-options --nocapture" cargo test --doc -- --nocapture fails with an error: "Option 'nocapture' given more than once".

Cc @rust-lang/rustdoc

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions