Skip to content

Commit fa62a0c

Browse files
committed
Introduce 'run-pass' header to 'ui' tests in compiletest. Fix issue #36516.
The 'run-pass' header cause a 'ui' test to execute the result. It is used to test the lint output, at the same time ensure those lints won't cause the source code to become compile-fail. 12 run-pass/run-pass-fulldeps tests gained the header and are moved to ui/ui-fulldeps. After this move, no run-pass/run-pass-fulldeps tests should rely on the compiler's JSON message. This allows us to stop passing `--error-format json` in run-pass tests, thus fixing #36516.
1 parent 9fa25a7 commit fa62a0c

28 files changed

+212
-5
lines changed

src/test/run-pass-fulldeps/deprecated-derive.rs renamed to src/test/ui-fulldeps/deprecated-derive.rs

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

11+
// run-pass
12+
1113
#![feature(rustc_private)]
1214
#![allow(dead_code)]
1315

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: derive(Encodable) is deprecated in favor of derive(RustcEncodable)
2+
--> $DIR/deprecated-derive.rs:18:10
3+
|
4+
18 | #[derive(Encodable)]
5+
| ^^^^^^^^^
6+

src/test/run-pass-fulldeps/lint-group-plugin.rs renamed to src/test/ui-fulldeps/lint-group-plugin.rs

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

11+
// run-pass
1112
// aux-build:lint_group_plugin_test.rs
1213
// ignore-stage1
1314
#![feature(plugin)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: item is named 'lintme'
2+
--> $DIR/lint-group-plugin.rs:18:1
3+
|
4+
18 | fn lintme() { } //~ WARNING item is named 'lintme'
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(test_lint)] on by default
8+
9+
warning: item is named 'pleaselintme'
10+
--> $DIR/lint-group-plugin.rs:19:1
11+
|
12+
19 | fn pleaselintme() { } //~ WARNING item is named 'pleaselintme'
13+
| ^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: #[warn(please_lint)] on by default
16+

src/test/run-pass-fulldeps/lint-plugin-cmdline-allow.rs renamed to src/test/ui-fulldeps/lint-plugin-cmdline-allow.rs

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

11+
// run-pass
1112
// aux-build:lint_plugin_test.rs
1213
// ignore-stage1
1314
// compile-flags: -A test-lint
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: function is never used: `lintme`
2+
--> $DIR/lint-plugin-cmdline-allow.rs:19:1
3+
|
4+
19 | fn lintme() { }
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(dead_code)] on by default
8+

src/test/run-pass-fulldeps/lint-plugin-cmdline-load.rs renamed to src/test/ui-fulldeps/lint-plugin-cmdline-load.rs

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

11+
// run-pass
1112
// aux-build:lint_plugin_test.rs
1213
// ignore-stage1
1314
// compile-flags: -Z extra-plugins=lint_plugin_test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: item is named 'lintme'
2+
--> $DIR/lint-plugin-cmdline-load.rs:18:1
3+
|
4+
18 | fn lintme() { } //~ WARNING item is named 'lintme'
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(test_lint)] on by default
8+

src/test/run-pass-fulldeps/lint-plugin.rs renamed to src/test/ui-fulldeps/lint-plugin.rs

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

11+
// run-pass
1112
// aux-build:lint_plugin_test.rs
1213
// ignore-stage1
1314
#![feature(plugin)]
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: item is named 'lintme'
2+
--> $DIR/lint-plugin.rs:18:1
3+
|
4+
18 | fn lintme() { } //~ WARNING item is named 'lintme'
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(test_lint)] on by default
8+

src/test/run-pass/deprecated-macro_escape-inner.rs renamed to src/test/ui/deprecated-macro_escape-inner.rs

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

