Skip to content

Commit d276166

Browse files
committed
[WIP] rustdoc testing: Further improve chapters and sections
1 parent 1652578 commit d276166

File tree

8 files changed

+126
-81
lines changed

8 files changed

+126
-81
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
- [Rustdoc internals](./rustdoc-internals.md)
102102
- [Search](./rustdoc-internals/search.md)
103103
- [The `rustdoc` test suite](./rustdoc-internals/rustdoc-test-suite.md)
104+
- [The `rustdoc-gui` test suite](./rustdoc-internals/rustdoc-gui-test-suite.md)
105+
- [The `rustdoc-json` test suite](./rustdoc-internals/rustdoc-json-test-suite.md)
104106
- [Autodiff internals](./autodiff/internals.md)
105107
- [Installation](./autodiff/installation.md)
106108
- [How to debug](./autodiff/debugging.md)

src/rustdoc-internals.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,10 @@ Some extra reading about `make_test` can be found
272272

273273
## Dotting i's And Crossing t's
274274

275-
So that's `rustdoc`'s code in a nutshell, but there's more things in the
276-
compiler that deal with it. Since we have the full `compiletest` suite at hand,
277-
there's a set of tests in `tests/rustdoc` that make sure the final `HTML` is
278-
what we expect in various situations. These tests also use a supplementary
279-
script, `src/etc/htmldocck.py`, that allows it to look through the final `HTML`
280-
using `XPath` notation to get a precise look at the output. The full
281-
description of all the commands available to `rustdoc` tests (e.g. [`@has`] and
282-
[`@matches`]) is in [`htmldocck.py`].
283-
284-
To use multiple crates in a `rustdoc` test, add `//@ aux-build:filename.rs`
285-
to the top of the test file. `filename.rs` should be placed in an `auxiliary`
286-
directory relative to the test file with the comment. If you need to build
287-
docs for the auxiliary file, use `//@ build-aux-docs`.
275+
<!-- FIXME(fmease):
276+
* Make this section make sense again
277+
* Deduplicate with section in ../rustdoc.md#tests
278+
-->
288279

289280
In addition, there are separate tests for the search index and `rustdoc`'s
290281
ability to query it. The files in `tests/rustdoc-js` each contain a
@@ -295,10 +286,6 @@ that features results in all tabs can be found in `basic.js`. The basic idea is
295286
that you match a given `QUERY` with a set of `EXPECTED` results, complete with
296287
the full item path of each item.
297288

298-
[`@has`]: https://github.com/rust-lang/rust/blob/master/src/etc/htmldocck.py#L39
299-
[`@matches`]: https://github.com/rust-lang/rust/blob/master/src/etc/htmldocck.py#L44
300-
[`htmldocck.py`]: https://github.com/rust-lang/rust/blob/master/src/etc/htmldocck.py
301-
302289
## Testing Locally
303290

304291
Some features of the generated `HTML` documentation might require local
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The `rustdoc-gui` test suite
2+
3+
> **FIXME**: This section is a stub. Please help us flesh it out!
4+
5+
This page is about the test suite named `rustdoc-gui` used to test the "GUI" of `rustdoc` (i.e., the HTML/JS/CSS as rendered in a browser).
6+
For other rustdoc-specific test suites, see [Rustdoc test suites].
7+
8+
These use a NodeJS-based tool called [`browser-UI-test`] that uses [puppeteer] to run tests in a headless browser and check rendering and interactivity. For information on how to write this form of test, see [`tests/rustdoc-gui/README.md`][rustdoc-gui-readme] as well as [the description of the `.goml` format][goml-script]
9+
10+
[Rustdoc test suites]: ../tests/compiletest.md#rustdoc-test-suites
11+
[`browser-UI-test`]: https://github.com/GuillaumeGomez/browser-UI-test/
12+
[puppeteer]: https://pptr.dev/
13+
[rustdoc-gui-readme]: https://github.com/rust-lang/rust/blob/master/tests/rustdoc-gui/README.md
14+
[goml-script]: https://github.com/GuillaumeGomez/browser-UI-test/blob/master/goml-script.md
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The `rustdoc-json` test suite
2+
3+
> **FIXME**: This section is a stub. It will be populated by [PR #2422](https://github.com/rust-lang/rustc-dev-guide/pull/2422/).

src/rustdoc-internals/rustdoc-test-suite.md

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
# The `rustdoc` test suite
22

3-
This page is specifically about the test suite named `rustdoc`.
4-
For other test suites used for testing rustdoc, see [Rustdoc tests](../rustdoc.md#tests).
3+
This page is about the test suite named `rustdoc` used to test the HTML output of `rustdoc`.
4+
For other rustdoc-specific test suites, see [Rustdoc test suites].
55

6-
The `rustdoc` test suite is specifically used to test the HTML output of rustdoc.
7-
8-
This is achieved by means of `htmldocck.py`, a custom checker script that leverages [XPath].
6+
This is achieved by means of [`htmldocck.py`],
7+
a supplementary checker script invoked by compiletest that leverages [XPath].
98

9+
[Rustdoc test suites]: ../tests/compiletest.md#rustdoc-test-suites
10+
[`htmldocck.py`]: https://github.com/rust-lang/rust/blob/master/src/etc/htmldocck.py
1011
[XPath]: https://en.wikipedia.org/wiki/XPath
1112

12-
## Directives
13-
Directives to htmldocck are similar to those given to `compiletest` in that they take the form of `//@` comments.
13+
## HtmlDocCk-Specific Directives
1414

15-
In addition to the directives listed here,
16-
`rustdoc` tests also support most
17-
[compiletest directives](../tests/directives.html).
15+
Directives to HtmlDocCk are similar to those given to `compiletest` in that they take the form of `//@` comments.
1816

19-
All `PATH`s in directives are relative to the rustdoc output directory (`build/TARGET/test/rustdoc/TESTNAME`),
20-
so it is conventional to use a `#![crate_name = "foo"]` attribute to avoid
21-
having to write a long crate name multiple times.
2217
To avoid repetition, `-` can be used in any `PATH` argument to re-use the previous `PATH` argument.
18+
It is conventional to use a `#![crate_name = "foo"]` attribute to avoid
19+
having to write a long crate name multiple times.
2320

2421
All arguments take the form of quoted strings
2522
(both single and double quotes are supported),
@@ -35,33 +32,41 @@ In this case, the start of the next line should be `//`, with no `@`.
3532

3633
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.
3734

35+
<!-- FIXME(fmease): Mention that the regexes match case-sensitively and in single-line mode? -->
36+
3837
### `has`
3938

4039
Usage 1: `//@ has PATH`
4140
Usage 2: `//@ has PATH XPATH PATTERN`
4241

4342
In the first form, `has` checks that a given file exists.
4443

45-
In the second form, `has` is an alias for `matches`,
44+
In the second form, `has` is the same as `matches`,
4645
except `PATTERN` is a whitespace-normalized[^1] string instead of a regex.
46+
<!-- FIXME(fmease): It's more important to note *here* that the file under test gets normalized too (PATTERN is in 99% cases already normalized) -->
4747

4848
### `matches`
4949

5050
Usage: `//@ matches PATH XPATH PATTERN`
5151

52-
Checks that the text of each element selected by `XPATH` in `PATH` matches the python-flavored regex `PATTERN`.
52+
Checks that the text of each element selected by `XPATH` in `PATH` matches the Python-flavored regex `PATTERN`.
5353

5454
### `matchesraw`
5555

56-
Usage: `//@ matchesraw PATH PATTERN`
56+
Usage: `//@ matchesraw PATH XPATH PATTERN`
5757

5858
Checks that the contents of the file `PATH` matches the regex `PATTERN`.
5959

60+
<!-- FIXME(fmease): This previously didn't mention XPATH, mention it in prose -->
61+
6062
### `hasraw`
6163

62-
Usage: `//@ hasraw PATH PATTERN`
64+
Usage: `//@ hasraw PATH XPATH PATTERN`
6365

6466
Same as `matchesraw`, except `PATTERN` is a whitespace-normalized[^1] string instead of a regex.
67+
<!-- FIXME(fmease): It's more important to note *here* that the file under test gets normalized too (PATTERN is in 99% cases already normalized) -->
68+
69+
<!-- FIXME(fmease): This previously didn't mention XPATH, mention it in prose -->
6570

6671
### `count`
6772

@@ -79,9 +84,13 @@ determined by the XPath, and compares it to a pre-recorded value
7984
in a file. The file's name is the test's name with the `.rs` extension
8085
replaced with `.NAME.html`, where NAME is the snapshot's name.
8186

82-
htmldocck supports the `--bless` option to accept the current subtree
87+
HtmlDocCk supports the `--bless` option to accept the current subtree
8388
as expected, saving it to the file determined by the snapshot's name.
84-
compiletest's `--bless` flag is forwarded to htmldocck.
89+
compiletest's `--bless` flag is forwarded to HtmlDocCk.
90+
91+
<!-- FIXME(fmease): Also mention that we normalize certain URLS
92+
both when and checking and when normalizing
93+
-->
8594

8695
### `has-dir`
8796

@@ -94,19 +103,42 @@ Checks for the existence of directory `PATH`.
94103
Usage: `//@ files PATH ENTRIES`
95104

96105
Checks that the directory `PATH` contains exactly `ENTRIES`.
97-
`ENTRIES` is a python list of strings inside a quoted string,
106+
`ENTRIES` is a Python list of strings inside a quoted string,
98107
as if it were to be parsed by `eval`.
99108
(note that the list is actually parsed by `shlex.split`,
100-
so it cannot contain arbitrary python expressions).
109+
so it cannot contain arbitrary Python expressions).
101110

102111
Example: `//@ files "foo/bar" '["index.html", "sidebar-items.js"]'`
103112

104113
[^1]: Whitespace normalization means that all spans of consecutive whitespace are replaced with a single space. The files themselves are also whitespace-normalized.
105114

115+
## Compiletest Directives
116+
117+
In addition to the directives listed here,
118+
`rustdoc` tests also support most
119+
[compiletest directives](../tests/directives.html).
120+
121+
<!-- FIXME(fmease):
122+
Should definitely also mention `//@ aux-crate` and `//@ proc-macro`
123+
UNLESS we nuke this paragraph entirely and refer to the compiletest section(s)?
124+
-->
125+
To use multiple crates in a `rustdoc` test, add `//@ aux-build:filename.rs`
126+
to the top of the test file. `filename.rs` should be placed in an `auxiliary`
127+
directory relative to the test file with the comment.
128+
129+
<!-- FIXME(fmease): We might want to explain why this exists / what this actually means -->
130+
If you need to build docs for the auxiliary file, use `//@ build-aux-docs`.
131+
132+
<!-- FIXME(fmease): Mention `//@ doc-flags`! -->
133+
106134
## Limitations
107-
`htmldocck.py` uses the xpath implementation from the standard library.
135+
136+
HtmlDocCk uses the XPath implementation from the Python standard library.
108137
This leads to several limitations:
138+
109139
* All `XPATH` arguments must start with `//` due to a flaw in the implementation.
110140
* Many XPath features (functions, axies, etc.) are not supported.
111141
* Only well-formed HTML can be parsed (hopefully rustdoc doesn't output mismatched tags).
112142

143+
<!-- FIXME(fmease): Maybe link to revisions? -->
144+
Furthmore, compiletest revisions are not supported.

src/rustdoc.md

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,29 @@ does is call the `main()` that's in this crate's `lib.rs`, though.)
6767

6868
## Code structure
6969

70-
* All paths in this section are relative to `src/librustdoc` in the rust-lang/rust repository.
70+
All paths in this section are relative to `src/librustdoc/` in the rust-lang/rust repository.
71+
7172
* Most of the HTML printing code is in `html/format.rs` and `html/render/mod.rs`.
72-
It's in a bunch of `fmt::Display` implementations and supplementary
73-
functions.
74-
* The types that got `Display` impls above are defined in `clean/mod.rs`, right
75-
next to the custom `Clean` trait used to process them out of the rustc HIR.
73+
It's in a bunch of functions returning `impl std::fmt::Display`.
74+
* The data types that get rendered by the functions mentioned above are defined in `clean/types.rs`.
75+
The functions responsible for creating them from the `HIR` and the `rustc_middle::ty` IR
76+
live in `clean/mod.rs`.
7677
* The bits specific to using rustdoc as a test harness are in
7778
`doctest.rs`.
7879
* The Markdown renderer is loaded up in `html/markdown.rs`, including functions
7980
for extracting doctests from a given block of Markdown.
8081
* Frontend CSS and JavaScript are stored in `html/static/`.
82+
* Re. JavaScript, type annotations are written using [TypeScript-flavored JSDoc]
83+
comments and an external `.d.ts` file.
84+
This way, the code itself remains plain, valid JavaScript.
85+
We only use `tsc` as a linter.
8186

82-
## Tests
87+
[TypeScript-flavored JSDoc]: https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
8388

84-
* Tests on search engine and index are located in `tests/rustdoc-js` and `tests/rustdoc-js-std`.
85-
The format is specified
86-
[in the search guide](rustdoc-internals/search.md#testing-the-search-engine).
87-
* Tests on the "UI" of rustdoc (the terminal output it produces when run) are in
88-
`tests/rustdoc-ui`
89-
* Tests on the "GUI" of rustdoc (the HTML, JS, and CSS as rendered in a browser)
90-
are in `tests/rustdoc-gui`. These use a [NodeJS tool called
91-
browser-UI-test](https://github.com/GuillaumeGomez/browser-UI-test/) that uses
92-
puppeteer to run tests in a headless browser and check rendering and
93-
interactivity. For information on how to write this form of test,
94-
see [`tests/rustdoc-gui/README.md`][rustdoc-gui-readme]
95-
as well as [the description of the `.goml` format][goml-script]
96-
* Tests on the structure of rustdoc HTML output are located in `tests/rustdoc`,
97-
where they're handled by the test runner of bootstrap and
98-
the supplementary script `src/etc/htmldocck.py`.
99-
[These tests have several extra directives available to them](./rustdoc-internals/rustdoc-test-suite.md).
100-
* Additionally, JavaScript type annotations are written using [TypeScript-flavored JSDoc]
101-
comments and an external d.ts file. The code itself is plain, valid JavaScript; we only
102-
use tsc as a linter.
89+
## Tests
10390

104-
[TypeScript-flavored JSDoc]: https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
105-
[rustdoc-gui-readme]: https://github.com/rust-lang/rust/blob/master/tests/rustdoc-gui/README.md
106-
[goml-script]: https://github.com/GuillaumeGomez/browser-UI-test/blob/master/goml-script.md
91+
`rustdoc`'s integration tests are split across several test suites.
92+
See [Rustdoc tests suites](tests/compiletest.md#rustdoc-test-suites) for more details.
10793

10894
## Constraints
10995

src/tests/compiletest.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ incremental compilation. The various suites are defined in
5656

5757
The following test suites are available, with links for more information:
5858

59+
[`tests`]: https://github.com/rust-lang/rust/blob/master/tests
60+
[`src/tools/compiletest/src/common.rs`]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs
61+
5962
### Compiler-specific test suites
6063

6164
| Test suite | Purpose |
@@ -71,26 +74,31 @@ The following test suites are available, with links for more information:
7174
| [`mir-opt`](#mir-opt-tests) | Check MIR generation and optimizations |
7275
| [`coverage`](#coverage-tests) | Check coverage instrumentation |
7376
| [`coverage-run-rustdoc`](#coverage-tests) | `coverage` tests that also run instrumented doctests |
77+
| [`crashes`](#crashes-tests) | Check that the compiler ICEs/panics/crashes on certain inputs to catch accidental fixes |
7478

7579
### General purpose test suite
7680

7781
[`run-make`](#run-make-tests) are general purpose tests using Rust programs.
7882

7983
### Rustdoc test suites
8084

81-
See [Rustdoc tests](../rustdoc.md#tests) for more details.
82-
83-
| Test suite | Purpose |
84-
|------------------|--------------------------------------------------------------------------|
85-
| `rustdoc` | Check `rustdoc` generated files contain the expected documentation |
86-
| `rustdoc-gui` | Check `rustdoc`'s GUI using a web browser |
87-
| `rustdoc-js` | Check `rustdoc` search is working as expected |
88-
| `rustdoc-js-std` | Check rustdoc search is working as expected specifically on the std docs |
89-
| `rustdoc-json` | Check JSON output of `rustdoc` |
90-
| `rustdoc-ui` | Check terminal output of `rustdoc` |
91-
92-
[`tests`]: https://github.com/rust-lang/rust/blob/master/tests
93-
[`src/tools/compiletest/src/common.rs`]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs
85+
| Test suite | Purpose |
86+
|--------------------------------------|--------------------------------------------------------------------------|
87+
| [`rustdoc`][rustdoc-html-tests] | Check HTML output of `rustdoc` |
88+
| [`rustdoc-gui`][rustdoc-gui-tests] | Check `rustdoc`'s GUI using a web browser |
89+
| [`rustdoc-js`][rustdoc-js-tests] | Check `rustdoc`'s search engine and index |
90+
| [`rustdoc-js-std`][rustdoc-js-tests] | Check `rustdoc`'s search engine and index on the std library docs |
91+
| [`rustdoc-json`][rustdoc-json-tests] | Check JSON output of `rustdoc` |
92+
| `rustdoc-ui` | Check terminal output of `rustdoc` ([see also](ui.md)) |
93+
94+
<!-- FIXME(fmease): Also mention `tests/ui/rustdoc/`! -->
95+
<!-- | `tests/ui/rustdoc/` | |
96+
| `tests/run-make/rustdoc-*` | | -->
97+
98+
[rustdoc-html-tests]: ../rustdoc-internals/rustdoc-test-suite.md
99+
[rustdoc-gui-tests]: ../rustdoc-internals/rustdoc-gui-test-suite.md
100+
[rustdoc-js-tests]: ../rustdoc-internals/search.md#testing-the-search-engine
101+
[rustdoc-json-tests]: ../rustdoc-internals/rustdoc-json-test-suite.md
94102

95103
### Pretty-printer tests
96104

src/tests/directives.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,27 @@ Consider writing the test as a proper incremental test instead.
261261

262262
| Directive | Explanation | Supported test suites | Possible values |
263263
|-------------|--------------------------------------------------------------|------------------------------------------|---------------------------|
264-
| `doc-flags` | Flags passed to `rustdoc` when building the test or aux file | `rustdoc`, `rustdoc-js`, `rustdoc-json` | Any valid `rustdoc` flags |
264+
| `doc-flags` | Flags passed to `rustdoc` when building the test or aux file | `rustdoc`, `rustdoc-js`, `rustdoc-json` | Any valid `rustdoc` flags |
265265

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

272+
#### Test-suite-specific directives
273+
274+
The test suites [`rustdoc`][rustdoc-html-tests],
275+
[`rustdoc-js`/`rustdoc-js-std`][rustdoc-js-tests] and
276+
[`rustdoc-json`][rustdoc-json-tests]
277+
each feature an additional set of directives whose basic syntax resembles the one of
278+
compiletest directives but which are ultimately read and checked by separate tools.
279+
For more information, please read their respective chapters as linked above.
280+
281+
[rustdoc-html-tests]: ../rustdoc-internals/rustdoc-test-suite.md
282+
[rustdoc-js-tests]: ../rustdoc-internals/search.html#testing-the-search-engine
283+
[rustdoc-json-tests]: ../rustdoc-internals/rustdoc-json-test-suite.md
284+
272285
### Pretty printing
273286

274287
See [Pretty-printer](compiletest.md#pretty-printer-tests).

0 commit comments

Comments
 (0)