-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Documentation test triggered without ``` #49717
Comments
Markdown code blocks are indicated by ``` or leading whitespace: http://spec.commonmark.org/0.28/#indented-code-blocks |
Thanks for the response. That's reasonable. It might be good to document this behavior at https://doc.rust-lang.org/stable/rustdoc/documentation-tests.html. It wasn't obvious to me that indented blocks are supposed to be treated as executable tests as opposed to generic code includes. It also seems inconsistent that the following are not considered tests:
|
Marking as t-doc; this just falls out of the markdown rules, but probably worth calling out anyway. |
I'm happy to mentor anyone who wants to fix this bug! Here's how: Modify the start of https://github.com/rust-lang/rust/blob/master/src/doc/rustdoc/src/documentation-tests.md to mention that the triple backticks is the most common way of writing a block of code, but Markdown also supports indenting four times. I'm happy to answer any additional questions! |
I’d like to take this on! @steveklabnik, do you think it’s worth linking to the CommonMark spec (linked above), or would that be out of scope for an introduction to doctests? |
I think that'd be great; in fact, we should probably link to it in general when talking about documentation, that's extra credit though :) |
I had a go at writing it in #51158. I thought adding a new section to the end would be better than adding another example at the start, to keep the introduction focussed. |
Mention spec and indented blocks in doctest docs Fixes rust-lang#49717. This commit adds a new section to the Documentation Test docs, which briefly mentions indented code blocks, and links to the CommonMark specification for both. I’m not sure about saying "fenced code blocks the more popular choice in the Rust community” because it seems like I’m speaking for everyone, but I can’t think of a better way to phrase it!
Mention spec and indented blocks in doctest docs Fixes rust-lang#49717. This commit adds a new section to the Documentation Test docs, which briefly mentions indented code blocks, and links to the CommonMark specification for both. I’m not sure about saying "fenced code blocks the more popular choice in the Rust community” because it seems like I’m speaking for everyone, but I can’t think of a better way to phrase it!
If you'd like to fix this bug, here's how!
The follow documentation comment is considered a documentation test. All of the Rust references I have read indicate ``` are needed to indicate a documentation test.
lib.rs
Then running
cargo test
gives the following output:The text was updated successfully, but these errors were encountered: