Skip to content

Commit 1ff0b12

Browse files
committed
Update tests chapters for review comments.
1 parent e7f9a34 commit 1ff0b12

File tree

2 files changed

+35
-37
lines changed

2 files changed

+35
-37
lines changed

Diff for: src/tests/intro.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ The standard library relies very heavily on documentation tests to cover its fun
4343
However, unit tests and integration tests can also be used as needed.
4444
Almost all of the compiler packages have doctests disabled.
4545

46-
The standard library and compiler often place all unit tests in a separate `tests` file.
46+
The standard library and compiler always place all unit tests in a separate `tests` file
47+
(this is enforced in [tidy][tidy-unit-tests]).
4748
This approach ensures that when the test file is changed, the crate does not need to be recompiled.
4849
For example:
4950

@@ -62,6 +63,8 @@ then that would require recompiling the entire standard library, and the entiret
6263
* `--doc` — Only runs documentation tests in the package.
6364
* `--no-doc` — Run all tests *except* documentation tests.
6465

66+
[tidy-unit-tests]: https://github.com/rust-lang/rust/blob/master/src/tools/tidy/src/unit_tests.rs
67+
6568
### Tidy
6669

6770
Tidy is a custom tool used for validating source code style and formatting conventions,

Diff for: src/tests/ui.md

+31-36
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ UI tests are a particular [test suite](compiletest.md#test-suites) of compiletes
99
The tests in [`src/test/ui`] are a collection of general-purpose tests which
1010
primarily focus on validating the console output of the compiler, but can be
1111
used for many other purposes.
12-
For example, tests can also be configure to [run the resulting
12+
For example, tests can also be configured to [run the resulting
1313
program](#controlling-passfail-expectations) to verify its behavior.
1414

1515
[`src/test/ui`]: https://github.com/rust-lang/rust/blob/master/src/test/ui
@@ -96,41 +96,42 @@ generated.
9696
The compiler output is normalized to eliminate output difference between
9797
platforms, mainly about filenames.
9898

99-
The following strings replace their corresponding values:
100-
101-
- `$DIR`: The directory where the test is defined.
102-
- Example: `/path/to/rust/src/test/ui/error-codes`
103-
- `$SRC_DIR`: The root source directory.
104-
- Example: `/path/to/rust/src`
105-
- `$TEST_BUILD_DIR`: The base directory where the test's output goes.
106-
- Example: `/path/to/rust/build/x86_64-unknown-linux-gnu/test/ui`
107-
108-
Additionally, the following changes are made:
109-
110-
- Line and column numbers for paths in `$SRC_DIR` are replaced with `LL:CC`.
111-
For example, `/path/to/rust/library/core/src/clone.rs:122:8` is replaced with
112-
`$SRC_DIR/core/src/clone.rs:LL:COL`.
113-
114-
Note: The line and column numbers for `-->` lines pointing to the test are
115-
*not* normalized, and left as-is. This ensures that the compiler continues
116-
to point to the correct location, and keeps the stderr files readable.
117-
Ideally all line/column information would be retained, but small changes to
118-
the source causes large diffs, and more frequent merge conflicts and test
119-
errors. See also `-Z ui-testing` below which applies additional line number
120-
normalization.
121-
- `\t` is replaced with an actual tab character.
122-
- Error line annotations like `//~ ERROR some message` are removed.
99+
Compiletest makes the following replacements on the compiler output:
100+
101+
- The directory where the test is defined is replaced with `$DIR`.
102+
Example: `/path/to/rust/src/test/ui/error-codes`
103+
- The directory to the standard library source is replaced with `$SRC_DIR`.
104+
Example: `/path/to/rust/library`
105+
- Line and column numbers for paths in `$SRC_DIR` are replaced with `LL:COL`.
106+
This helps ensure that changes to the layout of the standard library do not
107+
cause widespread changes to the `.stderr` files.
108+
Example: `$SRC_DIR/alloc/src/sync.rs:53:46`
109+
- The base directory where the test's output goes is replaced with `$TEST_BUILD_DIR`.
110+
This only comes up in a few rare circumstances.
111+
Example: `/path/to/rust/build/x86_64-unknown-linux-gnu/test/ui`
112+
- Tabs are replaced with `\t`.
123113
- Backslashes (`\`) are converted to forward slashes (`/`) within paths (using
124114
a heuristic). This helps normalize differences with Windows-style paths.
125115
- CRLF newlines are converted to LF.
116+
- Error line annotations like `//~ ERROR some message` are removed.
117+
- Various v0 and legacy symbol hashes are replaced with placeholders like
118+
`[HASH]` or `<SYMBOL_HASH>`.
126119

127120
Additionally, the compiler is run with the `-Z ui-testing` flag which causes
128121
the compiler itself to apply some changes to the diagnostic output to make it
129-
more suitable for UI testing. For example, it will anonymize line numbers in
130-
the output (line numbers prefixing each source line are replaced with `LL`).
122+
more suitable for UI testing.
123+
For example, it will anonymize line numbers in the output (line numbers
124+
prefixing each source line are replaced with `LL`).
131125
In extremely rare situations, this mode can be disabled with the header
132126
command `// compile-flags: -Z ui-testing=no`.
133127

128+
Note: The line and column numbers for `-->` lines pointing to the test are
129+
*not* normalized, and left as-is. This ensures that the compiler continues
130+
to point to the correct location, and keeps the stderr files readable.
131+
Ideally all line/column information would be retained, but small changes to
132+
the source causes large diffs, and more frequent merge conflicts and test
133+
errors.
134+
134135
Sometimes these built-in normalizations are not enough. In such cases, you
135136
may provide custom normalization rules using the header commands, e.g.
136137

@@ -189,8 +190,9 @@ the source.
189190
Finally, they ensure that no additional unexpected errors are generated.
190191

191192
They have several forms, but generally are a comment with the diagnostic
192-
level (such as `ERROR`) and a substring of the expected error output
193-
(you don't have to write out the entire text, just whatever is important).
193+
level (such as `ERROR`) and a substring of the expected error output.
194+
You don't have to write out the entire message, just make sure to include the
195+
important part of the message to make it self-documenting.
194196

195197
The error annotation needs to match with the line of the diagnostic.
196198
There are several ways to match the message with the line (see the examples below):
@@ -205,13 +207,6 @@ There are several ways to match the message with the line (see the examples belo
205207
This is more convenient than using multiple carets when there are multiple
206208
messages associated with the same line.
207209

208-
Error annotations are considered during tidy lints of line length and should
209-
be formatted according to tidy requirements.
210-
You may use an error message prefix sub-string if necessary to meet line
211-
length requirements.
212-
Make sure that the text is long enough for the error message to be
213-
self-documenting.
214-
215210
### Error annotation examples
216211

217212
Here are examples of error annotations on different lines of UI test

0 commit comments

Comments
 (0)