-
Notifications
You must be signed in to change notification settings - Fork 546
add new section on the rustdoc
test suite
#2295
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f00643a
add new section on the `rustdoc` test suite
lolbinarycat 8b50156
add htmldocck.md to SUMMARY.md
lolbinarycat f248d2f
htmldocck: expand limitations and mention compiletest directives
lolbinarycat 72aa06d
rustdoc test suite: clean up wording and intro
lolbinarycat 174678d
rename htmldocck.md -> rustdoc-test-suite.md
lolbinarycat 2e1c499
clean up wording/grammar and mention double quotes
lolbinarycat 871280d
normalize link titles
lolbinarycat 59f11cd
update filename in link
lolbinarycat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# `rustdoc` tests | ||
lolbinarycat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
This page is specifically about the `rustdoc` test suite, for other test suites used for testing rustdoc, see [Rustdoc § Tests](../rustdoc.md#tests). | ||
lolbinarycat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
`htmldocck.py` is a custom checker script that uses [XPath] to verify the HTML output of rustdoc. | ||
|
||
[XPath]: https://en.wikipedia.org/wiki/XPath | ||
|
||
## Directives | ||
Directives to htmldocck are similar to those given to `compiletest` in that they take the form of `//@` comments. | ||
lolbinarycat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
All `PATH`s in directives are relative to the the rustdoc output directory (`build/TARGET/test/rustdoc/TESTNAME`), | ||
so it is conventional to use a `#![crate_name = "foo"]` attribute to avoid writing paths. | ||
lolbinarycat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
To avoid repetion, `-` can be used in any `PATH` argument to re-use the previous `PATH` argument. | ||
|
||
All arguments take the form of quoted strings, | ||
lolbinarycat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with the exception of `COUNT` and the special `-` form of `PATH`. | ||
|
||
Directives are assertions that place constraints on the generated HTML. | ||
|
||
All directives (except `files`) can be negated by putting a `!` in front of their name. | ||
|
||
Similar to shell commands, | ||
directives can extend across multiple lines if their last char is `\`. | ||
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. | ||
|
||
### `has` | ||
|
||
Usage 1: `//@ has PATH` | ||
Usage 2: `//@ has PATH XPATH PATTERN` | ||
|
||
In the first form, `has` checks that a given file exists. | ||
|
||
In the second form, `has` is an alias for `matches`, | ||
except `PATTERN` is a whitespace-normalized[^1] string instead of a regex. | ||
|
||
### `matches` | ||
|
||
Usage: `//@ matches PATH XPATH PATTERN` | ||
|
||
Checks that the text of each element selected by `XPATH` in `PATH` matches the python-flavored regex `PATTERN`. | ||
|
||
### `matchesraw` | ||
|
||
Usage: `//@ matchesraw PATH PATTERN` | ||
|
||
Checks that the contents of the file `PATH` matches the regex `PATTERN`. | ||
|
||
### `hasraw` | ||
|
||
Usage: `//@ hasraw PATH PATTERN` | ||
|
||
Same as `matchesraw`, except `PATTERN` is a whitespace-normalized[^1] string instead of a regex. | ||
|
||
### `count` | ||
|
||
Usage: `//@ count PATH XPATH COUNT` | ||
|
||
Checks that there are exactly `COUNT` matches for `XPATH` within the file `PATH`. | ||
|
||
### `snapshot` | ||
|
||
Usage: `//@ snapshot NAME PATH XPATH` | ||
|
||
Creates a snapshot test named NAME. | ||
A snapshot test captures a subtree of the DOM, at the location | ||
determined by the XPath, and compares it to a pre-recorded value | ||
in a file. The file's name is the test's name with the `.rs` extension | ||
replaced with `.NAME.html`, where NAME is the snapshot's name. | ||
|
||
htmldocck supports the `--bless` option to accept the current subtree | ||
as expected, saving it to the file determined by the snapshot's name. | ||
compiletest's `--bless` flag is forwarded to htmldocck. | ||
|
||
### `has-dir` | ||
|
||
Usage: `//@ has-dir PATH` | ||
|
||
Checks for the existance of directory `PATH`. | ||
|
||
### `files` | ||
|
||
Usage: `//@ files PATH ENTRIES` | ||
|
||
Checks that the directory `PATH` contains exactly `ENTRIES`. | ||
`ENTRIES` is a python list of strings inside a quoted string, | ||
as if it were to be parsed by `eval`. | ||
(note that the list is actually parsed by `shlex.split`, | ||
so it cannot contain arbitrary python expressions). | ||
|
||
Example: `//@ files "foo/bar" '["index.html", "sidebar-items.js"]'` | ||
|
||
[^1]: Whitespace normalization means that all spans of consecutive whitespace are replaced with a single space. The files themselves are also whitespace-normalized. | ||
|
||
## Limitations | ||
All `XPATH` arguments must start with `//` due to a flaw in the implemention. | ||
lolbinarycat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Only well-formed HTML can be parsed (hopefully rustdoc doesn't output mismatched tags). | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.