Skip to content

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 8 commits into from
Mar 20, 2025

Conversation

lolbinarycat
Copy link
Contributor

Currently this stuff is only documented in a comment at the start of htmldocck.py, and that commend is very outdated and often missing important details, like the fact that has and matches are accept different kinds of patterns.

@fmease fmease self-assigned this Mar 18, 2025
@fmease fmease added S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content T-rustdoc Relevant to rustdoc team labels Mar 18, 2025
Copy link
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. I have a couple of comments!

@fmease
Copy link
Member

fmease commented Mar 18, 2025

Also CC @GuillaumeGomez @notriddle

@lolbinarycat
Copy link
Contributor Author

@fmease I think I've managed to address all your comments in a way I'm satisfied with, does this look good?

@jieyouxu
Copy link
Member

Merging since rustdoc maintainers approved, can always be improved in follow-ups.

@jieyouxu
Copy link
Member

(rust-lang/team#1704 will allow rustdoc maintainers to have write access to this repo, since it makes no sense if the rustdoc experts can't merge rustdoc doc changes.)

@jieyouxu jieyouxu merged commit 047ccc0 into rust-lang:master Mar 20, 2025
1 check passed
@fmease
Copy link
Member

fmease commented Mar 20, 2025

Noo, my review wasn't done (this still has several smallish issues) :/ I'll create a follow-up PR

@jieyouxu
Copy link
Member

Oh sorry :(


The `rustdoc` test suite is specifically used to test the HTML output of rustdoc.

This is achived by means of `htmldocck.py`, a custom checker script that leverages [XPath].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is achived by means of `htmldocck.py`, a custom checker script that leverages [XPath].
This is achieved by means of `htmldocck.py`, a custom checker script that leverages [XPath].


Usage: `//@ matches PATH XPATH PATTERN`

Checks that the text of each element selected by `XPATH` in `PATH` matches the python-flavored regex `PATTERN`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


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

In the second form, `has` is an alias for `matches`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the second form, `has` is an alias for `matches`,
In the second form, `has` is the same as `matches`,

If it's not the same it's not an alias :)


Usage: `//@ has-dir PATH`

Checks for the existance of directory `PATH`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Checks for the existance of directory `PATH`.
Checks for the existence of directory `PATH`.

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

## Limitations
`htmldocck.py` uses the xpath implementation from the standard library.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`htmldocck.py` uses the xpath implementation from the standard library.
`htmldocck.py` uses the XPath implementation from the standard library.

Comment on lines +96 to +99
`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).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`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).
`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).


### `hasraw`

Usage: `//@ hasraw PATH PATTERN`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Usage: `//@ hasraw PATH PATTERN`
Usage: `//@ hasraw PATH XPATH PATTERN`

+ extending prose description


### `matchesraw`

Usage: `//@ matchesraw PATH PATTERN`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Usage: `//@ matchesraw PATH PATTERN`
Usage: `//@ matchesraw PATH XPATH PATTERN`

+ extending prose description


Usage: `//@ hasraw PATH PATTERN`

Same as `matchesraw`, except `PATTERN` is a whitespace-normalized[^1] string instead of a regex.
Copy link
Member

@fmease fmease Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only mentions in the footnote that file's contents are also whitespace normalized. However, that's arguably more important (in 99% cases the PATTERN the test author writes is normalized already). This should be the other way around.

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.
Copy link
Member

@fmease fmease Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@fmease
Copy link
Member

fmease commented Mar 20, 2025

Also this should've been squashed ^^' (the last 7 commits were just fixups and thus should't've become part of the final history)

@jieyouxu
Copy link
Member

Noo, my review wasn't done (this still has several smallish issues) :/ I'll create a follow-up PR

I can address some of the stuff you mentioned unless you already have changes locally, I'll also add a bit more on how this is wired up between bootstrap <-> rustdoc test suites.

(Sorry)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://rustc-dev-guide.rust-lang.org/rustdoc-internals.html#dotting-is-and-crossing-ts already mentions htmldocck albeit more briefly. Furthermore it mentions useful compiletest directives like //@ build-aux-docs.

We should remove this section and import some of the additional pieces of information into this document. We should also mention compiletest directive //@ doc-flags.

@fmease
Copy link
Member

fmease commented Mar 20, 2025

I already have my editor open and will open a PR in <30 minutes I guess. Feel free to add extra information after that :)

`rustdoc` tests also support most
[compiletest directives](../tests/directives.html).

All `PATH`s in directives are relative to the the rustdoc output directory (`build/TARGET/test/rustdoc/TESTNAME`),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm confusing myself, if you say the path is relative to build/$TARGET/test/rustdoc/$CRATE_NAME I would think a path like foo/fn.bar.html would expand to build/$TARGET/test/rustdoc/foo/foo/fn.bar.html assuming the crate name is foo (notice the double foo/).

I would describe it as relative to build/$TARGET/test/rustdoc/ in which case this sentence merely describes an implementation detail of compiletest which the test writer shouldn't need to worry about.

Copy link
Member

@jieyouxu jieyouxu Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tests/rustdoc supposed to support revisions? I'm assuming the answer is "no", but I don't see it being explicitly rejected.

(Asking because revision is part of the output dir name mangling)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're currently rejected by compiletest (via an assert) since htmldocck.py has no notion of that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, https://github.com/rust-lang/rust/blob/4e2b096ed6c8a1400624a54f6c4fd0c0ce48a579/src/tools/compiletest/src/runtest/rustdoc.rs#L7. I was looking at another place where I did the rejection 💀 I should fix that as part of the compiletest directive handling rework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content T-rustdoc Relevant to rustdoc team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants