-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Run rustdoc tests #3206
Comments
Indeed doc tests do not run when cross compiling (which is what happens when running the coverage): rust-lang/rust#64245 (tho it s good to also have an issue on our side). |
Since we switched to I would vote for closing this issue, because there's nothing really to be done on our side, wdyt? |
Rustdoc tests do not appear to run when under For example the function under the /// Macro for defining `impl Display for BitMut`.
macro_rules! bit_mut_display {
($x:ty) => {
impl<const P: u8> std::fmt::Display for BitMut<'_, $x, P> {
#[doc = concat!("
```
use bit_fields::BitMut;
let mut x = 5", stringify!($x), ";
assert_eq!(BitMut::<_,0>(&mut x).to_string(),true.to_string());
assert_eq!(BitMut::<_,1>(&mut x).to_string(),false.to_string());
assert_eq!(BitMut::<_,2>(&mut x).to_string(),true.to_string());
```
")]
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", bool::from(self))
}
}
};
} |
I think what we want is just to make sure the doc tests are run (i.e they compile) and not necessarily to include them in coverage (we write unit tests for that). And as far as my investigation, this cargo test line here does seem to run them. If you print the stderr of that line you will get:
|
I believe this is the issue relating to doc-tests coverage not working correctly rust-lang/rust#79417. A specific case is with macros that generate functionality, the best approach to effectively test these is with doc-tests. I think coverage from doc-tests is important, I would argue doc-tests are preferable to unit tests as they act as both unit tests and documentation. |
that issue is about coverage of the actual doc test lines (e.g. the lines inside of a doc comment) - so not what we want. I have definitely seen coverage from doc tests being included in our coverage reports, so this seems to be an issue with our CI. Maybe some profraw files aren't picked up by the grcov invocation?
there is a performance component to consider here: each doc test is its own compilation unit, see rust-lang/rust#75341 which seems to suggest an up to 30x speed degradation of running identical testing work load in doctests vs unit tests. |
We are running coverage with the |
Running
test_coverage.py
does not take into account doc tests in the coverage,cargo test
does not run them.Using
sudo ./tools/devtool shell -p
and runningcargo test
also ignores doc tests.Both
and
exclude execution of rustdoc tests.
In addition this excludes rustdoc tests from code coverage (https://doc.rust-lang.org/rustc/instrument-coverage.html#including-doc-tests).
Blocked on: rust-lang/rust#56925
The text was updated successfully, but these errors were encountered: