Skip to content

Commit 3ad06b3

Browse files
committed
revert "Update tools code"
This reverts commit 1dc2015, which switched to compiling the UI tests twice rather than extracting the humanized output from a field in the JSON output. A conflict in this revert commit had to be fixed manually where changes introduced in rust-lang#48449 collide with the change we're trying to revert (from rust-lang#48337). This is in the matter of rust-lang#48550. Conflicts: src/tools/compiletest/src/runtest.rs
1 parent 0ff9872 commit 3ad06b3

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

src/tools/compiletest/src/json.rs

+19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ struct DiagnosticCode {
5757
explanation: Option<String>,
5858
}
5959

60+
pub fn extract_rendered(output: &str, proc_res: &ProcRes) -> String {
61+
output.lines()
62+
.filter_map(|line| if line.starts_with('{') {
63+
match json::decode::<Diagnostic>(line) {
64+
Ok(diagnostic) => diagnostic.rendered,
65+
Err(error) => {
66+
proc_res.fatal(Some(&format!("failed to decode compiler output as json: \
67+
`{}`\noutput: {}\nline: {}",
68+
error,
69+
line,
70+
output)));
71+
}
72+
}
73+
} else {
74+
None
75+
})
76+
.collect()
77+
}
78+
6079
pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
6180
output.lines()
6281
.flat_map(|line| parse_line(file_name, line, output, proc_res))

src/tools/compiletest/src/runtest.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'test> TestCx<'test> {
248248
}
249249

250250
fn run_cfail_test(&self) {
251-
let proc_res = self.compile_test(&[]);
251+
let proc_res = self.compile_test();
252252
self.check_if_test_should_compile(&proc_res);
253253
self.check_no_compiler_crash(&proc_res);
254254

@@ -267,7 +267,7 @@ impl<'test> TestCx<'test> {
267267
}
268268

269269
fn run_rfail_test(&self) {
270-
let proc_res = self.compile_test(&[]);
270+
let proc_res = self.compile_test();
271271

272272
if !proc_res.status.success() {
273273
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -309,7 +309,7 @@ impl<'test> TestCx<'test> {
309309
}
310310

311311
fn run_rpass_test(&self) {
312-
let proc_res = self.compile_test(&[]);
312+
let proc_res = self.compile_test();
313313

314314
if !proc_res.status.success() {
315315
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -336,7 +336,7 @@ impl<'test> TestCx<'test> {
336336
return self.run_rpass_test();
337337
}
338338

339-
let mut proc_res = self.compile_test(&[]);
339+
let mut proc_res = self.compile_test();
340340

341341
if !proc_res.status.success() {
342342
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -578,7 +578,7 @@ impl<'test> TestCx<'test> {
578578
let mut cmds = commands.join("\n");
579579

580580
// compile test file (it should have 'compile-flags:-g' in the header)
581-
let compiler_run_result = self.compile_test(&[]);
581+
let compiler_run_result = self.compile_test();
582582
if !compiler_run_result.status.success() {
583583
self.fatal_proc_rec("compilation failed!", &compiler_run_result);
584584
}
@@ -835,7 +835,7 @@ impl<'test> TestCx<'test> {
835835

836836
fn run_debuginfo_lldb_test_no_opt(&self) {
837837
// compile test file (it should have 'compile-flags:-g' in the header)
838-
let compile_result = self.compile_test(&[]);
838+
let compile_result = self.compile_test();
839839
if !compile_result.status.success() {
840840
self.fatal_proc_rec("compilation failed!", &compile_result);
841841
}
@@ -1272,15 +1272,12 @@ impl<'test> TestCx<'test> {
12721272
}
12731273
}
12741274

1275-
fn compile_test(&self, extra_args: &[&'static str]) -> ProcRes {
1275+
fn compile_test(&self) -> ProcRes {
12761276
let mut rustc = self.make_compile_args(
12771277
&self.testpaths.file,
12781278
TargetLocation::ThisFile(self.make_exe_name()),
12791279
);
12801280

1281-
if !extra_args.is_empty() {
1282-
rustc.args(extra_args);
1283-
}
12841281
rustc.arg("-L").arg(&self.aux_output_dir_name());
12851282

12861283
match self.config.mode {
@@ -1628,14 +1625,13 @@ impl<'test> TestCx<'test> {
16281625
}
16291626
}
16301627
Ui => {
1631-
// In case no "--error-format" has been given in the test, we'll compile
1632-
// a first time to get the compiler's output then compile with
1633-
// "--error-format json" to check if all expected errors are actually there
1634-
// and that no new one appeared.
1628+
if !self.props.compile_flags.iter().any(|s| s.starts_with("--error-format")) {
1629+
rustc.args(&["--error-format", "json"]);
1630+
}
16351631
if !self.props.disable_ui_testing_normalization {
16361632
rustc.arg("-Zui-testing");
16371633
}
1638-
}
1634+
},
16391635
MirOpt => {
16401636
rustc.args(&[
16411637
"-Zdump-mir=all",
@@ -2114,7 +2110,7 @@ impl<'test> TestCx<'test> {
21142110
fn run_codegen_units_test(&self) {
21152111
assert!(self.revision.is_none(), "revisions not relevant here");
21162112

2117-
let proc_res = self.compile_test(&[]);
2113+
let proc_res = self.compile_test();
21182114

21192115
if !proc_res.status.success() {
21202116
self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -2498,7 +2494,7 @@ impl<'test> TestCx<'test> {
24982494
.iter()
24992495
.any(|s| s.contains("--error-format"));
25002496

2501-
let proc_res = self.compile_test(&[]);
2497+
let proc_res = self.compile_test();
25022498
self.check_if_test_should_compile(&proc_res);
25032499

25042500
let expected_stderr_path = self.expected_output_path(UI_STDERR);
@@ -2510,8 +2506,13 @@ impl<'test> TestCx<'test> {
25102506
let normalized_stdout =
25112507
self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout);
25122508

2513-
let normalized_stderr = self.normalize_output(&proc_res.stderr,
2514-
&self.props.normalize_stderr);
2509+
let stderr = if explicit {
2510+
proc_res.stderr.clone()
2511+
} else {
2512+
json::extract_rendered(&proc_res.stderr, &proc_res)
2513+
};
2514+
2515+
let normalized_stderr = self.normalize_output(&stderr, &self.props.normalize_stderr);
25152516

25162517
let mut errors = 0;
25172518
errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
@@ -2544,7 +2545,6 @@ impl<'test> TestCx<'test> {
25442545
}
25452546
}
25462547
if !explicit {
2547-
let proc_res = self.compile_test(&["--error-format", "json"]);
25482548
if !expected_errors.is_empty() || !proc_res.status.success() {
25492549
// "// error-pattern" comments
25502550
self.check_expected_errors(expected_errors, &proc_res);
@@ -2556,7 +2556,7 @@ impl<'test> TestCx<'test> {
25562556
}
25572557

25582558
fn run_mir_opt_test(&self) {
2559-
let proc_res = self.compile_test(&[]);
2559+
let proc_res = self.compile_test();
25602560

25612561
if !proc_res.status.success() {
25622562
self.fatal_proc_rec("compilation failed!", &proc_res);

0 commit comments

Comments
 (0)