Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Have an option to output warnings from doctests #41574
Running cargo test runs doctests by default, and shows warnings for regular code, but not for the doctests themselves. This can be enabled by running cargo test -- --nocapture. I'd like to have warnings also show in our CI tests, even for doctests, but setting -- --nocapture shows all the output which we don't want (and can't control, because they come from the underlying libraries complaining about our tests that are supposed to fail).
I'd think having warnings on for doctests by default would be good, but that wouldn't be backwards compatible. Maybe a --doctest-warnings option could be added in lieu of that?
I believe this was done in 5d145c1, so discussion there might be worth reading. It seems that there are a bunch of warnings that come up with doctests that should be ignored, but there are also ones that can appear that shouldn't be. The question is how do we address both needs?
I've updated the title to better reflect what I think this request is, please correct it if I've misunderstood.
Many doc tests are small and would have warnings for unused variables, etc. I wouldn't want to see these by default, but I'd be ok with a flag to turn on just output of doc test warnings. I don't think I'd use it, but I wouldn't mind it being there.
Is there any way to get a sense of how many people would use this if it existed and the kinds of problems it would prevent, in order to prioritize this?
referenced this issue
May 1, 2017
added a commit
May 5, 2017
pushed a commit
Aug 11, 2017
referenced this issue
Mar 15, 2018
I'm digging into this CLI flag for #49028 and i'm struggling to figure out whether it's useful now. From digging into the implementation that remains, i can find two major features for it:
However, neither one is that useful, because for the first, you can just provide
So here's the results of my testing that led me to this conclusion, and i want to know whether this flag is worth keeping, or whether we need to file additional bugs that can be worked on.
#![crate_type = "lib"] #![doc(test(attr(warn(warnings))))] // suppress the default allow(unused) /// (written on a spider's web) Some Struct /// /// ``` /// let x = 5; /// println!("sup"); /// ``` pub struct SomeStruct; struct OtherStruct; // emit a warning when compiling
console output for various interactions with this rust file
$ rustdoc +nightly --version rustdoc 1.26.0-nightly (392645394 2018-03-15) $ rustc +nightly g.rs warning: struct is never used: `OtherStruct` --> g.rs:12:1 | 12 | struct OtherStruct; | ^^^^^^^^^^^^^^^^^^^ | = note: #[warn(dead_code)] on by default $ rustdoc +nightly g.rs (no output) $ rustdoc +nightly g.rs -Z unstable-options --display-warnings (no output) $ rustdoc +nightly --test g.rs running 1 test test g.rs - SomeStruct (line 6) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out $ rustdoc +nightly --test g.rs -Z unstable-options --display-warnings running 1 test test g.rs - SomeStruct (line 6) ... ok successes: ---- g.rs - SomeStruct (line 6) stdout ---- warning: unused variable: `x` --> g.rs:7:5 | 3 | let x = 5; | ^ help: consider using `_x` instead | = note: #[warn(unused_variables)] on by default successes: g.rs - SomeStruct (line 6) test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out $ rustdoc +nightly --test g.rs --test-args "--nocapture" running 1 test warning: unused variable: `x` --> g.rs:7:5 | 3 | let x = 5; | ^ help: consider using `_x` instead | = note: #[warn(unused_variables)] on by default test g.rs - SomeStruct (line 6) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out