-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add --scrape-tests
option to rustdoc to scrape functions marked #[test]
#93497
Conversation
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. |
I stand on my position by if it's not enabled by default, then let's say I'm neutral. |
I thought scrape-examples only works on |
They can be inside the crate source code and in their own folder. |
Examples can theoretically be scraped from any source file in your Cargo workspace. The default is just the |
Oh, so scrape-examples already supports scraping e.g. library source code if you tell it to? |
That's right. And rust-lang/cargo#10343 makes that configurable at the target level. |
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. |
This is quite an extension so I'd prefer to have everyone on the team agreeing with it first. cc @rust-lang/rustdoc |
I support this PR. A crate might be intended for use in test cases, so it makes sense to have example code that uses If other words, I think being example code and being test code are orthogonal. |
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. |
Maybe this should be a different flag, e.g. |
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. |
ac73cbb
to
5f6d413
Compare
Yeah, using the flag seems confusing to me. |
Could you squash your commits btw? |
fd6dd22
to
a4f5a32
Compare
Done. |
--test
flag through rustdoc to rustc so #[test]
functions can be scraped
Just noting that now that it's a new unstable flag, an FCP shouldn't be necessary. |
a4f5a32
to
fbbcb08
Compare
I just added some documentation for the flag as well. |
Looks good to me now, thanks! |
@GuillaumeGomez can you @bors (or should I do it?) |
I'm waiting for one last review from @camelid. If they don't see anything else, then let's r+. :) |
As long as this PR only adds behavior behind a new unstable flag, I have no objections. |
Then let's go! @bors: r+ |
📌 Commit fbbcb08 has been approved by |
…askrgr Rollup of 10 pull requests Successful merges: - rust-lang#89892 (Suggest `impl Trait` return type when incorrectly using a generic return type) - rust-lang#91675 (Add MemTagSanitizer Support) - rust-lang#92806 (Add more information to `impl Trait` error) - rust-lang#93497 (Pass `--test` flag through rustdoc to rustc so `#[test]` functions can be scraped) - rust-lang#93814 (mips64-openwrt-linux-musl: correct soft-foat) - rust-lang#93847 (kmc-solid: Use the filesystem thread-safety wrapper) - rust-lang#93877 (asm: Allow the use of r8-r14 as clobbers on Thumb1) - rust-lang#93892 (Only mark projection as ambiguous if GAT substs are constrained) - rust-lang#93915 (Implement --check-cfg option (RFC 3013), take 2) - rust-lang#93953 (Add the `known-bug` test directive, use it, and do some cleanup) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
NoteThis 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 through rustdoc to rustc so #[test]
functions can be scraped--scrape-tests
option to rustdoc to scrape functions marked #[test]
Good point. I updated the title. |
As a part of stabilizing the scrape examples extension in Cargo, I uncovered a bug where examples cannot be scraped from tests. See this test: https://github.com/rust-lang/cargo/pull/10343/files#diff-27aa4f012ebfebaaee61498d91d2370de460628405d136b05e77efe61e044679R2496
The issue is that when rustdoc is run on a test file, because
--test
is not passed as a rustc option, then functions annotated with#[test]
are ignored by the compiler. So this PR changes rustdoc so when--test
is passed in conjunction with a--scrape-example-<suffix>
flag, then thetest
field ofrustc_interface::Config
is true.r? @camelid