Skip to content

Commit b360b44

Browse files
committed
Auto merge of #43083 - kennytm:fix-42434-custom-stdxxx-normalization, r=nikomatsakis
compilertest (UI test): Support custom normalization. Closes #42434. Adds this header for UI tests: ```rust // normalize-stderr-32bit: "fn() (32 bits)" -> "fn() ($PTR bits)" ``` It will normalize the `stderr` output on 32-bit platforms, by replacing all instances of `fn() (32 bits)` by `fn() ($PTR bits)`. Extends the UI tests in #42304 and #41968 to 32-bit targets. r? @nikomatsakis
2 parents 9475ae4 + 34209b0 commit b360b44

13 files changed

+219
-148
lines changed

src/test/COMPILER_TESTS.md

+72-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The error levels that you can have are:
3737
Header commands specify something about the entire test file as a
3838
whole, instead of just a few lines inside the test.
3939

40-
* `ignore-X` where `X` is an architecture, OS or stage will ignore the test accordingly
40+
* `ignore-X` where `X` is a target detail or stage will ignore the test accordingly (see below)
4141
* `ignore-pretty` will not compile the pretty-printed test (this is done to test the pretty-printer, but might not always work)
4242
* `ignore-test` always ignores the test
4343
* `ignore-lldb` and `ignore-gdb` will skip the debuginfo tests
@@ -50,6 +50,14 @@ whole, instead of just a few lines inside the test.
5050
feature is attempted without the proper `#![feature(X)]` tag.
5151
Each unstable lang feature is required to have a gate test.
5252

53+
Some examples of `X` in `ignore-X`:
54+
55+
* Architecture: `aarch64`, `arm`, `asmjs`, `mips`, `wasm32`, `x86_64`, `x86`, ...
56+
* OS: `android`, `emscripten`, `freebsd`, `ios`, `linux`, `macos`, `windows`, ...
57+
* Environment (fourth word of the target triple): `gnu`, `msvc`, `musl`.
58+
* Pointer width: `32bit`, `64bit`.
59+
* Stage: `stage0`, `stage1`, `stage2`.
60+
5361
## Revisions
5462