11+
// run-pass
12+
1113
mod foo {
1214
#![macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
1315
//~^ HELP consider an outer attribute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
warning: macro_escape is a deprecated synonym for macro_use
2+
--> $DIR/deprecated-macro_escape-inner.rs:14:5
3+
|
4+
14 | #![macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider an outer attribute, #[macro_use] mod ...
8+

src/test/run-pass/deprecated-macro_escape.rs renamed to src/test/ui/deprecated-macro_escape.rs

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

11+
// run-pass
12+
1113
#[macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
1214
mod foo {
1315
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: macro_escape is a deprecated synonym for macro_use
2+
--> $DIR/deprecated-macro_escape.rs:13:1
3+
|
4+
13 | #[macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
5+
| ^^^^^^^^^^^^^^^
6+

src/test/run-pass/deriving-meta-empty-trait-list.rs renamed to src/test/ui/deriving-meta-empty-trait-list.rs

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

11+
// run-pass
12+
1113
#![allow(dead_code)]
1214

1315
#[derive] //~ WARNING empty trait list in `derive`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
warning: empty trait list in `derive`
2+
--> $DIR/deriving-meta-empty-trait-list.rs:15:1
3+
|
4+
15 | #[derive] //~ WARNING empty trait list in `derive`
5+
| ^^^^^^^^^
6+
7+
warning: empty trait list in `derive`
8+
--> $DIR/deriving-meta-empty-trait-list.rs:18:1
9+
|
10+
18 | #[derive()] //~ WARNING empty trait list in `derive`
11+
| ^^^^^^^^^^^
12+

src/test/run-pass/enum-size-variance.rs renamed to src/test/ui/enum-size-variance.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
//
10+
11+
// run-pass
12+
1113
#![warn(variant_size_differences)]
1214
#![allow(dead_code)]
1315

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

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

src/test/run-pass/issue-19100.rs renamed to src/test/ui/issue-19100.rs

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

11+
// run-pass
12+
1113
#![allow(non_snake_case)]
1214
#![allow(dead_code)]
1315
#![allow(unused_variables)]

src/test/ui/issue-19100.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2+
--> $DIR/issue-19100.rs:27:1
3+
|
4+
27 | Bar if true
5+
| ^^^
6+
|
7+
= help: if you meant to match on a variant, consider making the path in the pattern qualified: `Foo::Bar`
8+
9+
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
10+
--> $DIR/issue-19100.rs:32:1
11+
|
12+
32 | Baz if false
13+
| ^^^
14+
|
15+
= help: if you meant to match on a variant, consider making the path in the pattern qualified: `Foo::Baz`
16+

src/test/run-pass/path-lookahead.rs renamed to src/test/ui/path-lookahead.rs

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

11+
// run-pass
12+
1113
// Parser test for #37765
1214

1315
fn with_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `with_parens`

src/test/ui/path-lookahead.stderr

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
warning: unnecessary parentheses around `return` value
2+
--> $DIR/path-lookahead.rs:16:10
3+
|
4+
16 | return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: #[warn(unused_parens)] on by default
8+
9+
warning: function is never used: `with_parens`
10+
--> $DIR/path-lookahead.rs:15:1
11+
|
12+
15 | / fn with_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `with_parens`
13+
16 | | return (<T as ToString>::to_string(&arg)); //~WARN unnecessary parentheses around `return` value
14+
17 | | }
15+
| |_^
16+
|
17+
= note: #[warn(dead_code)] on by default
18+
19+
warning: function is never used: `no_parens`
20+
--> $DIR/path-lookahead.rs:19:1
21+
|
22+
19 | / fn no_parens<T: ToString>(arg: T) -> String { //~WARN function is never used: `no_parens`
23+
20 | | return <T as ToString>::to_string(&arg);
24+
21 | | }
25+
| |_^
26+
|
27+
= note: #[warn(dead_code)] on by default
28+

src/test/run-pass/test-should-panic-attr.rs renamed to src/test/ui/test-should-panic-attr.rs

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

11+
// run-pass
1112
// compile-flags: --test
1213

1314
#[test]
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
warning: attribute must be of the form: `#[should_panic]` or `#[should_panic(expected = "error message")]`
2+
--> $DIR/test-should-panic-attr.rs:15:1
3+
|
4+
15 | #[should_panic = "foo"]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: Errors in this attribute were erroneously allowed and will become a hard error in a future release.
8+
9+
warning: argument must be of the form: `expected = "error message"`
10+
--> $DIR/test-should-panic-attr.rs:22:1
11+
|
12+
22 | #[should_panic(expected)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: Errors in this attribute were erroneously allowed and will become a hard error in a future release.
16+
17+
warning: argument must be of the form: `expected = "error message"`
18+
--> $DIR/test-should-panic-attr.rs:29:1
19+
|
20+
29 | #[should_panic(expect)]
21+
| ^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: Errors in this attribute were erroneously allowed and will become a hard error in a future release.
24+
25+
warning: argument must be of the form: `expected = "error message"`
26+
--> $DIR/test-should-panic-attr.rs:36:1
27+
|
28+
36 | #[should_panic(expected(foo, bar))]
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: Errors in this attribute were erroneously allowed and will become a hard error in a future release.
32+
33+
warning: argument must be of the form: `expected = "error message"`
34+
--> $DIR/test-should-panic-attr.rs:43:1
35+
|
36+
43 | #[should_panic(expected = "foo", bar)]
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
|
39+
= note: Errors in this attribute were erroneously allowed and will become a hard error in a future release.
40+

src/tools/compiletest/src/header.rs

+12
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ pub struct TestProps {
233233
pub must_compile_successfully: bool,
234234
// rustdoc will test the output of the `--test` option
235235
pub check_test_line_numbers_match: bool,
236+
// The test must be compiled and run successfully. Only used in UI tests for
237+
// now.
238+
pub run_pass: bool,
236239
}
237240

238241
impl TestProps {
@@ -258,6 +261,7 @@ impl TestProps {
258261
incremental_dir: None,
259262
must_compile_successfully: false,
260263
check_test_line_numbers_match: false,
264+
run_pass: false,
261265
}
262266
}
263267

@@ -368,6 +372,10 @@ impl TestProps {
368372
if !self.check_test_line_numbers_match {
369373
self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
370374
}
375+
376+
if !self.run_pass {
377+
self.run_pass = config.parse_run_pass(ln);
378+
}
371379
});
372380

373381
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
@@ -485,6 +493,10 @@ impl Config {
485493
self.parse_name_directive(line, "check-test-line-numbers-match")
486494
}
487495

496+
fn parse_run_pass(&self, line: &str) -> bool {
497+
self.parse_name_directive(line, "run-pass")
498+
}
499+
488500
fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> {
489501
self.parse_name_value_directive(line, name).map(|nv| {
490502
// nv is either FOO or FOO=BAR

src/tools/compiletest/src/runtest.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ impl<'test> TestCx<'test> {
214214
self.fatal_proc_rec("compilation failed!", &proc_res);
215215
}
216216

217+
// FIXME(#41968): Move this check to tidy?
217218
let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
218-
if !expected_errors.is_empty() {
219-
self.check_expected_errors(expected_errors, &proc_res);
220-
}
219+
assert!(expected_errors.is_empty(),
220+
"run-pass tests with expected warnings should be moved to ui/");
221221

222222
let proc_res = self.exec_compiled_test();
223223

@@ -1394,7 +1394,6 @@ actual:\n\
13941394
match self.config.mode {
13951395
CompileFail |
13961396
ParseFail |
1397-
RunPass |
13981397
Incremental => {
13991398
// If we are extracting and matching errors in the new
14001399
// fashion, then you want JSON mode. Old-skool error
@@ -1422,6 +1421,7 @@ actual:\n\
14221421

14231422
args.push(dir_opt);
14241423
}
1424+
RunPass |
14251425
RunFail |
14261426
RunPassValgrind |
14271427
Pretty |
@@ -2254,6 +2254,14 @@ actual:\n\
22542254
self.fatal_proc_rec(&format!("{} errors occurred comparing output.", errors),
22552255
&proc_res);
22562256
}
2257+
2258+
if self.props.run_pass {
2259+
let proc_res = self.exec_compiled_test();
2260+
2261+
if !proc_res.status.success() {
2262+
self.fatal_proc_rec("test run failed!", &proc_res);
2263+
}
2264+
}
22572265
}
22582266

22592267
fn run_mir_opt_test(&self) {

0 commit comments

Comments
 (0)