Skip to content

rustdoc: Test & document test_harness code block attribute#148183

Open
fmease wants to merge 1 commit into
rust-lang:mainfrom
fmease:rustdoc-test-n-doc-doctest-test-harness
Open

rustdoc: Test & document test_harness code block attribute#148183
fmease wants to merge 1 commit into
rust-lang:mainfrom
fmease:rustdoc-test-n-doc-doctest-test-harness

Conversation

@fmease

@fmease fmease commented Oct 27, 2025

Copy link
Copy Markdown
Member

View all comments

They were fully untested and undocumented previously despite being stable.
Context: #t-rustdoc > `test_harness` langstr @ 💬.

While at it, I've also improved the documentation for code block attributes in general.
I was only inspired to do so because there was no good place for test_harness and because it got hard to skim due to a lack of subsubsections.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Oct 27, 2025
@rustbot

rustbot commented Oct 27, 2025

Copy link
Copy Markdown
Collaborator

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@@ -847,11 +847,12 @@ pub(crate) enum Ignore {
Some(Vec<String>),
}

@fmease fmease Oct 27, 2025

Copy link
Copy Markdown
Member Author

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

  1. Extended Backus-Naur form.

  2. Augmented Backus-Naur form.

/// 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

@fmease fmease Oct 27, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prose terminals are to be denoted by <…> not by (…) (which is grouping) per IETF RFC 5234 (Ctrl+F for prose-val).

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from eab1d61 to 5e7f083 Compare October 27, 2025 18:05
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from 5e7f083 to c687f89 Compare October 27, 2025 18:53
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from c687f89 to f71d897 Compare October 27, 2025 19:41
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from f71d897 to 9a78729 Compare October 27, 2025 20:24
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from 9a78729 to 3a17eba Compare October 27, 2025 23:40
Code blocks can be annotated with attributes that help `rustdoc` do the right
thing when testing your code:
Code blocks can be annotated with attributes that tell `rustdoc` how to build and interpret the test.
They follow the triple backtick in the opening line.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily triple, it can be ten if you want. ^^'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'd say (or something along the lines):

Suggested change
They follow the triple backtick in the opening line.
They follow the backticks marking the beginning of the code block.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it can also be ~~~ ^^'. I've used triple backtick because that's what's also used at the top of the file. We do link to the CommonMark spec later for the full rules.

But yeah, I should probably rephrase that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep forgetting about ~~~... Markdown is too flexible 😅

@fmease fmease Jun 5, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with code fence + a link to the relevant part of the CommonMark spec.

They follow the triple backtick in the opening line.
As such, they share the place with language strings like `rust` or `text`.
Multiple attributes can be provided by separating them with commas, spaces or tabs.
You can also write comments which are enclosed in parentheses `(…)`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to the relevant part of the book which explains the syntax of codeblock attributes instead?

@fmease fmease Nov 14, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part of the book about codeblock attributes. We didn't have any documentation in the Book about this before.

Comment thread src/doc/rustdoc/src/write-documentation/documentation-tests.md Outdated
@lolbinarycat

Copy link
Copy Markdown
Contributor

A quick github code search reveals this is in fact used in the wild.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2026
@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from 3a17eba to f13978f Compare June 5, 2026 13:01
@rustbot

rustbot commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@fmease

fmease commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 5, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 5, 2026
@rust-bors

rust-bors Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#157502), which was unapproved.

View changes since this unapproval

@fmease

fmease commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

This is so sad, there's no official (cross-platform) way to pass libtest arguments to the inner test harness, that's pretty sad but kinda obvious in hindsight; --test-threads=1 isn't forwarded which makes sense meaning that one test case has non-deterministic output (duh).

I'm crying, do I need to abuse runtools now?

@GuillaumeGomez

Copy link
Copy Markdown
Member

I won't judge if you do. :3

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from f13978f to 5706bfe Compare June 8, 2026 14:11
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Jun 8, 2026
@fmease