5563
Certain classes of tests support "revisions" (as of the time of this
@@ -86,3 +94,66 @@ For example, the `ignore-test` header (and all "ignore" headers)
8694
currently only apply to the test as a whole, not to particular
8795
revisions. The only headers that are intended to really work when
8896
customized to a revision are error patterns and compiler flags.
97+
98+
## Guide to the UI Tests
99+
100+
The UI tests are intended to capture the compiler's complete output,
101+
so that we can test all aspects of the presentation. They work by
102+
compiling a file (e.g., `ui/hello_world/main.rs`), capturing the output,
103+
and then applying some normalization (see below). This normalized
104+
result is then compared against reference files named
105+
`ui/hello_world/main.stderr` and `ui/hello_world/main.stdout`. If either of
106+
those files doesn't exist, the output must be empty. If the test run
107+
fails, we will print out the current output, but it is also saved in
108+
`build/<target-triple>/test/ui/hello_world/main.stdout` (this path is
109+
printed as part of the test failure mesage), so you can run `diff` and
110+
so forth.
111+
112+
### Editing and updating the reference files
113+
114+
If you have changed the compiler's output intentionally, or you are
115+
making a new test, you can use the script `ui/update-references.sh` to
116+
update the references. When you run the test framework, it will report
117+
various errors: in those errors is a command you can use to run the
118+
`ui/update-references.sh` script, which will then copy over the files
119+
from the build directory and use them as the new reference. You can
120+
also just run `ui/update-all-references.sh`. In both cases, you can run
121+
the script with `--help` to get a help message.
122+
123+
### Normalization
124+
125+
The normalization applied is aimed at eliminating output difference
126+
between platforms, mainly about filenames:
127+
128+
- the test directory is replaced with `$DIR`
129+
- all backslashes (`\`) are converted to forward slashes (`/`) (for Windows)
130+
- all CR LF newlines are converted to LF
131+
132+
Sometimes these built-in normalizations are not enough. In such cases, you
133+
may provide custom normalization rules using the header commands, e.g.
134+
135+
```
136+
// normalize-stderr-32bit: "fn() (32 bits)" -> "fn() ($PTR bits)"
137+
// normalize-stderr-64bit: "fn() (64 bits)" -> "fn() ($PTR bits)"
138+
```
139+
140+
This tells the test, on 32-bit platforms, whenever the compiler writes
141+
`fn() (32 bits)` to stderr, it should be normalized to read `fn() ($PTR bits)`
142+
instead. Similar for 64-bit.
143+
144+
The corresponding reference file will use the normalized output to test both
145+
32-bit and 64-bit platforms:
146+
147+
```
148+
...
149+
|
150+
= note: source type: fn() ($PTR bits)
151+
= note: target type: u16 (16 bits)
152+
...
153+
```
154+
155+
Please see `ui/transmute/main.rs` and `.stderr` for a concrete usage example.
156+
157+
Besides `normalize-stderr-32bit` and `-64bit`, one may use any target
158+
information or stage supported by `ignore-X` here as well (e.g.
159+
`normalize-stderr-windows`).

src/test/run-pass/i128-ffi.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
// should look like.
1414

1515
// ignore-windows
16-
17-
// Ignore 32 bit targets:
18-
// ignore-x86
19-
// ignore-arm
20-
21-
// ignore-emscripten
16+
// ignore-32bit
2217

2318
#![feature(i128_type)]
2419

src/test/ui/README.md

-31
This file was deleted.

src/test/ui/enum-size-variance.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
// except according to those terms.
1010

1111
// run-pass
12-
// ignore-x86
13-
// ignore-arm
14-
// ignore-emscripten
15-
// ^ ignore 32-bit targets, as the error message is target-dependent. see PR #41968.
1612

1713
#![warn(variant_size_differences)]
1814
#![allow(dead_code)]
@@ -24,26 +20,26 @@ enum Enum1 { }
2420

2521
enum Enum2 { A, B, C }
2622

27-
enum Enum3 { D(isize), E, F }
23+
enum Enum3 { D(i64), E, F }
2824

29-
enum Enum4 { H(isize), I(isize), J }
25+
enum Enum4 { H(i64), I(i64), J }
3026

3127
enum Enum5 {
32-
L(isize, isize, isize, isize), //~ WARNING three times larger
33-
M(isize),
28+
L(i64, i64, i64, i64), //~ WARNING three times larger
29+
M(i64),
3430
N
3531
}
3632

3733
enum Enum6<T, U> {
3834
O(T),
3935
P(U),
40-
Q(isize)
36+
Q(i64)
4137
}
4238

4339
#[allow(variant_size_differences)]
4440
enum Enum7 {
45-
R(isize, isize, isize, isize),
46-
S(isize),
41+
R(i64, i64, i64, i64),
42+
S(i64),
4743
T
4844
}
4945
pub fn main() { }

src/test/ui/enum-size-variance.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
warning: enum variant is more than three times larger (32 bytes) than the next largest
2-
--> $DIR/enum-size-variance.rs:32:5
2+
--> $DIR/enum-size-variance.rs:28:5
33
|
4-
32 | L(isize, isize, isize, isize), //~ WARNING three times larger
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
28 | L(i64, i64, i64, i64), //~ WARNING three times larger
5+
| ^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: lint level defined here
8-
--> $DIR/enum-size-variance.rs:17:9
8+
--> $DIR/enum-size-variance.rs:13:9
99
|
10-
17 | #![warn(variant_size_differences)]
10+
13 | #![warn(variant_size_differences)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^
1212

src/test/ui/transmute/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-x86
12-
// ignore-arm
13-
// ignore-emscripten
14-
// ignore 32-bit platforms (test output is different)
11+
// normalize-stderr-32bit: "&str (64 bits)" -> "&str ($STR bits)"
12+
// normalize-stderr-64bit: "&str (128 bits)" -> "&str ($STR bits)"
13+
14+
1515

1616
#![feature(untagged_unions)]
1717
use std::mem::transmute;

src/test/ui/transmute/main.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error[E0512]: transmute called with types of different sizes
2222
34 | let x: u8 = transmute("test"); //~ ERROR transmute called with types of different sizes
2323
| ^^^^^^^^^
2424
|
25-
= note: source type: &str (128 bits)
25+
= note: source type: &str ($STR bits)
2626
= note: target type: u8 (8 bits)
2727

2828
error[E0512]: transmute called with types of different sizes

src/test/ui/transmute/transmute-from-fn-item-types-error.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-x86
12-
// ignore-arm
13-
// ignore-emscripten
14-
// ignore 32-bit platforms (test output is different)
15-
1611
use std::mem;
1712

18-
unsafe fn foo() -> (i32, *const (), Option<fn()>) {
13+
unsafe fn foo() -> (i8, *const (), Option<fn()>) {
1914
let i = mem::transmute(bar);
2015
//~^ ERROR is zero-sized and can't be transmuted
2116
//~^^ NOTE cast with `as` to a pointer instead
@@ -46,7 +41,7 @@ unsafe fn bar() {
4641
//~^^ NOTE cast with `as` to a pointer instead
4742

4843
// No error if a coercion would otherwise occur.
49-
mem::transmute::<fn(), u32>(main);
44+
mem::transmute::<fn(), usize>(main);
5045
}
5146

5247
unsafe fn baz() {
@@ -63,7 +58,7 @@ unsafe fn baz() {
6358
//~^^ NOTE cast with `as` to a pointer instead
6459

6560
// No error if a coercion would otherwise occur.
66-
mem::transmute::<Option<fn()>, u32>(Some(main));
61+
mem::transmute::<Option<fn()>, usize>(Some(main));
6762
}
6863

6964
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,90 @@
11
error[E0512]: transmute called with types of different sizes
2-
--> $DIR/transmute-from-fn-item-types-error.rs:19:13
2+
--> $DIR/transmute-from-fn-item-types-error.rs:14:13
33
|
4-
19 | let i = mem::transmute(bar);
4+
14 | let i = mem::transmute(bar);
55
| ^^^^^^^^^^^^^^
66
|
77
= note: source type: unsafe fn() {bar} (0 bits)
8-
= note: target type: i32 (32 bits)
8+
= note: target type: i8 (8 bits)
99

1010
error[E0591]: can't transmute zero-sized type
11-
--> $DIR/transmute-from-fn-item-types-error.rs:23:13
11+
--> $DIR/transmute-from-fn-item-types-error.rs:18:13
1212
|
13-
23 | let p = mem::transmute(foo);
13+
18 | let p = mem::transmute(foo);
1414
| ^^^^^^^^^^^^^^
1515
|
16-
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
16+
= note: source type: unsafe fn() -> (i8, *const (), std::option::Option<fn()>) {foo}
1717
= note: target type: *const ()
1818
= help: cast with `as` to a pointer instead
1919

2020
error[E0591]: can't transmute zero-sized type
21-
--> $DIR/transmute-from-fn-item-types-error.rs:27:14
21+
--> $DIR/transmute-from-fn-item-types-error.rs:22:14
2222
|
23-
27 | let of = mem::transmute(main);
23+
22 | let of = mem::transmute(main);
2424
| ^^^^^^^^^^^^^^
2525
|
2626
= note: source type: fn() {main}
2727
= note: target type: std::option::Option<fn()>
2828
= help: cast with `as` to a pointer instead
2929

3030
error[E0512]: transmute called with types of different sizes
31-
--> $DIR/transmute-from-fn-item-types-error.rs:36:5
31+
--> $DIR/transmute-from-fn-item-types-error.rs:31:5
3232
|
33-
36 | mem::transmute::<_, u8>(main);
33+
31 | mem::transmute::<_, u8>(main);
3434
| ^^^^^^^^^^^^^^^^^^^^^^^
3535
|
3636
= note: source type: fn() {main} (0 bits)
3737
= note: target type: u8 (8 bits)
3838

3939
error[E0591]: can't transmute zero-sized type
40-
--> $DIR/transmute-from-fn-item-types-error.rs:40:5
40+
--> $DIR/transmute-from-fn-item-types-error.rs:35:5
4141
|
42-
40 | mem::transmute::<_, *mut ()>(foo);
42+
35 | mem::transmute::<_, *mut ()>(foo);
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444
|
45-
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
45+
= note: source type: unsafe fn() -> (i8, *const (), std::option::Option<fn()>) {foo}
4646
= note: target type: *mut ()
4747
= help: cast with `as` to a pointer instead
4848

4949
error[E0591]: can't transmute zero-sized type
50-
--> $DIR/transmute-from-fn-item-types-error.rs:44:5
50+
--> $DIR/transmute-from-fn-item-types-error.rs:39:5
5151
|
52-
44 | mem::transmute::<_, fn()>(bar);
52+
39 | mem::transmute::<_, fn()>(bar);
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^
5454
|
5555
= note: source type: unsafe fn() {bar}
5656
= note: target type: fn()
5757
= help: cast with `as` to a pointer instead
5858

59-
error[E0512]: transmute called with types of different sizes
60-
--> $DIR/transmute-from-fn-item-types-error.rs:49:5
61-
|
62-
49 | mem::transmute::<fn(), u32>(main);
63-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
64-
|
65-
= note: source type: fn() (64 bits)
66-
= note: target type: u32 (32 bits)
67-
6859
error[E0591]: can't transmute zero-sized type
69-
--> $DIR/transmute-from-fn-item-types-error.rs:53:5
60+
--> $DIR/transmute-from-fn-item-types-error.rs:48:5
7061
|
71-
53 | mem::transmute::<_, *mut ()>(Some(foo));
62+
48 | mem::transmute::<_, *mut ()>(Some(foo));
7263
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7364
|
74-
= note: source type: unsafe fn() -> (i32, *const (), std::option::Option<fn()>) {foo}
65+
= note: source type: unsafe fn() -> (i8, *const (), std::option::Option<fn()>) {foo}
7566
= note: target type: *mut ()
7667
= help: cast with `as` to a pointer instead
7768

7869
error[E0591]: can't transmute zero-sized type
79-
--> $DIR/transmute-from-fn-item-types-error.rs:57:5
70+
--> $DIR/transmute-from-fn-item-types-error.rs:52:5
8071
|
81-
57 | mem::transmute::<_, fn()>(Some(bar));
72+
52 | mem::transmute::<_, fn()>(Some(bar));
8273
| ^^^^^^^^^^^^^^^^^^^^^^^^^
8374
|
8475
= note: source type: unsafe fn() {bar}
8576
= note: target type: fn()
8677
= help: cast with `as` to a pointer instead
8778

8879
error[E0591]: can't transmute zero-sized type
89-
--> $DIR/transmute-from-fn-item-types-error.rs:61:5
80+
--> $DIR/transmute-from-fn-item-types-error.rs:56:5
9081
|
91-
61 | mem::transmute::<_, Option<fn()>>(Some(baz));
82+
56 | mem::transmute::<_, Option<fn()>>(Some(baz));
9283
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9384
|
9485
= note: source type: unsafe fn() {baz}
9586
= note: target type: std::option::Option<fn()>
9687
= help: cast with `as` to a pointer instead
9788

98-
error[E0512]: transmute called with types of different sizes
99-
--> $DIR/transmute-from-fn-item-types-error.rs:66:5
100-
|
101-
66 | mem::transmute::<Option<fn()>, u32>(Some(main));
102-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103-
|
104-
= note: source type: std::option::Option<fn()> (64 bits)
105-
= note: target type: u32 (32 bits)
106-
107-
error: aborting due to 11 previous errors
89+
error: aborting due to 9 previous errors
10890

0 commit comments

Comments
 (0)