Skip to content

Commit b979a31

Browse files
authored
Rollup merge of #145431 - AMS21:fix_141531, r=jieyouxu
Enhance UI test output handling for runtime errors When a UI test runs a compiled binary and an error/forbid pattern check fails, the failure message previously only showed compiler output, hiding the executed programs stdout/stderr. This makes it harder to see near-miss or unexpected runtime lines. Fixed #141531 Supersedes #141977
2 parents c97a9c8 + dbd5add commit b979a31

File tree

1 file changed

+15
-3
lines changed
  • src/tools/compiletest/src/runtest

1 file changed

+15
-3
lines changed

src/tools/compiletest/src/runtest/ui.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::{
1010
TestCx, TestOutput, Truncated, UI_FIXED, WillExecute,
1111
};
1212
use crate::json;
13+
use crate::runtest::ProcRes;
1314

1415
impl TestCx<'_> {
1516
pub(super) fn run_ui_test(&self) {
@@ -127,6 +128,9 @@ impl TestCx<'_> {
127128
);
128129
}
129130

131+
// If the test is executed, capture its ProcRes separately so that
132+
// pattern/forbid checks can report the *runtime* stdout/stderr when they fail.
133+
let mut run_proc_res: Option<ProcRes> = None;
130134
let output_to_check = if let WillExecute::Yes = should_run {
131135
let proc_res = self.exec_compiled_test();
132136
let run_output_errors = if self.props.check_run_results {
@@ -189,7 +193,10 @@ impl TestCx<'_> {
189193
unreachable!("run_ui_test() must not be called if the test should not run");
190194
}
191195

192-
self.get_output(&proc_res)
196+
let output = self.get_output(&proc_res);
197+
// Move the proc_res into our option after we've extracted output.
198+
run_proc_res = Some(proc_res);
199+
output
193200
} else {
194201
self.get_output(&proc_res)
195202
};
@@ -200,9 +207,14 @@ impl TestCx<'_> {
200207
explicit, self.config.compare_mode, proc_res.status, self.props.error_patterns
201208
);
202209

210+
// Compiler diagnostics (expected errors) are always tied to the compile-time ProcRes.
203211
self.check_expected_errors(&proc_res);
204-
self.check_all_error_patterns(&output_to_check, &proc_res);
205-
self.check_forbid_output(&output_to_check, &proc_res);
212+
213+
// For runtime pattern/forbid checks prefer the executed program's ProcRes if available
214+
// so that missing pattern failures include the program's stdout/stderr.
215+
let pattern_proc_res = run_proc_res.as_ref().unwrap_or(&proc_res);
216+
self.check_all_error_patterns(&output_to_check, pattern_proc_res);
217+
self.check_forbid_output(&output_to_check, pattern_proc_res);
206218

207219
if self.props.run_rustfix && self.config.compare_mode.is_none() {
208220
// And finally, compile the fixed code and make sure it both

0 commit comments

Comments
 (0)