-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Cargo test interprets symbols from functions' documentation #10465
Comments
Link issue: rust-lang/cargo#10465 Signed-off-by: Violeta Kabadzhova <vkabadzhova@gmail.com>
This is normal behavior for documentation tests. When there is a code block in a doc comment, There are various ways to work around this. It looks like you are writing some diagrams. One approach is to mark that as a text block:
I'm going to close in favor of these issues: |
Thanks for the report. I believe it is an expected result. The content of a doc comment must also be a valid markdown. It will then be parsed by rustdoc to build HTML doc and run doctest. Since indented code blocks are also valid code blocks, they will then be run as doctests. That's why Here is another minimal example that also makes doctest fail. /// Indentation with 4 spaces -> code block
///
/// 1 + 1
pub fn test() {
assert!(false);
} To avoid this behavior, I recommend fencing your text with three backticks a.k.a. fenced code blocks, such like: /// You doc comment
///
/// ```text
/// ^ ascii art
/// ``` |
Oops. A race condition with @ehuss 😆 |
Thank you @ehuss and @weihanglo for the answers. |
Problem
When running the
cargo test
command, I receive some errors after the tests have already finished indicating success.However, the indicated symbols (the "^") I have used nowhere but the code documentation. If I remove them, the problem disappears:

Steps
cargo t
(tests that pass)The function of question is located in a public struct which is in src/some-directory/file.rs
Possible Solution(s)
I tend to think it interprets those symbols wrongly, since I would be surprised if
cargo t
should anyhow intervene with the functions' documentation.Notes
Note:
cargo t
works as expected in the following cases:[3 spaces] /// new vector which [5 spaces] |^
[some spaces] ///[some spaces]^
But it fails in the following case:
///[14 spaces]^
Version
The text was updated successfully, but these errors were encountered: