Skip to content

[WIP] rustdoc testing: Further improve chapters and sections #2298

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fmease
Copy link
Member

@fmease fmease commented Mar 20, 2025

Follow-up to #2295 (applies my remaining review comments).

This is WIP / a draft because I g2g. Will impl all FIXME(fmease)s when I come back.

cc @lolbinarycat @jieyouxu @notriddle

@fmease fmease added S-waiting-on-author Status: this PR is waiting for additional action by the OP A-compiletest Area: src/tools/compiletest A-test-suite Area: rust-lang/rust test suites T-rustdoc Relevant to rustdoc team labels Mar 20, 2025
Comment on lines 13 to 15
## Htmldocck-Specific Directives

In addition to the directives listed here,
`rustdoc` tests also support most
[compiletest directives](../tests/directives.html).
Directives to htmldocck are similar to those given to `compiletest` in that they take the form of `//@` comments.
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: even though it's an implementation detail, I think it's worth hammering in the distinction that htmldocck directives are handled by htmldocck and not compiletest.

@@ -34,33 +32,41 @@ In this case, the start of the next line should be `//`, with no `@`.

For example, `//@ !has 'foo/struct.Bar.html'` checks that crate `foo` does not have a page for a struct named `Bar` in the crate root.

<!-- FIXME(fmease): Mention that the regexes match case-sensitively and in single-line mode? -->
Copy link
Member

Choose a reason for hiding this comment

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

Discussion: may also be worth mentioning if the regexes have any string and/or regex escape rules. For instance, I know some compiletest regex directives don't handle this very well.

Comment on lines 81 to 87
htmldocck supports the `--bless` option to accept the current subtree
Htmldocck supports the `--bless` option to accept the current subtree
Copy link
Member

@jieyouxu jieyouxu Mar 20, 2025

Choose a reason for hiding this comment

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

Question: IIRC the --bless flow requires html-tidy to be installed and available somewhere. Not sure if this is mentioned already. Maybe worth explicitly remarking or linking to that?

Comment on lines +121 to +124
<!-- FIXME(fmease):
Should definitely also mention `//@ aux-crate` and `//@ proc-macro`
UNLESS we nuke this paragraph entirely and refer to the compiletest section(s)?
-->
Copy link
Member

Choose a reason for hiding this comment

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

Remark (not-a-review-comment): I think this is where I would like compiletest to support some kind of directive handling "plugin" and allow htmldocck to register plugins. Then we could phrase this as "htmldocck registers additional directive handling to compiletest" either here, or even put this bit under main compiletest chapter.

Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: may or may not be helpful for someone looking to adjust how tests/rustdoc works / change htmldocck/compiletest for tests/rustdoc purposes... but here's a very coarse TL;DR on the test infra bits involved on running tests/rustdoc:


Test infra setup

The test infra setup for tests/rustdoc involves the following bits:

@fmease fmease force-pushed the rustdoc-testing-addendum branch 2 times, most recently from c109003 to d276166 Compare June 2, 2025 17:22
@fmease fmease force-pushed the rustdoc-testing-addendum branch from d276166 to d1b2c3f Compare June 2, 2025 17:32

<!--
**FIXME(rustdoc)**: what does `check-test-line-numbers-match` do?
Asked in
<https://rust-lang.zulipchat.com/#narrow/stream/266220-t-rustdoc/topic/What.20is.20the.20.60check-test-line-numbers-match.60.20directive.3F>.
-->

#### Test-suite-specific directives
Copy link
Member Author

@fmease fmease Jun 2, 2025

Choose a reason for hiding this comment

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

I've added this subsection because you may very likely land in section Compiletest directives § Rustdoc (the parent section) via fuzzy searching (I noticed that earlier) when (from the perspective of a new user) all you wanted was to get to know what on earth those tool-specific directives meant.

On master, this section wouldn't help you in the slightest.

Re. my change: I wouldn't classify this as duplicating information (which master rustdoc docs do a bunch and it's maddening!) but as necessary redundancy. It's also helpful IMO if you're just scrolling this section trying to get an overview over directive handling (tool-specific directives are an important part of it).

