Skip to content

Commit b526170

Browse files
committed
More docs
1 parent 0fd4c18 commit b526170

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

src/compiler-src.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ itself is [`src/tools/rustdoc`], which does nothing except call [`rustdoc::main`
154154

155155
There is also `JavaScript` and `CSS` for the docs in [`src/tools/rustdoc-js`]
156156
and [`src/tools/rustdoc-themes`]. The type definitions for `--output-format=json`
157-
are in a seperate crate in [`src/rustdoc-json-types`].
157+
are in a separate crate in [`src/rustdoc-json-types`].
158158

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

src/rustdoc-internals/rustdoc-json-test-suite.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,81 @@
33
This page is specifically about the test suite named `rustdoc-json`, which tests rustdoc's [json output].
44
For other test suites used for testing rustdoc, see [Rustdoc tests](../rustdoc.md#tests).
55

6-
Tests are run with compiletest, and have access to the usuall set of [directives](../tests/directives.md).
6+
Tests are run with compiletest, and have access to the usual set of [directives](../tests/directives.md).
77
Frequenly used directives here are:
88

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

13-
Each crate's json output is checked by 2 programs: [jsondoclint] and [jsondocck].
13+
Each crate's json output is checked by 2 programs: [jsondoclint](#jsondocck) and [jsondocck](#jsondocck).
1414

1515
## jsondoclint
1616

1717
[jsondoclint] checks that all [`Id`]s exist in the `index` (or `paths`).
18-
This makes sure their are no dangling [`Id`]s.
18+
This makes sure there are no dangling [`Id`]s.
1919

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

2424
## jsondocck
2525

26-
<!-- TODO: shlex, jsonpath, values, variables -->
26+
[jsondocck] processes direcives given in comments, to assert that the values in the output are expected.
27+
It's alot like [htmldocck](./rustdoc-test-suite.md) in that way.
28+
29+
It uses [JSONPath] as a query language, which takes a path, and returns a *list* of values that that path is said to match to.
2730

2831
### Directives
2932

3033
- `//@ has <path>`:: Checks `<path>` exists, i.e. matches at least 1 value.
3134
- `//@ !has <path>`:: Checks `<path>` doesn't exist, i.e. matches 0 values.
32-
- `//@ has <path> <value>`: Check `<path>` exists, and 1 of the matches is equal to the given `<value>`
35+
- `//@ has <path> <value>`: Check `<path>` exists, and at least 1 of the matches is equal to the given `<value>`
3336
- `//@ !has <path> <value>`: Checks `<path>` exists, but none of the matches equal the given `<value>`.
34-
- `//@ is <path> <value>`: Check `<path>` matches exacly one value, and it's equal to the given `<value>`.
37+
- `//@ is <path> <value>`: Check `<path>` matches exactly one value, and it's equal to the given `<value>`.
3538
- `//@ is <path> <value> <value>...`: Check that `<path>` matches to exactly every given `<value>`.
3639
Ordering doesn't matter here.
3740
- `//@ !is <path> <value>`: Check `<path>` matches exactly one value, and that value is not equal to the given `<value>`.
3841
- `//@ count <path> <number>` Check that `<path>` matches to `<number>` of values.
42+
- `//@ set <name> = <path>`, Check that `<path>` matches exactly one value, and store that value to the variable called `<name>`
43+
44+
These are defined in [`directive.rs`].
45+
46+
### Values
47+
48+
Values can be either JSON values, or variables.
49+
50+
- JSON values are JSON literals, e.g. `true`, `"string"`, `{"key": "value"}`.
51+
These often need to be quoted using `'`, to be processed as 1 value. See [§Argument spliting](#argument-spliting)
52+
- Variables can be used to store the value in one path, and use it in later queries.
53+
They are set with the `//@ set <name> = <path>` directive, and accessed with `$<name>`
54+
55+
```rust
56+
//@ set foo = $some.path
57+
//@ is $.some.other.path $foo
58+
```
59+
60+
### Argument spliting
61+
62+
Arguments to directives are split using the [shlex] crate, which implements POSIX shell escaping.
63+
This is because both `<path>` and `<value>` arguments to [directives](#directives) frequently have both
64+
whitespace and quote marks.
65+
66+
To use the `@ is` with a `<path>` of `$.index[?(@.docs == "foo")].some.field` and a value of `"bar"` [^why quote], you'd write:
3967

68+
```rust
69+
//@ is '$.is[?(@.docs == "foo")].some.field' '"bar"'
70+
```
4071

72+
[^why quote]: The value needs to be `"bar"` *after* shlex splitting, because we
73+
it needs to be a JSON string value.
4174

4275
[json output]: https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#json-output
4376
[jsondocck]: https://github.com/rust-lang/rust/tree/master/src/tools/jsondocck
4477
[jsondoclint]: https://github.com/rust-lang/rust/tree/master/src/tools/jsondoclint
4578
[aux-build]: ../tests/compiletest.md#building-auxiliary-crates
4679
[`Id`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc_json_types/struct.Id.html
4780
[document private items]: https://doc.rust-lang.org/nightly/rustdoc/command-line-arguments.html#--document-private-items-show-items-that-are-not-public
81+
[`directive.rs`]: https://github.com/rust-lang/rust/blob/master/src/tools/jsondocck/src/directive.rs
82+
[shlex]: https://docs.rs/shlex/1.3.0/shlex/index.html
83+
[JSONPath]: https://www.rfc-editor.org/rfc/rfc9535.html

0 commit comments

Comments
 (0)