-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Doctests don't work in bin targets #5477
Comments
This is a limitation of rustdoc, it can't run doctests over binaries. |
Could this limitation be addressed? I elaborated a bit why I consider this important over in the users forum. |
Heh everything can be addressed with enough elbow grease! It's a matter of design and problem solving now moreso than "let's fix the accidental omission" |
I wasn't sure if your comment was meant in a "works as intended" or "it has to be like that" way so I wanted to add a bit more background info. The issue description isn't 100% on point. /// ```rust
/// assert!(false);
/// ```
fn foo() {
println!("Hello, world!");
} In the code above rustdoc won't execute the doctest, neither in case of In case of |
Indeed that is correct! It may be best to discuss this at rust-lang/rust rather than Cargo, as this is all mostly remnants of rustdoc itself |
If it is tricky to get
to execute always, maybe it can warn about it instead? Like "This doctest is not expected to be executed because of {it is a non-library crate, not a public item}". |
Moved issue to: rust-lang/rust#50784 |
@kornelski this is now supported in rustdoc: rust-lang/rust#50784 (comment) |
Is this issue blocked by anything or there's just no spare hands to fix it? Will you accept PR? |
@kriomant Looking at rust-lang/rust#50784, it looks like this is all in cargo's court and that we have most of the tools in place for this. I've gone ahead and marked this as "needs mentor". That doesn't mean this can't be worked on but that you likely won't be able to get much help from the cargo team. For me, the main question is what happens today if you have a failing doctest in a bin and then upgrade (ie |
I'm still skeptical that it would be a good idea to move forward with this as-is. As mentioned in rust-lang/rust#50784 (comment), doctests would not have access to any of the symbols within the binary, and thus would only be able to show illustrations from a corresponding lib target. Since I suspect that is not what most people will expect it to do, I think it could add to confusion about things not working. |
Thanks for pointing out your comment! I missed that! |
It could still be useful to be able to run doctests for documentation in integration tests. |
This is also tracked in rust-lang/testing-devex-team#5 (comment). |
It's surprising that doctests don't work binary targets:
cargo test --all
I'd expect the above to fail, but it looks like the doc-comment code is never ran. Even if I explicitly enable doctests for the binary:
they still aren't run.
The text was updated successfully, but these errors were encountered: