-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Add descriptive names to doctests #3311
base: master
Are you sure you want to change the base?
Conversation
This RFC proposes the ability to annotate documentation test code blocks with metadata of the form `name=NAME`. The given name will be used to identify the documentation test when it is run by the test runner, in addition to the current information of test binary, module, and line number. For example, this documention test: ```name=arithmetic assert_eq!(2 + 2, 4); ``` Assuming that it is in crate `foo`, in file `src/lib.rs`, in module `bar`, on line 37, will produce this output when run: Doc-tests foo running 1 test test src/lib.rs - bar::arithmetic (line 37) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
- Mention test filtering - Remove restriction that `NAME` be a valid identifier - Rename IDENT to NAME
Updated and addressed comments. Thank you for the feedback!
A previous version of this RFC required that doctest names be valid rust identifiers. I think this might be a good idea, but someone wasn't convinced. I think it's probably a reasonable restriction, and means that you can use the identifiers as names for the generated test binaries/functions/etc, so it's something that I'd like feedback on. However, I wanted the text of the RFC to be consistent, so I removed references to that restriction for now. |
Thanks for the feedback! I added the requirement that names be valid rust identifiers, and used spaces to separate attributes in the examples instead of commas. |
Friendly ping! |
This probably needs re-thought through to match up with rust-lang/rust#110800. I'll start FCP if that's done, since this change otherwise looks good. |
Are commas the preferred way (or only?) way to separate annotations on a code block? I used spaces originally, since they were accepted by the parser, but I'm not sure if that changed. I think that's the only change here that needs to be made. |
Oh damn, completely forgot to stabilize this feature. Gonna send a PR for that. Commas are the only character to separate annotations currently. To add your feature, I think you just need to check for |
@GuillaumeGomez Nice! Okay, updated the RFC to use commas in the example about separating attribute names. I think this is ready to go. |
Considering rust-lang/rust#124577 is about to get stabilized, I'm not sure if Another thing to note is that you will be able to add attributes to generated codeblocks with this syntax: In any case, I think renaming |
The docs don't say that, and the code seems to warn on "unsupported attributes" without storing them anywhere, so I don't think that's true. If that PR is supposed to add this feature, it'll need fixed and should probably be pointed out to everyone else. (Also, I don't see a problem with
I think that's a bad idea. The |
Good catch, you can see that key-values only only certain values here. |
I personally think |
So, if we're essentially on board with calling it @rfcbot fcp merge |
Team member @notriddle has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
One thing to note is that the eBNF doesn't currently allow to have |
Or put it inside the braces. I just didn’t catch that. |
Then |
This is a very nice feature! @rfcbot concern braced-unbraced As mentioned above, we need to decide if we'd like extend the code block attr grammar to support bare @rfcbot concern raw-idents I guess it's implied by the use of the word Rust identifier but I'd like to raise awareness that this includes raw identifiers (prefix: @rfcbot concern hard-errors
I'd like to see this clarified. I'm pretty sure we don't want to emit a hard error for duplicate names but merely a warn-by-default Edit: The same applies to other syntax errors (e.g., RHS not being a valid ident). @rfcbot reviewed Footnotes
|
Thank you for the review!
I personally would prefer the unbraced
I noted that raw identifiers are allowed.
In the same vein, should |
That's a separate point. And I honestly don't know if it's feasible or worth impl'ing this, namely checking that doctest names are unique within the " |
Just updated the RFC. If the idea is that |
Wait a minute. It reverted back to commas? @rfcbot concern interoperability We seem to be going in circles. The original commit, 7641de1, from 2022, used the syntax I objected to this syntax, citing a Babelmark run that showed most CommonMark engines interpreting this as adding In cc3c07a, this was resolved by separating the This syntax needs to be designed so that most markdown renderers treat it as separate from the language tag. Allowing commas is fine, but using a space to separate the name from the language needs to work. |
That doesn't seem to be true. |
This feature was discussed in the previous monthly meeting, and we decided that it needed better motivation before adding it. To estimate how common this need might be, I used Crater to measure how many crates had items with more than five doctests to an item. The answer, as it turns out, is 0.6%. |
I wasn't sure if this needed an RFC or not. It's a rather minor feature, however, it is a user-visible change, and since I've already written one, I thought I'd open a PR. Feel free to close it if it doesn't require an RFC.
I did some supporting work on this in rust-lang/rust#78429, which made code block info string parsing only split on
,
and whitespace, so that an attribute of the formname=foo
would be possible, but never followed up with the actual RFC.This RFC proposes the ability to annotate documentation test code blocks with metadata of the form
name=NAME
. The given name will be used to identify the documentation test when it is run by the test runner, in addition to the current information of test binary, module, and line number.For example, this documention test:
Assuming that it is in crate
foo
, in filesrc/lib.rs
, in modulebar
, on line 37, will produce this output when run:Rendered