Add --scrape-tests option to rustdoc to scrape functions marked #[test] by willcrichton · Pull Request #93497 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation27 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

willcrichton

@rustbot rustbot added the T-rustdoc

Relevant to the rustdoc team, which will review and decide on the PR/issue.

label

Jan 31, 2022

This was referenced

Jan 31, 2022

@GuillaumeGomez

In my opinion it's not necessarily the "right" usage. In tests you use items in order to make sure they work under any circumstance. Not sure if it's good to be used as an example.

@willcrichton

In my opinion it's not necessarily the "right" usage. In tests you use items in order to make sure they work under any circumstance. Not sure if it's good to be used as an example.

Note that this PR makes it possible for Rustdoc to scrape examples from tests. The proposed default is still that only examples and library code are used. But this way if someone wants to include tests as examples, then they can. That decision is left to the library author.

@GuillaumeGomez

I stand on my position by if it's not enabled by default, then let's say I'm neutral.

@camelid

I thought scrape-examples only works on examples/? Aren't #[test] functions usually in the crate itself?

@GuillaumeGomez

They can be inside the crate source code and in their own folder.

@willcrichton

Examples can theoretically be scraped from any source file in your Cargo workspace. The default is just the examples/ directory.

@camelid

Oh, so scrape-examples already supports scraping e.g. library source code if you tell it to?

@willcrichton

@willcrichton

If there are no other objections to this PR, it would be good to get it merged so I can get tests passing on rust-lang/cargo#10343.

@GuillaumeGomez

This is quite an extension so I'd prefer to have everyone on the team agreeing with it first.

cc @rust-lang/rustdoc

@notriddle

I support this PR. A crate might be intended for use in test cases, so it makes sense to have example code that uses #[test], and you ought to be able up scrape it.

If other words, I think being example code and being test code are orthogonal.

@GuillaumeGomez

I don't agree with your point of view but I agree on the fact that users should be able to include their tests into the "scraped examples". For me, tests are meant to check that your code works whereas examples are meant to show how to use your API.

@camelid

Maybe this should be a different flag, e.g. --include-tests? --test is used to run tests, but AFAICT this PR makes it so it's also used when building docs? That seems wrong.

@willcrichton

This PR only affects the case where the user is scraping examples, not the general documentation code paths. But I can create a new flag if you like.

@camelid

This PR only affects the case where the user is scraping examples, not the general documentation code paths. But I can create a new flag if you like.

Yeah, using the flag seems confusing to me.

@camelid

Could you squash your commits btw?

@willcrichton

@camelid camelid changed the titlePass --test flag through rustdoc to rustc so #[test] functions can be scraped Pass --test flag through rustdoc to rustc so #[test] functions can be scraped

Feb 11, 2022

@camelid

Just noting that now that it's a new unstable flag, an FCP shouldn't be necessary.

@willcrichton

@willcrichton

I just added some documentation for the flag as well.

GuillaumeGomez

@GuillaumeGomez

Looks good to me now, thanks!

@willcrichton

@GuillaumeGomez

I'm waiting for one last review from @camelid. If they don't see anything else, then let's r+. :)

@camelid

As long as this PR only adds behavior behind a new unstable flag, I have no objections.

@GuillaumeGomez

@bors

📌 Commit fbbcb08 has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Feb 18, 2022

bors added a commit to rust-lang-ci/rust that referenced this pull request

Feb 19, 2022

@bors

…askrgr

Rollup of 10 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

@camelid

Note

This PR's title is actually inaccurate since the contents changed after creation. It actually adds a new unstable flag and doesn't change the existing --test flag's behavior.

@GuillaumeGomez GuillaumeGomez changed the titlePass --test flag through rustdoc to rustc so #[test] functions can be scraped Add --scrape-tests option to rustdoc to scrape functions marked #[test]

Feb 20, 2022

@GuillaumeGomez

Good point. I updated the title.

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-rustdoc

Relevant to the rustdoc team, which will review and decide on the PR/issue.