1
1
# The ` rustdoc ` test suite
2
2
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 ] .
5
5
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] .
9
8
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
10
11
[ XPath ] : https://en.wikipedia.org/wiki/XPath
11
12
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
14
14
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.
18
16
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.
22
17
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.
23
20
24
21
All arguments take the form of quoted strings
25
22
(both single and double quotes are supported),
@@ -35,33 +32,41 @@ In this case, the start of the next line should be `//`, with no `@`.
35
32
36
33
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.
37
34
35
+ <!-- FIXME(fmease): Mention that the regexes match case-sensitively and in single-line mode? -->
36
+
38
37
### ` has `
39
38
40
39
Usage 1: ` //@ has PATH `
41
40
Usage 2: ` //@ has PATH XPATH PATTERN `
42
41
43
42
In the first form, ` has ` checks that a given file exists.
44
43
45
- In the second form, ` has ` is an alias for ` matches ` ,
44
+ In the second form, ` has ` is the same as ` matches ` ,
46
45
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) -->
47
47
48
48
### ` matches `
49
49
50
50
Usage: ` //@ matches PATH XPATH PATTERN `
51
51
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 ` .
53
53
54
54
### ` matchesraw `
55
55
56
- Usage: ` //@ matchesraw PATH PATTERN `
56
+ Usage: ` //@ matchesraw PATH XPATH PATTERN `
57
57
58
58
Checks that the contents of the file ` PATH ` matches the regex ` PATTERN ` .
59
59
60
+ <!-- FIXME(fmease): This previously didn't mention XPATH, mention it in prose -->
61
+
60
62
### ` hasraw `
61
63
62
- Usage: ` //@ hasraw PATH PATTERN `
64
+ Usage: ` //@ hasraw PATH XPATH PATTERN `
63
65
64
66
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 -->
65
70
66
71
### ` count `
67
72
@@ -79,9 +84,13 @@ determined by the XPath, and compares it to a pre-recorded value
79
84
in a file. The file's name is the test's name with the ` .rs ` extension
80
85
replaced with ` .NAME.html ` , where NAME is the snapshot's name.
81
86
82
- htmldocck supports the ` --bless ` option to accept the current subtree
87
+ HtmlDocCk supports the ` --bless ` option to accept the current subtree
83
88
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
+ -->
85
94
86
95
### ` has-dir `
87
96
@@ -94,19 +103,42 @@ Checks for the existence of directory `PATH`.
94
103
Usage: ` //@ files PATH ENTRIES `
95
104
96
105
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,
98
107
as if it were to be parsed by ` eval ` .
99
108
(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).
101
110
102
111
Example: ` //@ files "foo/bar" '["index.html", "sidebar-items.js"]' `
103
112
104
113
[ ^ 1 ] : Whitespace normalization means that all spans of consecutive whitespace are replaced with a single space. The files themselves are also whitespace-normalized.
105
114
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
+
106
134
## Limitations
107
- ` htmldocck.py ` uses the xpath implementation from the standard library.
135
+
136
+ HtmlDocCk uses the XPath implementation from the Python standard library.
108
137
This leads to several limitations:
138
+
109
139
* All ` XPATH ` arguments must start with ` // ` due to a flaw in the implementation.
110
140
* Many XPath features (functions, axies, etc.) are not supported.
111
141
* Only well-formed HTML can be parsed (hopefully rustdoc doesn't output mismatched tags).
112
142
143
+ <!-- FIXME(fmease): Maybe link to revisions? -->
144
+ Furthmore, compiletest revisions are not supported.
0 commit comments