-
Couldn't load subscription status.
- Fork 13.9k
rustdoc: Test & document test_harness code block attribute
#148183
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
Open
fmease
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
fmease:rustdoc-test-n-doc-doctest-test-harness
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -847,11 +847,12 @@ pub(crate) enum Ignore { | |
| Some(Vec<String>), | ||
| } | ||
|
|
||
| /// This is the parser for fenced codeblocks attributes. It implements the following eBNF: | ||
| /// This is the parser for fenced codeblocks attributes. | ||
| /// | ||
| /// ```eBNF | ||
| /// lang-string = *(token-list / delimited-attribute-list / comment) | ||
| /// It implements the following grammar as expressed in ABNF: | ||
| /// | ||
| /// ```ABNF | ||
| /// lang-string = *(token-list / delimited-attribute-list / comment) | ||
| /// bareword = LEADINGCHAR *(CHAR) | ||
| /// bareword-without-leading-char = CHAR *(CHAR) | ||
| /// quoted-string = QUOTE *(NONQUOTE) QUOTE | ||
|
|
@@ -862,7 +863,7 @@ pub(crate) enum Ignore { | |
| /// attribute-list = [sep] attribute *(sep attribute) [sep] | ||
| /// delimited-attribute-list = OPEN-CURLY-BRACKET attribute-list CLOSE-CURLY-BRACKET | ||
| /// token-list = [sep] token *(sep token) [sep] | ||
| /// comment = OPEN_PAREN *(all characters) CLOSE_PAREN | ||
| /// comment = OPEN_PAREN *<all characters except closing parentheses> CLOSE_PAREN | ||
|
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. Prose terminals are to be denoted by |
||
| /// | ||
| /// OPEN_PAREN = "(" | ||
| /// CLOSE_PARENT = ")" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Ensure that the code block attr `test_harness` works as expected. | ||
| //@ compile-flags: --test --test-args --test-threads=1 | ||
| //@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR" | ||
| //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | ||
| //@ rustc-env: RUST_BACKTRACE=0 | ||
| //@ failure-status: 101 | ||
|
|
||
| // The `main` fn won't be run under `test_harness`, so this test should pass. | ||
| //! ```test_harness | ||
| //! fn main() { | ||
| //! assert!(false); | ||
| //! } | ||
| //! ``` | ||
| // Check that we run both `bad` and `good` even if `bad` fails. | ||
| //! ```test_harness | ||
| //! #[test] | ||
| //! fn bad() { | ||
| //! assert!(false); | ||
| //! } | ||
| //! | ||
| //! #[test] | ||
| //! fn good() { | ||
| //! assert!(true); | ||
| //! } | ||
| //! ``` | ||
| // Contrary to normal doctests, cfg `test` is active under `test_harness`. | ||
| //! ```test_harness | ||
| //! #[cfg(test)] | ||
| //! mod group { | ||
| //! #[test] | ||
| //! fn element() { | ||
| //! assert!(false); | ||
| //! } | ||
| //! } | ||
| //! ``` | ||
| // `test_harness` doctests aren't implicitly wrapped in a `main` fn even if they contain stmts. | ||
| //! ```test_harness | ||
| //! assert!(true); | ||
| //! | ||
| //! #[test] fn extra() {} | ||
| //! ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
|
|
||
| running 4 tests | ||
| test $DIR/test-harness.rs - (line 14) ... FAILED | ||
| test $DIR/test-harness.rs - (line 25) ... FAILED | ||
| test $DIR/test-harness.rs - (line 34) ... FAILED | ||
| test $DIR/test-harness.rs - (line 9) ... ok | ||
|
|
||
| failures: | ||
|
|
||
| ---- $DIR/test-harness.rs - (line 14) stdout ---- | ||
| Test executable failed (exit status: 101). | ||
|
|
||
| stdout: | ||
|
|
||
| running 2 tests | ||
| test bad ... FAILED | ||
| test good ... ok | ||
|
|
||
| failures: | ||
|
|
||
| ---- bad stdout ---- | ||
|
|
||
| thread 'bad' ($TID) panicked at $DIR/test-harness.rs:4:5: | ||
| assertion failed: false | ||
| note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace | ||
|
|
||
|
|
||
| failures: | ||
| bad | ||
|
|
||
| test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
|
||
|
|
||
|
|
||
| ---- $DIR/test-harness.rs - (line 25) stdout ---- | ||
| Test executable failed (exit status: 101). | ||
|
|
||
| stdout: | ||
|
|
||
| running 1 test | ||
| test group::element ... FAILED | ||
|
|
||
| failures: | ||
|
|
||
| ---- group::element stdout ---- | ||
|
|
||
| thread 'group::element' ($TID) panicked at $DIR/test-harness.rs:6:9: | ||
| assertion failed: false | ||
| note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace | ||
|
|
||
|
|
||
| failures: | ||
| group::element | ||
|
|
||
| test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
|
||
|
|
||
|
|
||
| ---- $DIR/test-harness.rs - (line 34) stdout ---- | ||
| error: non-item macro in item position: assert | ||
| --> $DIR/test-harness.rs:35:1 | ||
| | | ||
| LL | assert!(true); | ||
| | ^^^^^^^^^^^^^ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| Couldn't compile the test. | ||
|
|
||
| failures: | ||
| $DIR/test-harness.rs - (line 14) | ||
| $DIR/test-harness.rs - (line 25) | ||
| $DIR/test-harness.rs - (line 34) | ||
|
|
||
| test result: FAILED. 1 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
It's not any old ENBF1 (variant), it's ABNF2 specifically (from IETF RFC 5234) which I previously didn't know about (and thus was confused about the syntax).
Footnotes
Extended Backus-Naur form. ↩
Augmented Backus-Naur form. ↩