where they're handled by the test runner of bootstrap and
the supplementary script `src/etc/htmldocck.py`.
[These tests have several extra directives available to them](./rustdoc-internals/rustdoc-test-suite.md).
* Additionally, JavaScript type annotations are written using [TypeScript-flavored JSDoc]
Copy link
Member Author

@fmease fmease Jun 2, 2025

Choose a reason for hiding this comment

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

This bullet point had nothing to do with tests (but with static analysis). I've moved it into Code Structure where the term JavaScript was already mentioned.

Ofc, that's still not great of a place, ideally we would have a separate section about internal linting / static analysis or something of similar nature.

Copy link
Contributor

Choose a reason for hiding this comment

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

the rationale was that both are run in CI, but I guess there is a fairly meaningful distinction between static analysis and unit/integration tests, with the line only becoming blurry again once you bring in proof assistants like kani.


* Tests on search engine and index are located in `tests/rustdoc-js` and `tests/rustdoc-js-std`.
Copy link
Member Author

@fmease fmease Jun 2, 2025

Choose a reason for hiding this comment

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

This unordered list of tests suites was incredibly illegible. If you're trying to find out about a specific test suite, you basically needed to linearly scan through it and skip all that prose.

A table is way better. First I tried to turn it into a table, then I found out that we already have such a table over at tests/compiletest.md#rustdoc-test-suites. There's no need to duplicate this information, it's even counterproductive as everything gets easily outdated and it's hard to find a "single source of truth" because they don't match 100%.

So I've just removed this subsection (because this subpage shouldn't actually talk about testing, we have an entire directory full of documents for that1) in favor of a cross-link. I've slightly fleshed out that table, so no information gets lost.

Footnotes

  1. I really dislike how rustdoc content is split weirdly between rustdoc.md and rustdoc-internals.md as it's unclear where to put content. We need to reassess and restructure. Find a better flow.

@@ -270,35 +270,6 @@ in `test.rs` is the function `make_test`, which is where hand-written
Some extra reading about `make_test` can be found
[here](https://quietmisdreavus.net/code/2018/02/23/how-the-doctests-get-made/).

## Dotting i's And Crossing t's
Copy link
Member Author

Choose a reason for hiding this comment

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

Severely outdated (the rustdoc-js{,-std} test suites are nowadays fully documented in a separate document) and we also shouldn't talk about tests here, we have whole subdirectory dedicated for that.

Copy link
Contributor

@lolbinarycat lolbinarycat left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning this up! I'm always in favor of deduplicating and peeling away unnecessary indirection, although leaving stubs with links to the main section is also good, for discovery, and I also appove of adding new stubs sections like the one you added about testsuite-specific directives.

* The bits specific to using rustdoc as a test harness are in
`doctest.rs`.
* The Markdown renderer is loaded up in `html/markdown.rs`, including functions
for extracting doctests from a given block of Markdown.
* Frontend CSS and JavaScript are stored in `html/static/`.
* Re. JavaScript, type annotations are written using [TypeScript-flavored JSDoc]
comments and an external `.d.ts` file.
This way, the code itself remains plain, valid JavaScript.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should explain that this is so that tsc is not required as a build-time dependancy of rustdoc, not because we don't transform the source code at all (we are minifying it, so the jsdoc comments will not appear in the final documentation bundle unless minification is disabled, not sure how many of those details we should include)

isn't this duplicating some text that already exists somewhere? should we deduplicate that and make a subpage for how we use tsc? or is it small enough that the duplication isn't a problem?

where they're handled by the test runner of bootstrap and
the supplementary script `src/etc/htmldocck.py`.
[These tests have several extra directives available to them](./rustdoc-internals/rustdoc-test-suite.md).
* Additionally, JavaScript type annotations are written using [TypeScript-flavored JSDoc]
Copy link
Contributor

Choose a reason for hiding this comment

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

the rationale was that both are run in CI, but I guess there is a fairly meaningful distinction between static analysis and unit/integration tests, with the line only becoming blurry again once you bring in proof assistants like kani.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: src/tools/compiletest A-test-suite Area: rust-lang/rust test suites S-waiting-on-author Status: this PR is waiting for additional action by the OP T-rustdoc Relevant to rustdoc team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants