-
-
Notifications
You must be signed in to change notification settings - Fork 15k
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -846,11 +846,12 @@ pub(crate) enum Ignore { | |
| Some(Vec<String>), | ||
| } | ||
|
|
||
|
Member
Author
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. 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 |
||
| /// 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 | ||
|
|
@@ -861,7 +862,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 | ||
|
Member
Author
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 = ")" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Test that we can successfully run two separate test suites. | ||
| // Check that we run all four tests even though `ill` and `bad` both fail. | ||
|
|
||
| //! ```test_harness | ||
| //! #[test] | ||
| //! fn well() { | ||
| //! assert!(true); | ||
| //! } | ||
| //! | ||
| //! #[test] | ||
| //! fn ill() { | ||
| //! assert!(false); | ||
| //! } | ||
| //! ``` | ||
|
|
||
| //! ```test_harness | ||
| //! #[test] | ||
| //! fn bad() { | ||
| //! assert!(false); | ||
| //! } | ||
| //! | ||
| //! #[test] | ||
| //! fn good() { | ||
| //! assert!(true); | ||
| //! } | ||
| //! ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
|
|
||
| running 2 tests | ||
| test doctests.rs - (line 15) ... FAILED | ||
| test doctests.rs - (line 4) ... FAILED | ||
|
|
||
| failures: | ||
|
|
||
| ---- doctests.rs - (line 15) stdout ---- | ||
| Test executable failed ($STATUS). | ||
|
|
||
| stdout: | ||
|
|
||
| running 2 tests | ||
| test bad ... FAILED | ||
| test good ... ok | ||
|
|
||
| failures: | ||
|
|
||
| ---- bad stdout ---- | ||
|
|
||
| thread 'bad' ($TID) panicked at doctests.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 | ||
|
|
||
|
|
||
|
|
||
| ---- doctests.rs - (line 4) stdout ---- | ||
| Test executable failed ($STATUS). | ||
|
|
||
| stdout: | ||
|
|
||
| running 2 tests | ||
| test ill ... FAILED | ||
| test well ... ok | ||
|
|
||
| failures: | ||
|
|
||
| ---- ill stdout ---- | ||
|
|
||
| thread 'ill' ($TID) panicked at doctests.rs:9:6: | ||
| assertion failed: false | ||
| note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace | ||
|
|
||
|
|
||
| failures: | ||
| ill | ||
|
|
||
| test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
|
||
|
|
||
|
|
||
|
|
||
| failures: | ||
| doctests.rs - (line 15) | ||
| doctests.rs - (line 4) | ||
|
|
||
| test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //@ ignore-cross-compile (needs to run host tool binary) | ||
|
|
||
| // Test the behavior of doctests that are marked `test_harness` and that contain multiple `#[test]` | ||
| // functions. Sadly this needs to be a run-make test instead of rustdoc-UI one because at the time | ||
| // of writing we can only pass `--test-threads=1` to the inner test suite using a runtool (needed to | ||
| // guarantee deterministic test output) which we'd like to be written in Rust to be cross-platform. | ||
| // | ||
| // See also #157511 and `tests/rustdoc-ui/doctest/test_harness.rs`. | ||
|
|
||
| use std::path::Path; | ||
|
|
||
| use run_make_support::{diff, rustc, rustdoc}; | ||
|
|
||
| fn main() { | ||
| let doctests_path = Path::new("doctests.rs"); | ||
| let runtool_path = Path::new("runtool.rs"); | ||
|
|
||
| rustc().input(doctests_path).crate_type("lib").run(); | ||
| rustc().input(runtool_path).run(); | ||
|
|
||
| let output = rustdoc() | ||
| .input(doctests_path) | ||
| .arg("--test") | ||
| // for the outer test suite | ||
| .arg("--test-args=--test-threads=1") | ||
| .arg("--test-runtool") | ||
| .arg(Path::new(".").join(runtool_path).with_extension(std::env::consts::EXE_EXTENSION)) | ||
| .arg("-L.") | ||
| .env("RUST_BACKTRACE", "0") | ||
| .run_fail(); | ||
| output.assert_exit_code(101); | ||
| output.assert_stderr_equals(""); | ||
|
|
||
| diff() | ||
| .expected_file(doctests_path.with_extension("stdout")) | ||
| .actual_text("stdout", output.stdout_utf8()) | ||
| .normalize(r#"finished in \d+\.\d+s"#, "finished in $$TIME") | ||
| .normalize(r"thread '(?P<name>.*?)' \(\d+\) panicked", "thread '$name' ($$TID) panicked") | ||
| .normalize(r"Test executable failed \(.+?\)", "Test executable failed ($$STATUS)") | ||
| .run(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // The whole purpose of this runtool is to pass `--test-threads=1` | ||
| // to the inner testsuite to guarantee deterministic output. | ||
| // See also #157511. | ||
|
|
||
| fn main() { | ||
| let status = std::process::Command::new(std::env::args().nth(1).unwrap()) | ||
| .arg("--test-threads=1") | ||
| .status() | ||
| .unwrap(); | ||
| std::process::exit(status.code().unwrap()) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.