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 test suites.

Tests are run with compiletest, and have access to the usual set of directives. Frequently used directives here are:

Each crate’s json output is checked by 2 programs: jsondoclint and jsondocck.

jsondoclint

jsondoclint checks that all Ids exist in the index (or paths). This makes sure there are no dangling Ids.

jsondocck

jsondocck processes directives given in comments, to assert that the values in the output are expected. It’s a lot like htmldocck in that way.

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.

Directives

These are defined in directive.rs.

Values

Values can be either JSON values, or variables.

Argument splitting

Arguments to directives are split using the shlex crate, which implements POSIX shell escaping. This is because both <path> and <value> arguments to directives frequently have both whitespace and quote marks.

To use the @ is with a <path> of $.index[?(@.docs == "foo")].some.field and a value of "bar" 1, you’d write:

//@ is '$.is[?(@.docs == "foo")].some.field' '"bar"'
  1. The value needs to be "bar" after shlex splitting, because we it needs to be a JSON string value. ↩