-
Notifications
You must be signed in to change notification settings - Fork 546
[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
base: master
Are you sure you want to change the base?
Conversation
## 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. |
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.
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? --> |
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.
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.
htmldocck supports the `--bless` option to accept the current subtree | ||
Htmldocck supports the `--bless` option to accept the current subtree |
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.
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?
<!-- FIXME(fmease): | ||
Should definitely also mention `//@ aux-crate` and `//@ proc-macro` | ||
UNLESS we nuke this paragraph entirely and refer to the compiletest section(s)? | ||
--> |
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.
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.
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.
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:
- Bootstrap (the build system) and its test step that builds:
- A suitably-staged sysroot (including the compiler and standard library).
- A rustdoc built with the sysroot.
compiletest
itself, and running it with the suitable configuration under therustdoc
test mode.- The implementation can be traced back from https://github.com/rust-lang/rust/blob/4e2b096ed6c8a1400624a54f6c4fd0c0ce48a579/src/bootstrap/src/core/build_steps/test.rs#L1349-L1355.
compiletest
handles the test discovery, compiletest directive parsing/handling (not to be confused with htmldocck directives) and test running via libtest. Seesrc/tools/compiletest/src/runtest/rustdoc.rs
.compiletest
invokessrc/etc/htmldocck.py
against the test file.
c109003
to
d276166
Compare
d276166
to
d1b2c3f
Compare
|
||
<!-- | ||
**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 |
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.
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] |
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.
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.
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.
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`. |
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.
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
-
I really dislike how rustdoc content is split weirdly between
rustdoc.md
andrustdoc-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 |
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.
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.
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.
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. |
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.
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] |
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.
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
.
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