Skip to content
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

Closed
benhansen-io opened this issue Apr 6, 2018 · 7 comments
Closed

Documentation test triggered without ``` #49717

benhansen-io opened this issue Apr 6, 2018 · 7 comments
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority

Comments

@benhansen-io
Copy link

benhansen-io commented Apr 6, 2018

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

///                   
///     a             
/// b                 
pub fn some_lib_fn() {
                  
} 

Then running cargo test gives the following output:

 running 0 tests                                                                   
                                                                                   
 test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out        
                                                                                   
    Doc-tests reproduce-doc-test                                                   
                                                                                   
 running 1 test                                                                    
 test src/lib.rs - some_lib_fn (line 1) ... FAILED                                 
                                                                                   
 failures:                                                                         
                                                                                   
 ---- src/lib.rs - some_lib_fn (line 1) stdout ----                                
         error[E0425]: cannot find value `a` in this scope                         
  --> src/lib.rs:2:1                                                               
   |                                                                               
 3 | a                                                                             
   | ^ not found in this scope                                                     
                                                                                   
 thread 'rustc' panicked at 'couldn't compile the test', librustdoc/test.rs:298:13 
 note: Run with `RUST_BACKTRACE=1` for a backtrace.                                
                                                                                   
                                                                                   
 failures:                                                                         
     src/lib.rs - some_lib_fn (line 1)                                             
                                                                                   
 test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out    
                                                                                   
 error: test failed, to rerun pass '--doc'                                         
@sfackler
Copy link
Member

sfackler commented Apr 6, 2018

Markdown code blocks are indicated by ``` or leading whitespace: http://spec.commonmark.org/0.28/#indented-code-blocks

@benhansen-io
Copy link
Author

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:

///               
///     a         
///               
pub fn some_fn() {
                  
}

///               
///     a         
pub fn some_fn() {
}

@steveklabnik steveklabnik added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Apr 6, 2018
@steveklabnik
Copy link
Member

Marking as t-doc; this just falls out of the markdown rules, but probably worth calling out anyway.

@steveklabnik steveklabnik added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. P-medium Medium priority E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels May 28, 2018
@steveklabnik
Copy link
Member

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!

@ogham
Copy link
Contributor

ogham commented May 29, 2018

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?

@steveklabnik
Copy link
Member

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 :)

@ogham
Copy link
Contributor

ogham commented May 29, 2018

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.

kennytm added a commit to kennytm/rust that referenced this issue May 30, 2018
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!
kennytm added a commit to kennytm/rust that referenced this issue Jun 22, 2018
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!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

4 participants