fmease commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@bors try jobs=aarch64-gnu-llvm-21-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 8, 2026
…s, r=<try>

rustdoc: Test & document `test_harness` code block attribute


try-job: aarch64-gnu-llvm-21-1
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

💔 Test for fa2c91f failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from 5706bfe to 4f88c4d Compare June 8, 2026 16:31
@fmease

fmease commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@bors try jobs=x86_64-msvc-1,aarch64-gnu-llvm-21-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 8, 2026
…s, r=<try>

rustdoc: Test & document `test_harness` code block attribute


try-job: x86_64-msvc-1
try-job: aarch64-gnu-llvm-21-1
@rust-bors

rust-bors Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 2fe156a failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the rustdoc-test-n-doc-doctest-test-harness branch from 4f88c4d to a918066 Compare June 8, 2026 19:46
Moreover, flesh out the rustdoc book section about code block attributes.
@fmease

fmease commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@bors try jobs=x86_64-msvc-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 8, 2026
…s, r=<try>

rustdoc: Test & document `test_harness` code block attribute


try-job: x86_64-msvc-1
@fmease

fmease commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

Final try-builds still needs to come back clean of course but this is now ready for re-review. I've basically split out the problematic part out of the rustdoc-UI test into a new run-make test.

@fmease fmease added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 8, 2026
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 8, 2026
@rust-bors

rust-bors Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

💔 Test for acf5f03 failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-msvc-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [run-make] tests\run-make\doctests-test_harness stdout ----

error: rmake recipe failed to complete
status: exit code: 101
command: "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\test\\run-make\\doctests-test_harness\\rmake.exe"
stdout: none
--- stderr -------------------------------
"D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage2\\bin\\rustc.exe" "-L" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\test\\run-make\\doctests-test_harness\\rmake_out" "doctests.rs" "--crate-type" "lib" "--target=x86_64-pc-windows-msvc"
output status: `exit code: 0`
=== STDOUT ===



=== STDERR ===



"D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage2\\bin\\rustc.exe" "-L" "D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\test\\run-make\\doctests-test_harness\\rmake_out" "runtool.rs" "--target=x86_64-pc-windows-msvc"
output status: `exit code: 0`
=== STDOUT ===



=== STDERR ===



"D:\\a\\rust\\rust\\build\\x86_64-pc-windows-msvc\\stage2\\bin\\rustdoc.exe" "doctests.rs" "--test" "--test-args=--test-threads=1" "--test-runtool" ".\\runtool..exe" "-L." "--target=x86_64-pc-windows-msvc"
output status: `exit code: 101`
=== STDOUT ===

running 2 tests
test doctests.rs - (line 15) ... FAILED
test doctests.rs - (line 4) ... FAILED

---
@@ -6,55 +6,9 @@
 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:
---
-
-
+Couldn't run the test: The system cannot find the file specified. (os error 2)
 ---- 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:
---
   0: std::panicking::panic_handler
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library\std\src\panicking.rs:689
   1: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library\core\src\panicking.rs:80
   2: <run_make_support::diff::Diff>::run
   3: rmake::main
   4: rmake::main
   5: std::rt::lang_start::<()>
   6: std::rt::lang_start::<()>
   7: std::rt::lang_start_internal::closure$0
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library\std\src\rt.rs:175
   8: std::panicking::catch_unwind::do_call
---

Some tests failed in compiletest suite=run-make mode=run-make host=x86_64-pc-windows-msvc target=x86_64-pc-windows-msvc
Bootstrap failed while executing `test --stage 2 --skip=compiler --skip=src`
Build completed unsuccessfully in 2:22:09
make: *** [Makefile:115: ci-msvc-py] Error 1
  local time: Mon Jun  8 22:17:09 CUT 2026
  network time: Mon, 08 Jun 2026 22:17:09 GMT
##[error]Process completed with exit code 2.
##[group]Run echo "disk usage:"
echo "disk usage:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants