Skip to content

Commit 191778d

Browse files
authored
Merge pull request #2637 from rust-lang/tshepang/sembr
sembr tests/running.md and improve it a bit
2 parents 2ae4b0b + 6e14d2a commit 191778d

File tree

2 files changed

+100
-80
lines changed

2 files changed

+100
-80
lines changed

src/doc/rustc-dev-guide/ci/sembr/src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ fn lengthen_lines(content: &str, limit: usize) -> String {
137137
let mut new_content = content.clone();
138138
let mut new_n = 0;
139139
let mut in_code_block = false;
140+
let mut in_html_div = false;
140141
let mut skip_next = false;
141142
for (n, line) in content.iter().enumerate() {
142143
if skip_next {
@@ -150,6 +151,17 @@ fn lengthen_lines(content: &str, limit: usize) -> String {
150151
in_code_block = !in_code_block;
151152
continue;
152153
}
154+
if line.trim_start().starts_with("<div") {
155+
in_html_div = true;
156+
continue;
157+
}
158+
if line.trim_start().starts_with("</div") {
159+
in_html_div = false;
160+
continue;
161+
}
162+
if in_html_div {
163+
continue;
164+
}
153165
if ignore(line, in_code_block) || REGEX_SPLIT.is_match(line) {
154166
continue;
155167
}
@@ -215,9 +227,15 @@ fn test_prettify() {
215227
let original = "\
216228
do not split
217229
short sentences
230+
<div class='warning'>
231+
a bit of text inside
232+
</div>
218233
";
219234
let expected = "\
220235
do not split short sentences
236+
<div class='warning'>
237+
a bit of text inside
238+
</div>
221239
";
222240
assert_eq!(expected, lengthen_lines(original, 50));
223241
}

src/doc/rustc-dev-guide/src/tests/running.md

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Running tests
22

3-
You can run the entire test collection using `x`. But note that running the
4-
*entire* test collection is almost never what you want to do during local
5-
development because it takes a really long time. For local development, see the
6-
subsection after on how to run a subset of tests.
3+
You can run the entire test collection using `x`.
4+
But note that running the *entire* test collection is almost never what you want to do during local
5+
development because it takes a really long time.
6+
For local development, see the subsection after on how to run a subset of tests.
77

88
<div class="warning">
99

10-
Running plain `./x test` will build the stage 1 compiler and then run the whole
11-
test suite. This not only includes `tests/`, but also `library/`, `compiler/`,
10+
Running plain `./x test` will build the stage 1 compiler and then run the whole test suite.
11+
This not only includes `tests/`, but also `library/`, `compiler/`,
1212
`src/tools/` package tests and more.
1313

1414
You usually only want to run a subset of the test suites (or even a smaller set
15-
of tests than that) which you expect will exercise your changes. PR CI exercises
16-
a subset of test collections, and merge queue CI will exercise all of the test
15+
of tests than that) which you expect will exercise your changes.
16+
PR CI exercises a subset of test collections, and merge queue CI will exercise all of the test
1717
collection.
1818

1919
</div>
@@ -22,8 +22,8 @@ collection.
2222
./x test
2323
```
2424

25-
The test results are cached and previously successful tests are `ignored` during
26-
testing. The stdout/stderr contents as well as a timestamp file for every test
25+
The test results are cached and previously successful tests are `ignored` during testing.
26+
The stdout/stderr contents as well as a timestamp file for every test
2727
can be found under `build/<target-tuple>/test/` for the given
2828
`<target-tuple>`. To force-rerun a test (e.g. in case the test runner fails to
2929
notice a change) you can use the `--force-rerun` CLI option.
@@ -40,18 +40,17 @@ notice a change) you can use the `--force-rerun` CLI option.
4040
4141
## Running a subset of the test suites
4242

43-
When working on a specific PR, you will usually want to run a smaller set of
44-
tests. For example, a good "smoke test" that can be used after modifying rustc
43+
When working on a specific PR, you will usually want to run a smaller set of tests.
44+
For example, a good "smoke test" that can be used after modifying rustc
4545
to see if things are generally working correctly would be to exercise the `ui`
4646
test suite ([`tests/ui`]):
4747

4848
```text
4949
./x test tests/ui
5050
```
5151

52-
Of course, the choice of test suites is
53-
somewhat arbitrary, and may not suit the task you are doing. For example, if you
54-
are hacking on debuginfo, you may be better off with the debuginfo test suite:
52+
Of course, the choice of test suites is somewhat arbitrary, and may not suit the task you are doing.
53+
For example, if you are hacking on debuginfo, you may be better off with the debuginfo test suite:
5554

5655
```text
5756
./x test tests/debuginfo
@@ -77,8 +76,8 @@ Likewise, you can test a single file by passing its path:
7776
./x test tests/ui/const-generics/const-test.rs
7877
```
7978

80-
`x` doesn't support running a single tool test by passing its path yet. You'll
81-
have to use the `--test-args` argument as described
79+
`x` doesn't support running a single tool test by passing its path yet.
80+
You'll have to use the `--test-args` argument as described
8281
[below](#running-an-individual-test).
8382

8483
```text
@@ -97,8 +96,8 @@ have to use the `--test-args` argument as described
9796
./x test --stage 0 library/std
9897
```
9998

100-
Note that this only runs tests on `std`; if you want to test `core` or other
101-
crates, you have to specify those explicitly.
99+
Note that this only runs tests on `std`;
100+
if you want to test `core` or other crates, you have to specify those explicitly.
102101

103102
### Run the tidy script and tests on the standard library
104103

@@ -117,8 +116,8 @@ you avoid having to run tests for components you did not change at all.
117116

118117
<div class="warning">
119118

120-
Note that bors only runs the tests with the full stage 2 build; therefore, while
121-
the tests **usually** work fine with stage 1, there are some limitations.
119+
Note that bors only runs the tests with the full stage 2 build;
120+
therefore, while the tests **usually** work fine with stage 1, there are some limitations.
122121

123122
</div>
124123

@@ -129,7 +128,8 @@ the tests **usually** work fine with stage 1, there are some limitations.
129128
```
130129

131130
<div class="warning">
132-
You almost never need to do this; CI will run these tests for you.
131+
You almost never need to do this;
132+
CI will run these tests for you.
133133
</div>
134134

135135
## Run unit tests on the compiler/library
@@ -140,7 +140,8 @@ You may want to run unit tests on a specific file with following:
140140
./x test compiler/rustc_data_structures/src/thin_vec/tests.rs
141141
```
142142

143-
But unfortunately, it's impossible. You should invoke the following instead:
143+
But unfortunately, it's impossible.
144+
You should invoke the following instead:
144145

145146
```text
146147
./x test compiler/rustc_data_structures/ --test-args thin_vec
@@ -149,24 +150,23 @@ But unfortunately, it's impossible. You should invoke the following instead:
149150
## Running an individual test
150151

151152
Another common thing that people want to do is to run an **individual test**,
152-
often the test they are trying to fix. As mentioned earlier, you may pass the
153-
full file path to achieve this, or alternatively one may invoke `x` with the
154-
`--test-args` option:
153+
often the test they are trying to fix.
154+
As mentioned earlier, you may pass the
155+
full file path to achieve this, or alternatively one may invoke `x` with the `--test-args` option:
155156

156157
```text
157158
./x test tests/ui --test-args issue-1234
158159
```
159160

160161
Under the hood, the test runner invokes the standard Rust test runner (the same
161162
one you get with `#[test]`), so this command would wind up filtering for tests
162-
that include "issue-1234" in the name. Thus, `--test-args` is a good way to run
163-
a collection of related tests.
163+
that include "issue-1234" in the name.
164+
Thus, `--test-args` is a good way to run a collection of related tests.
164165

165166
## Passing arguments to `rustc` when running tests
166167

167168
It can sometimes be useful to run some tests with specific compiler arguments,
168-
without using `RUSTFLAGS` (during development of unstable features, with `-Z`
169-
flags, for example).
169+
without using `RUSTFLAGS` (during development of unstable features, with `-Z` flags, for example).
170170

171171
This can be done with `./x test`'s `--compiletest-rustc-args` option, to pass
172172
additional arguments to the compiler when building the tests.
@@ -176,8 +176,7 @@ additional arguments to the compiler when building the tests.
176176
If you have changed the compiler's output intentionally, or you are making a new
177177
test, you can pass `--bless` to the test subcommand.
178178

179-
As an example,
180-
if some tests in `tests/ui` are failing, you can run this command:
179+
As an example, if some tests in `tests/ui` are failing, you can run this command:
181180

182181
```text
183182
./x test tests/ui --bless
@@ -192,8 +191,9 @@ just like when running the tests without the `--bless` flag.
192191
There are a few options for running tests:
193192

194193
* `bootstrap.toml` has the `rust.verbose-tests` option. If `false`, each test will
195-
print a single dot (the default). If `true`, the name of every test will be
196-
printed. This is equivalent to the `--quiet` option in the [Rust test
194+
print a single dot (the default).
195+
If `true`, the name of every test will be printed.
196+
This is equivalent to the `--quiet` option in the [Rust test
197197
harness](https://doc.rust-lang.org/rustc/tests/).
198198
* The environment variable `RUST_TEST_THREADS` can be set to the number of
199199
concurrent threads to use for testing.
@@ -202,24 +202,24 @@ There are a few options for running tests:
202202

203203
Pass UI tests now have three modes, `check-pass`, `build-pass` and `run-pass`.
204204
When `--pass $mode` is passed, these tests will be forced to run under the given
205-
`$mode` unless the directive `//@ ignore-pass` exists in the test file. For
206-
example, you can run all the tests in `tests/ui` as `check-pass`:
205+
`$mode` unless the directive `//@ ignore-pass` exists in the test file.
206+
For example, you can run all the tests in `tests/ui` as `check-pass`:
207207

208208
```text
209209
./x test tests/ui --pass check
210210
```
211211

212-
By passing `--pass $mode`, you can reduce the testing time. For each mode,
213-
please see [Controlling pass/fail
212+
By passing `--pass $mode`, you can reduce the testing time.
213+
For each mode, please see [Controlling pass/fail
214214
expectations](ui.md#controlling-passfail-expectations).
215215

216216
## Running tests with different "compare modes"
217217

218-
UI tests may have different output depending on certain "modes" that the
219-
compiler is in. For example, when using the Polonius mode, a test `foo.rs` will
218+
UI tests may have different output depending on certain "modes" that the compiler is in.
219+
For example, when using the Polonius mode, a test `foo.rs` will
220220
first look for expected output in `foo.polonius.stderr`, falling back to the
221-
usual `foo.stderr` if not found. The following will run the UI test suite in
222-
Polonius mode:
221+
usual `foo.stderr` if not found.
222+
The following will run the UI test suite in Polonius mode:
223223

224224
```text
225225
./x test tests/ui --compare-mode=polonius
@@ -229,66 +229,68 @@ See [Compare modes](compiletest.md#compare-modes) for more details.
229229

230230
## Running tests manually
231231

232-
Sometimes it's easier and faster to just run the test by hand. Most tests are
233-
just `.rs` files, so after [creating a rustup
232+
Sometimes it's easier and faster to just run the test by hand.
233+
Most tests are just `.rs` files, so after [creating a rustup
234234
toolchain](../building/how-to-build-and-run.md#creating-a-rustup-toolchain), you
235235
can do something like:
236236

237237
```text
238238
rustc +stage1 tests/ui/issue-1234.rs
239239
```
240240

241-
This is much faster, but doesn't always work. For example, some tests include
241+
This is much faster, but doesn't always work.
242+
For example, some tests include
242243
directives that specify specific compiler flags, or which rely on other crates,
243244
and they may not run the same without those options.
244245

245246
## Running tests on a remote machine
246247

247248
Tests may be run on a remote machine (e.g. to test builds for a different
248-
architecture). This is done using `remote-test-client` on the build machine to
249+
architecture).
250+
This is done using `remote-test-client` on the build machine to
249251
send test programs to `remote-test-server` running on the remote machine.
250-
`remote-test-server` executes the test programs and sends the results back to
251-
the build machine. `remote-test-server` provides *unauthenticated remote code
252+
`remote-test-server` executes the test programs and sends the results back to the build machine.
253+
`remote-test-server` provides *unauthenticated remote code
252254
execution* so be careful where it is used.
253255

254-
To do this, first build `remote-test-server` for the remote machine, e.g. for
255-
RISC-V
256+
To do this, first build `remote-test-server` for the remote machine
257+
(using RISC-V as an example):
256258

257259
```text
258260
./x build src/tools/remote-test-server --target riscv64gc-unknown-linux-gnu
259261
```
260262

261-
The binary will be created at
262-
`./build/host/stage2-tools/$TARGET_ARCH/release/remote-test-server`. Copy this
263-
over to the remote machine.
263+
The binary will be created at `./build/host/stage2-tools/$TARGET_ARCH/release/remote-test-server`.
264+
Copy this over to the remote machine.
264265

265266
On the remote machine, run the `remote-test-server` with the `--bind
266-
0.0.0.0:12345` flag (and optionally `-v` for verbose output). Output should look
267-
like this:
267+
0.0.0.0:12345` flag (and optionally `--verbose` flag).
268+
Output should look like this:
268269

269-
```text
270-
$ ./remote-test-server -v --bind 0.0.0.0:12345
270+
```console
271+
$ ./remote-test-server --verbose --bind 0.0.0.0:12345
271272
starting test server
272273
listening on 0.0.0.0:12345!
273274
```
274275

275276
Note that binding the server to 0.0.0.0 will allow all hosts able to reach your
276-
machine to execute arbitrary code on your machine. We strongly recommend either
277+
machine to execute arbitrary code on your machine.
278+
We strongly recommend either
277279
setting up a firewall to block external access to port 12345, or to use a more
278280
restrictive IP address when binding.
279281

280-
You can test if the `remote-test-server` is working by connecting to it and
281-
sending `ping\n`. It should reply `pong`:
282+
You can test if the `remote-test-server` is working by connecting to it and sending `ping\n`.
283+
It should reply `pong`:
282284

283-
```text
285+
```console
284286
$ nc $REMOTE_IP 12345
285287
ping
286288
pong
287289
```
288290

289291
To run tests using the remote runner, set the `TEST_DEVICE_ADDR` environment
290-
variable then use `x` as usual. For example, to run `ui` tests for a RISC-V
291-
machine with the IP address `1.2.3.4` use
292+
variable then use `x` as usual.
293+
For example, to run `ui` tests for a RISC-V machine with the IP address `1.2.3.4` use
292294

293295
```text
294296
export TEST_DEVICE_ADDR="1.2.3.4:12345"
@@ -315,34 +317,34 @@ run "/tmp/work/test1018/a"
315317
[...]
316318
```
317319

318-
Tests are built on the machine running `x` not on the remote machine. Tests
319-
which fail to build unexpectedly (or `ui` tests producing incorrect build
320+
Tests are built on the machine running `x` not on the remote machine.
321+
Tests which fail to build unexpectedly (or `ui` tests producing incorrect build
320322
output) may fail without ever running on the remote machine.
321323

322324
## Testing on emulators
323325

324-
Some platforms are tested via an emulator for architectures that aren't readily
325-
available. For architectures where the standard library is well supported and
326+
Some platforms are tested via an emulator for architectures that aren't readily available.
327+
For architectures where the standard library is well supported and
326328
the host operating system supports TCP/IP networking, see the above instructions
327329
for testing on a remote machine (in this case the remote machine is emulated).
328330

329-
There is also a set of tools for orchestrating running the tests within the
330-
emulator. Platforms such as `arm-android` and `arm-unknown-linux-gnueabihf` are
331-
set up to automatically run the tests under emulation on GitHub Actions. The
332-
following will take a look at how a target's tests are run under emulation.
331+
There is also a set of tools for orchestrating running the tests within the emulator.
332+
Platforms such as `arm-android` and `arm-unknown-linux-gnueabihf` are
333+
set up to automatically run the tests under emulation on GitHub Actions.
334+
The following will take a look at how a target's tests are run under emulation.
333335

334-
The Docker image for [armhf-gnu] includes [QEMU] to emulate the ARM CPU
335-
architecture. Included in the Rust tree are the tools [remote-test-client] and
336+
The Docker image for [armhf-gnu] includes [QEMU] to emulate the ARM CPU architecture.
337+
Included in the Rust tree are the tools [remote-test-client] and
336338
[remote-test-server] which are programs for sending test programs and libraries
337-
to the emulator, and running the tests within the emulator, and reading the
338-
results. The Docker image is set up to launch `remote-test-server` and the
339+
to the emulator, and running the tests within the emulator, and reading the results.
340+
The Docker image is set up to launch `remote-test-server` and the
339341
build tools use `remote-test-client` to communicate with the server to
340342
coordinate running tests (see [src/bootstrap/src/core/build_steps/test.rs]).
341343

342-
To run on the iOS/tvOS/watchOS/visionOS simulator, we can similarly treat it as
343-
a "remote" machine. A curious detail here is that the network is shared between
344-
the simulator instance and the host macOS, so we can use the local loopback
345-
address `127.0.0.1`. Something like the following should work:
344+
To run on the iOS/tvOS/watchOS/visionOS simulator, we can similarly treat it as a "remote" machine.
345+
A curious detail here is that the network is shared between
346+
the simulator instance and the host macOS, so we can use the local loopback address `127.0.0.1`.
347+
Something like the following should work:
346348

347349
```sh
348350
# Build the test server for the iOS simulator:
@@ -384,7 +386,7 @@ On the [wasm32-wasip1 target support page] a minimum version is specified that y
384386
Some cmake commands that take a while and give a lot of very concerning c++ warnings...
385387
Then, in `bootstrap.toml`, point to the sysroot like so:
386388

387-
```
389+
```toml
388390
[target.wasm32-wasip1]
389391
wasi-root = "<wasi-sdk location>/build/sysroot/install/share/wasi-sysroot"
390392
```

0 commit comments

Comments
 (0)