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.
2217To 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
2421All 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
3633For 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
4039Usage 1: ` //@ has PATH `
4140Usage 2: ` //@ has PATH XPATH PATTERN `
4241
4342In 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 ` ,
4645except ` 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
5050Usage: ` //@ 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
5858Checks 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
6466Same 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
7984in a file. The file's name is the test's name with the ` .rs ` extension
8085replaced 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
8388as 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`.
94103Usage: ` //@ files PATH ENTRIES `
95104
96105Checks 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,
98107as 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
102111Example: ` //@ 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.
108137This 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.
0 commit comments