Skip to content

Commit fe28bcf

Browse files
committed
Check error-patterns on UI tests. Fixes #52531.
Previously, even if no expected errors were supplied, if a test execution failed then supplied error patterns would not be checked. This commit modifies the conditional that determines whether error patterns or expected errors are checked to remedy this. Further, this commit modifies the error pattern checking logic so that each pattern is checked against all lines of the string. This is required for UI tests as the stderr is in JSON format - all on one line - so in the previous implementation when the first pattern was found on the first line (which was actually the entire error) then no other patterns would be found on subsequent lines (as there weren't any).
1 parent a8763b5 commit fe28bcf

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/tools/compiletest/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl fmt::Display for Mode {
9696
}
9797
}
9898

99-
#[derive(Clone, PartialEq)]
99+
#[derive(Clone, Debug, PartialEq)]
100100
pub enum CompareMode {
101101
Nll,
102102
Polonius,

src/tools/compiletest/src/runtest.rs

+23-20
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,7 @@ impl<'test> TestCx<'test> {
11261126
}
11271127

11281128
fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) {
1129+
debug!("check_error_patterns");
11291130
if self.props.error_patterns.is_empty() {
11301131
if self.props.compile_pass {
11311132
return;
@@ -1136,34 +1137,29 @@ impl<'test> TestCx<'test> {
11361137
));
11371138
}
11381139
}
1139-
let mut next_err_idx = 0;
1140-
let mut next_err_pat = self.props.error_patterns[next_err_idx].trim();
1141-
let mut done = false;
1142-
for line in output_to_check.lines() {
1143-
if line.contains(next_err_pat) {
1144-
debug!("found error pattern {}", next_err_pat);
1145-
next_err_idx += 1;
1146-
if next_err_idx == self.props.error_patterns.len() {
1147-
debug!("found all error patterns");
1148-
done = true;
1149-
break;
1150-
}
1151-
next_err_pat = self.props.error_patterns[next_err_idx].trim();
1140+
1141+
let mut missing_patterns: Vec<String> = Vec::new();
1142+
1143+
for pattern in &self.props.error_patterns {
1144+
if output_to_check.contains(pattern.trim()) {
1145+
debug!("found error pattern {}", pattern);
1146+
} else {
1147+
missing_patterns.push(pattern.to_string());
11521148
}
11531149
}
1154-
if done {
1150+
1151+
if missing_patterns.is_empty() {
11551152
return;
11561153
}
11571154

1158-
let missing_patterns = &self.props.error_patterns[next_err_idx..];
11591155
if missing_patterns.len() == 1 {
11601156
self.fatal_proc_rec(
11611157
&format!("error pattern '{}' not found!", missing_patterns[0]),
11621158
proc_res,
11631159
);
11641160
} else {
11651161
for pattern in missing_patterns {
1166-
self.error(&format!("error pattern '{}' not found!", *pattern));
1162+
self.error(&format!("error pattern '{}' not found!", pattern));
11671163
}
11681164
self.fatal_proc_rec("multiple error patterns not found", proc_res);
11691165
}
@@ -1186,6 +1182,8 @@ impl<'test> TestCx<'test> {
11861182
}
11871183

11881184
fn check_expected_errors(&self, expected_errors: Vec<errors::Error>, proc_res: &ProcRes) {
1185+
debug!("check_expected_errors: expected_errors={:?} proc_res.status={:?}",
1186+
expected_errors, proc_res.status);
11891187
if proc_res.status.success()
11901188
&& expected_errors
11911189
.iter()
@@ -2668,12 +2666,17 @@ impl<'test> TestCx<'test> {
26682666
self.fatal_proc_rec("test run failed!", &proc_res);
26692667
}
26702668
}
2669+
2670+
debug!("run_ui_test: explicit={:?} config.compare_mode={:?} expected_errors={:?} \
2671+
proc_res.status={:?} props.error_patterns={:?}",
2672+
explicit, self.config.compare_mode, expected_errors, proc_res.status,
2673+
self.props.error_patterns);
26712674
if !explicit && self.config.compare_mode.is_none() {
2672-
if !expected_errors.is_empty() || !proc_res.status.success() {
2673-
// "// error-pattern" comments
2674-
self.check_expected_errors(expected_errors, &proc_res);
2675-
} else if !self.props.error_patterns.is_empty() || !proc_res.status.success() {
2675+
if !expected_errors.is_empty() && !proc_res.status.success() {
26762676
// "//~ERROR comments"
2677+
self.check_expected_errors(expected_errors, &proc_res);
2678+
} else if !self.props.error_patterns.is_empty() && !proc_res.status.success() {
2679+
// "// error-pattern" comments
26772680
self.check_error_patterns(&proc_res.stderr, &proc_res);
26782681
}
26792682
}

0 commit comments

Comments
 (0)