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

rustdoc: Add an attribute to ignore collecting tests per-item. #38825

Closed
wants to merge 1 commit into from

Conversation

emilio
Copy link
Contributor

@emilio emilio commented Jan 4, 2017

This allows to ignore tests in modules we know they have uneffective tests, or
tests not under our control, like for example in:

rust-lang/rust-bindgen#378

r? @alexcrichton

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@@ -651,6 +651,15 @@ through the `#![doc(test(..))]` attribute.
This allows unused variables within the examples, but will fail the test for any
other lint warning thrown.

You can also ignore tests under a given item and that item inclussive with:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"inclussive"? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, I don't know how to write, amended, thanks :)

@GuillaumeGomez
Copy link
Member

It's awesome! Thanks a lot for this!

This allows to ignore tests in modules we know they have uneffective tests, or
tests not under our control, like for example in:

rust-lang/rust-bindgen#378

Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
@emilio
Copy link
Contributor Author

emilio commented Jan 10, 2017

Ping?

@GuillaumeGomez
Copy link
Member

Since it touches rustdoc source code, I'd prefer to have @rust-lang/tools confirmation first. Let's wait for them to take a look.

@alexcrichton
Copy link
Member

@emilio could you expand on the motivation for this? I was under the assumption that ignore annotations or such on markdown blocks would be sufficient?

I'd also want to consider the impact of syntax highlighting here as well. I think rustdoc interprets blocks by default as Rust code, so it seems like an attribute would be inevitably needed anyway to turn that off?

@emilio
Copy link
Contributor Author

emilio commented Jan 10, 2017

The motivation is that, in bindgen, we don't have control of those markdown blocks, because they belong to third-party libraries.

Mainly, consider a C library that defines the following:

/**
 * This function does something really impressive.
 *
 * Example usage:
 *
 * ```
 * int main() {
 *     do_foo();
 * }
 * ```
 */
void do_foo();

Bindgen tries to preserve documentation, and thus the generate code looks like:

extern "C" {
    /**
     * This function does something really impressive.
     *
     * Example usage:
     *
     * ```
     * int main() {
     *     do_foo();
     * }
     * ```
     */
    pub fn do_foo();
}

Running doctests in this crate obviously fails (because the code in the doc block is not valid rust).

We can solve it downstream processing comments (trying to add ignore annotations) and whatnot, but I think this solution is more elegant.

@alexcrichton
Copy link
Member

It seems like this would always be a bug in bindgen? This doesn't really fix the problem because we'll still syntax highlight the foreign blocks copied in as Rust, and possibly error out entirely if they're invalid Rust.

@emilio
Copy link
Contributor Author

emilio commented Jan 11, 2017

Well, this at least allows running cargo test without failures in a bindgen-generated crate. That has been the only reported error so far. If there's any other, like broken syntax highlighting, probably more checks should be added to prevent this, but I think an attribute that says "please don't make any assumptions about the doc blocks in this module" is helpful.

@alexcrichton
Copy link
Member

My point is basically that this is not a complete bug fix. Just because a bug hasn't been reported against bindgen doesn't mean that it shouldn't be fixed. A solution for both of these problems (testing everything and not assuming rust) may look similar. For example bindgen could avoid copying markdown blocks or modify markdown blocks. Similarly rustdoc could have one attribute to control this.

Designing only one solution without considering the other runs a risk of leaving us with a feature in rustdoc we never had in the first place

@alexcrichton
Copy link
Member

cc @rust-lang/docs, perhaps y'all've got more thoughts?

@emilio
Copy link
Contributor Author

emilio commented Jan 18, 2017 via email

@frewsxcv
Copy link
Member

I think I'm -1 on this. It's not obvious to me that the compiler should support this use case. To me, it seems like bindgen is doing the wrong thing here.

Documentation code blocks without a specified programming language are assumed to be Rust and will be syntax highlighted as so. Won't syntax highlighting also be a problem for these code blocks?

@emilio
Copy link
Contributor Author

emilio commented Jan 19, 2017

Read above, this is not a problem because rustdoc happily skips it if it can't parse it as rust, but I suggest above I could also do the check there if need be.

@alexcrichton
Copy link
Member

@emilio I'm not personally convinced by that aspect. If foreign code just happens to lex as Rust code then we still shouldn't highlight it as Rust?

@bors
Copy link
Contributor

bors commented Feb 15, 2017

☔ The latest upstream changes (presumably #39633) made this pull request unmergeable. Please resolve the merge conflicts.

@emilio
Copy link
Contributor Author

emilio commented Feb 15, 2017

I guess, though I'd assume that's uncommon enough. Anyway, we're going to need to process those anyway it seems, if only to avoid rust compile errors when others use /*! style comments, so this is no longer saving us any work.

Thanks for all the feedback! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants