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

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

Open
gliderkite opened this issue Nov 8, 2018 · 2 comments
Open

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

gliderkite opened this issue Nov 8, 2018 · 2 comments
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@gliderkite
Copy link

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)

@alexcrichton alexcrichton transferred this issue from rust-lang/cargo Nov 9, 2018
@alexcrichton alexcrichton added the A-doctests Area: Documentation tests, run by rustdoc label Nov 9, 2018
@alexcrichton
Copy link
Member

Thanks for the report! I've transferred this to the rust-lang/rust repository as this looks like it's a bug with rustdoc rather than Cargo.

This can be reproduced with the following:

/// ```compile_fail
/// Input: 123
/// ```
pub fn foo() {
}

executed with:

$ rustdoc --test foo.rs --test-args --nocapture

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

test foo.rs - foo (line 1) ... ok

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

@woshilapin
Copy link
Contributor

As I was browsing issues (what a nice hobby!) looking for something else, I went through another issue #26309 that might be related. I'm just pointing to it, it might help to whoever is gonna work on this.

@camelid camelid added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

4 participants