-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 the ability to test doc strings #11120
Conversation
Could you update the rustdoc tutorial to mention this while you're at it? It seems pretty threadbare at the moment, but it'd be nice to keep it from falling further behind. |
I have added some documentation in the rustdoc tutorial |
Yay! The doc target is (for example) (Also, it'd be worth adding to this page when this lands.) |
Yes, the target will be
I'll definitely add it to the testing wiki! I'll reference the rustdoc documentation I wrote for that. |
Couldn't I.e. if someone has done a full |
It does seem like we may want to assume that all code blocks are rust and testable unless otherwise specified. |
Very cool. |
This adds support for the `--test` flag to rustdoc which will parse a crate, extract all code examples in doc comments, and then run each test in the extra::test driver.
Don't run doc tests during make check-fast because it involves spawning lots of processes.
This commit adds a `--test` flag to rustdoc to expose the ability to test code examples in doc strings. This work by using sundown's `lang` attribute to figure out how a code block should be tested. The format for this is: ``` 1. ```rust 2. ```rust,ignore 3. ```rust,notest 4. ```rust,should_fail ``` Where `rust` means that rustdoc will attempt to test is, `ignore` means that it will not execute the test but it will compile it, `notest` means that rustdoc completely ignores it, and `should_fail` means that the test should fail. This commit also leverages `extra::test` for the testing harness in order to allow parallelization and whatnot. I have fixed all existing code examples in libstd and libextra, but I have not made a pass through the crates in order to change code blocks to testable code blocks. It may also be a questionable decision to require opting-in to a testable code block. Finally, I kept our sugar in the doc suite to omit lines starting with `#` in documentation but still process them during tests. Closes #2925
!!!! \o/ |
This commit adds a
--test
flag to rustdoc to expose the ability to test code examples in doc strings. This work by using sundown'slang
attribute to figure out how a code block should be tested. The format for this is:Where
rust
means that rustdoc will attempt to test is,ignore
means that it will not execute the test but it will compile it,notest
means that rustdoc completely ignores it, andshould_fail
means that the test should fail. This commit also leveragesextra::test
for the testing harness in order to allow parallelization and whatnot.I have fixed all existing code examples in libstd and libextra, but I have not made a pass through the crates in order to change code blocks to testable code blocks.
It may also be a questionable decision to require opting-in to a testable code block.
Finally, I kept our sugar in the doc suite to omit lines starting with
#
in documentation but still process them during tests.Closes #2925