-
Notifications
You must be signed in to change notification settings - Fork 13k
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 --extract-doctests
command-line flag
#134531
base: master
Are you sure you want to change the base?
Changes from all commits
5afc1c5
5adedd7
67a0fef
651988d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,3 +664,22 @@ Similar to cargo `build.rustc-wrapper` option, this flag takes a `rustc` wrapper | |
The first argument to the program will be the test builder program. | ||
|
||
This flag can be passed multiple times to nest wrappers. | ||
|
||
### `--extract-doctests`: outputs doctests in JSON format | ||
|
||
* Tracking issue: [#134529](https://github.com/rust-lang/rust/issues/134529) | ||
|
||
When this flag is used, it outputs the doctests original source code alongside information | ||
such as: | ||
|
||
* File where they are located. | ||
* Line where they are located. | ||
* Codeblock attributes (more information about this [here](./write-documentation/documentation-tests.html#attributes)). | ||
|
||
The output format is JSON. | ||
|
||
Using this flag looks like this: | ||
|
||
```bash | ||
$ rustdoc -Zunstable-options --extract-doctests src/lib.rs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a CLI option and not an output format? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I didn't think about it, it's SO MUCH better! |
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Test to ensure that it generates expected output for `--extract-doctests` command-line | ||
// flag. | ||
|
||
//@ compile-flags:-Z unstable-options --extract-doctests | ||
//@ normalize-stdout-test: "tests/rustdoc-ui" -> "$$DIR" | ||
//@ check-pass | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want a test for how this interacts with:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True although currently it's the code as defined in the documentation and no changes on rustdoc side (which I think matches better what rust for linux wants). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should provide another field with "rustdoc computed code" where hidden lines and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Currently we use both hidden lines and the Some of that post-processing may be easy to do by users, like the hidden lines I assume, but if you walk the source or IR or similar to figure out details (like the crate attributes that you move out of Having the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, for instance, if Of course, for things like crate attributes, it may be best to remove them so that the end user can re-add them where needed, so it wouldn't be the completely "unaltered" source code. But it could be an "adapted" version. Hidden lines should probably be normal lines in that adapted version. Perhaps it makes sense to provide all those versions, i.e. the completely unaltered one for those that may want to do something complex or to render the text somewhere, the "adapted" version for customized test environments and the |
||
//! ```ignore (checking attributes) | ||
//! let x = 12; | ||
//! let y = 14; | ||
//! ``` | ||
//! | ||
//! ```edition2018,compile_fail | ||
//! let | ||
//! ``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"filename":"$DIR/extract-doctests.rs","line":8,"langstr":{"original":"ignore (checking attributes)","should_panic":false,"no_run":false,"ignore":"All","rust":true,"test_harness":false,"compile_fail":false,"standalone_crate":false,"error_codes":[],"edition":null,"added_classes":[],"unknown":[]},"text":"let x = 12;\nlet y = 14;"},{"filename":"$DIR/extract-doctests.rs","line":13,"langstr":{"original":"edition2018,compile_fail","should_panic":false,"no_run":true,"ignore":"None","rust":true,"test_harness":false,"compile_fail":true,"standalone_crate":false,"error_codes":[],"edition":"2018","added_classes":[],"unknown":[]},"text":"let"}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not enough documentation, even for an unstable feature. You need to say what the actual keys are, and what they do (particularly the subkeys of
langstr
, which are not self-explanatory). Please include a prettified example JSON document with all of the format features used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure if we want everything to be documented as docblock attributes list might get longer. Well, I'll list the current one and we can think about it later.