Skip to content

Commit 3eb8611

Browse files
authored
Document error-pattern header (#989)
* Document `error-pattern` header * Address some reviews
1 parent 1838d29 commit 3eb8611

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/tests/adding.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ source.
207207
* `needs-sanitizer-{address,leak,memory,thread}` - indicates that test
208208
requires a target with a support for AddressSanitizer, LeakSanitizer,
209209
MemorySanitizer or ThreadSanitizer respectively.
210+
* `error-pattern` checks the diagnostics just like the `ERROR` annotation
211+
without specifying error line. This is useful when the error doesn't give
212+
any span.
210213

211214
[`header.rs`]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/header.rs
212215
[bless]: ./running.md#editing-and-updating-the-reference-files
@@ -291,6 +294,36 @@ fn main() {
291294
//~| ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields [E0023]
292295
```
293296

297+
#### When error line cannot be specified
298+
299+
Let's think about this test:
300+
301+
```rust,ignore
302+
fn main() {
303+
let a: *const [_] = &[1, 2, 3];
304+
unsafe {
305+
let _b = (*a)[3];
306+
}
307+
}
308+
```
309+
310+
We want to ensure this shows "index out of bounds" but we cannot use the `ERROR` annotation
311+
since the error doesn't have any span. Then it's time to use the `error-pattern`:
312+
313+
```rust,ignore
314+
// error-pattern: index out of bounds
315+
fn main() {
316+
let a: *const [_] = &[1, 2, 3];
317+
unsafe {
318+
let _b = (*a)[3];
319+
}
320+
}
321+
```
322+
323+
But for strict testing, try to use the `ERROR` annotation as much as possible.
324+
325+
#### Error levels
326+
294327
The error levels that you can have are:
295328

296329
1. `ERROR`

0 commit comments

Comments
 (0)