Skip to content

Commit a4a1a7c

Browse files
Ezrashawtshepang
authored andcommitted
docs: document new suggest-tests tool
1 parent 0ff2326 commit a4a1a7c

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [Test headers](./tests/headers.md)
2525
- [Performance testing](./tests/perf.md)
2626
- [Crater](./tests/crater.md)
27+
- [Suggest tests tool](./tests/suggest-tests.md)
2728
- [Debugging the compiler](./compiler-debugging.md)
2829
- [Using the tracing/logging instrumentation](./tracing.md)
2930
- [Profiling the compiler](./profiling.md)

src/building/suggested.md

+17
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ the problem. A nice side-effect of this style is that you are left
109109
with a fairly fine-grained set of commits at the end, all of which
110110
build and pass tests. This often helps reviewing.
111111

112+
## `x suggest`
113+
114+
The `x suggest` subcommand suggests (and runs) a subset of the extensive
115+
`rust-lang/rust` tests based on files you have changed. This is especially useful
116+
for new contributors who have not mastered the arcane `x` flags yet and more
117+
experienced contributors as a shorthand for reducing mental effort. In all cases
118+
it is useful not to run the full tests (which can take on the order of tens of
119+
minutes) and just run a subset which are relevant to your changes. For example,
120+
running `tidy` and `linkchecker` is useful when editing Markdown files, whereas UI
121+
tests are much less likely to be helpful. While `x suggest` is a useful tool, it
122+
does not guarantee perfect coverage (just as PR CI isn't a substitute for bors).
123+
See the [dedicated chapter](../tests/suggest-tests.md) for more information and
124+
contribution instructions.
125+
126+
Please note that `x suggest` is in a beta state currently and the tests that it
127+
will suggest are limited.
128+
112129
## Configuring `rustup` to use nightly
113130

114131
Some parts of the bootstrap process uses pinned, nightly versions of tools like

src/tests/suggest-tests.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Suggest tests tool
2+
3+
This chapter is about the internals of and contribution instructions for the
4+
`suggest-tests` tool. For a high-level overview of the tool, see
5+
[this section](../building/suggested.md#x-suggest). This tool is currently in a
6+
beta state and is tracked by [this](https://github.com/rust-lang/rust/issues/109933)
7+
issue on Github. Currently the number of tests it will suggest are very limited
8+
in scope, we are looking to expand this (contributions welcome!).
9+
10+
## Internals
11+
12+
The tool is defined in a separate crate ([`src/tools/suggest-tests`](https://github.com/rust-lang/rust/blob/master/src/tools/suggest-tests))
13+
which outputs suggestions which are parsed by a shim in bootstrap
14+
([`src/bootstrap/suggest.rs`](https://github.com/rust-lang/rust/blob/master/src/bootstrap/suggest.rs)).
15+
The only notable thing the bootstrap shim does is (when invoked with the
16+
`--run` flag) use bootstrap's internal mechanisms to create a new `Builder` and
17+
uses it to invoke the suggested commands. The `suggest-tests` crate is where the
18+
fun happens, two kinds of suggestions are defined: "static" and "dynamic"
19+
suggestions.
20+
21+
### Static suggestions
22+
23+
Defined [here](https://github.com/rust-lang/rust/blob/master/src/tools/suggest-tests/src/static_suggestions.rs).
24+
Static suggestions are simple: they are just [globs](https://crates.io/crates/glob)
25+
which map to a `x` command. In `suggest-tests`, this is implemented with a
26+
simple `macro_rules` macro.
27+
28+
### Dynamic suggestions
29+
30+
Defined [here](https://github.com/rust-lang/rust/blob/master/src/tools/suggest-tests/src/dynamic_suggestions.rs).
31+
These are more complicated than static suggestions and are implemented as
32+
functions with the following signature: `fn(&Path) -> Vec<Suggestion>`. In
33+
other words, each suggestion takes a path to a modified file and (after running
34+
arbitrary Rust code) can return any number of suggestions, or none. Dynamic
35+
suggestions are useful for situations where fine-grained control over
36+
suggestions is needed. For example, modifications to the `compiler/xyz/` path
37+
should trigger the `x test compiler/xyz` suggestion. In the future, dynamic
38+
suggestions might even read file contents to determine if (what) tests should
39+
run.
40+
41+
## Adding a suggestion
42+
43+
The following steps should serve as a rough guide to add suggestions to
44+
`suggest-tests` (very welcome!):
45+
46+
1. Determine the rules for your suggestion. Is it simple and operates only on
47+
a single path or does it match globs? Does it need fine-grained control over
48+
the resulting command or does "one size fit all"?
49+
2. Based on the previous step, decide if your suggestion should be implemented
50+
as either static or dynamic.
51+
3. Implement the suggestion. If it is dynamic then a test is highly recommended,
52+
to verify that your logic is correct and to give an example of the suggestion.
53+
See the [tests.rs](https://github.com/rust-lang/rust/blob/master/src/tools/suggest-tests/src/static_suggestions.rs)
54+
file.
55+
4. Open a PR implementing your suggestion. **(TODO: add example PR)**

0 commit comments

Comments
 (0)