Skip to content

Unexpected doc errors when using --nocapture and compile_fail #55813

Open
@gliderkite

Description

@gliderkite

Problem
cargo test -- --nocapture outputs error logs for documentation tests even when specifying the compile_fail argument.

Steps

  1. Create a new project with cargo new <project name>
  2. Add a lib.rs file to src
  3. Add the following method with documentation and code example which is supposed to fail compilation (the section code will contain invalid Rust code):
/// ```compile_fail
/// Input: 123
/// ```
pub fn foo() {
}
  1. Run cargo test -- --nocapture

The output will be:

Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running target/debug/deps/compile_fail-af4564015b61948e

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

 Running target/debug/deps/compile_fail-8c19ede40c69c8ad

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Doc-tests compile-fail

running 1 test
error: expected type, found 123
--> src/lib.rs:2:8
|
3 | Input: 123
| ^^^ expecting a type here because of type ascription

test src/lib.rs - foo (line 1) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Notes

Running cargo test presents a different output with no errors:

Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running target/debug/deps/compile_fail-af4564015b61948e

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

 Running target/debug/deps/compile_fail-8c19ede40c69c8ad

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Doc-tests compile-fail

running 1 test
test src/lib.rs - foo (line 1) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Output of cargo version:

cargo 1.30.0 (36d96825d 2018-10-24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.T-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