Skip to content

Start documenting tests/rustdoc-json #2422

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
- [Rustdoc internals](./rustdoc-internals.md)
- [Search](./rustdoc-internals/search.md)
- [The `rustdoc` test suite](./rustdoc-internals/rustdoc-test-suite.md)
- [The `rustdoc-json` test suite](./rustdoc-internals/rustdoc-json-test-suite.md)
- [Autodiff internals](./autodiff/internals.md)
- [Installation](./autodiff/installation.md)
- [How to debug](./autodiff/debugging.md)
Expand Down
4 changes: 3 additions & 1 deletion src/compiler-src.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ The bulk of [`rustdoc`] is in [`librustdoc`]. However, the [`rustdoc`] binary
itself is [`src/tools/rustdoc`], which does nothing except call [`rustdoc::main`].

There is also `JavaScript` and `CSS` for the docs in [`src/tools/rustdoc-js`]
and [`src/tools/rustdoc-themes`].
and [`src/tools/rustdoc-themes`]. The type definitions for `--output-format=json`
are in a seperate crate in [`src/rustdoc-json-types`].
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
are in a seperate crate in [`src/rustdoc-json-types`].
are in a separate crate in [`src/rustdoc-json-types`].


You can read more about [`rustdoc`] in [this chapter][rustdoc-chapter].

Expand All @@ -164,6 +165,7 @@ You can read more about [`rustdoc`] in [this chapter][rustdoc-chapter].
[`src/tools/rustdoc-js`]: https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc-js
[`src/tools/rustdoc-themes`]: https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc-themes
[`src/tools/rustdoc`]: https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc
[`src/rustdoc-json-types`]: https://github.com/rust-lang/rust/tree/master/src/rustdoc-json-types
[rustdoc-chapter]: ./rustdoc.md

## Tests
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ directly, even during `HTML` generation. This [didn't used to be the case], and
a lot of `rustdoc`'s architecture was designed around not doing that, but a
`TyCtxt` is now passed to `formats::renderer::run_format`, which is used to
run generation for both `HTML` and the
(unstable as of <!-- date-check --> March 2023) JSON format.
(unstable as of <!-- date-check --> May 2025) JSON format.

This change has allowed other changes to remove data from the "clean" [`AST`][ast]
that can be easily derived from `TyCtxt` queries, and we'll usually accept
Expand Down
47 changes: 47 additions & 0 deletions src/rustdoc-internals/rustdoc-json-test-suite.md
Copy link
Member

Choose a reason for hiding this comment

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# The `rustdoc-json` test suite

This page is specifically about the test suite named `rustdoc-json`, which tests rustdoc's [json output].
For other test suites used for testing rustdoc, see [Rustdoc tests](../rustdoc.md#tests).

Tests are run with compiletest, and have access to the usuall set of [directives](../tests/directives.md).
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
Tests are run with compiletest, and have access to the usuall set of [directives](../tests/directives.md).
Tests are run with compiletest, and have access to the usual set of [directives](../tests/directives.md).

Frequenly used directives here are:
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
Frequenly used directives here are:
Frequently used directives here are:


- [`//@ aux-build`][aux-build] to have dependencies.
- `//@ edition: 2021` (or some other edition).
- `//@ compile-flags: --document-hidden-items` to enable [document private items].

Each crate's json output is checked by 2 programs: [jsondoclint] and [jsondocck].

## jsondoclint

[jsondoclint] checks that all [`Id`]s exist in the `index` (or `paths`).
This makes sure their are no dangling [`Id`]s.
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 makes sure their are no dangling [`Id`]s.
This makes sure there are no dangling [`Id`]s.


<!-- TODO: It does some more things too?
Also, talk about how it works
-->

## jsondocck

<!-- TODO: shlex, jsonpath, values, variables -->

### Directives

- `//@ has <path>`:: Checks `<path>` exists, i.e. matches at least 1 value.
- `//@ !has <path>`:: Checks `<path>` doesn't exist, i.e. matches 0 values.
- `//@ has <path> <value>`: Check `<path>` exists, and 1 of the matches is equal to the given `<value>`
Copy link
Member

Choose a reason for hiding this comment

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

i imagine you mean "at least one", right? otherwise this is equivalent to @ is.

- `//@ !has <path> <value>`: Checks `<path>` exists, but none of the matches equal the given `<value>`.
- `//@ is <path> <value>`: Check `<path>` matches exacly one value, and it's equal to the given `<value>`.
- `//@ is <path> <value> <value>...`: Check that `<path>` matches to exactly every given `<value>`.
Ordering doesn't matter here.
- `//@ !is <path> <value>`: Check `<path>` matches exactly one value, and that value is not equal to the given `<value>`.
- `//@ count <path> <number>` Check that `<path>` matches to `<number>` of values.
Comment on lines +30 to +38
Copy link
Member

Choose a reason for hiding this comment

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

can you link to an exhaustive reference of the directives? source code is fine, just somewhere to look if a new directive gets added and i can't find it in the dev guide.




[json output]: https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#json-output
[jsondocck]: https://github.com/rust-lang/rust/tree/master/src/tools/jsondocck
[jsondoclint]: https://github.com/rust-lang/rust/tree/master/src/tools/jsondoclint
[aux-build]: ../tests/compiletest.md#building-auxiliary-crates
[`Id`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types/struct.Id.html
[document private items]: https://doc.rust-lang.org/nightly/rustdoc/command-line-arguments.html#--document-private-items-show-items-that-are-not-public