未验证 提交 fe28bcf1 编写于 作者: D David Wood

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).
上级 a8763b53
......@@ -96,7 +96,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
#[derive(Clone, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum CompareMode {
Nll,
Polonius,
......
......@@ -1126,6 +1126,7 @@ fn check_single_line(line: &str, check_line: &str) -> bool {
}
fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) {
debug!("check_error_patterns");
if self.props.error_patterns.is_empty() {
if self.props.compile_pass {
return;
......@@ -1136,26 +1137,21 @@ fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) {
));
}
}
let mut next_err_idx = 0;
let mut next_err_pat = self.props.error_patterns[next_err_idx].trim();
let mut done = false;
for line in output_to_check.lines() {
if line.contains(next_err_pat) {
debug!("found error pattern {}", next_err_pat);
next_err_idx += 1;
if next_err_idx == self.props.error_patterns.len() {
debug!("found all error patterns");
done = true;
break;
}
next_err_pat = self.props.error_patterns[next_err_idx].trim();
let mut missing_patterns: Vec<String> = Vec::new();
for pattern in &self.props.error_patterns {
if output_to_check.contains(pattern.trim()) {
debug!("found error pattern {}", pattern);
} else {
missing_patterns.push(pattern.to_string());
}
}
if done {
if missing_patterns.is_empty() {
return;
}
let missing_patterns = &self.props.error_patterns[next_err_idx..];
if missing_patterns.len() == 1 {
self.fatal_proc_rec(
&format!("error pattern '{}' not found!", missing_patterns[0]),
......@@ -1163,7 +1159,7 @@ fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) {
);
} else {
for pattern in missing_patterns {
self.error(&format!("error pattern '{}' not found!", *pattern));
self.error(&format!("error pattern '{}' not found!", pattern));
}
self.fatal_proc_rec("multiple error patterns not found", proc_res);
}
......@@ -1186,6 +1182,8 @@ fn check_forbid_output(&self, output_to_check: &str, proc_res: &ProcRes) {
}
fn check_expected_errors(&self, expected_errors: Vec<errors::Error>, proc_res: &ProcRes) {
debug!("check_expected_errors: expected_errors={:?} proc_res.status={:?}",
expected_errors, proc_res.status);
if proc_res.status.success()
&& expected_errors
.iter()
......@@ -2668,12 +2666,17 @@ fn run_ui_test(&self) {
self.fatal_proc_rec("test run failed!", &proc_res);
}
}
debug!("run_ui_test: explicit={:?} config.compare_mode={:?} expected_errors={:?} \
proc_res.status={:?} props.error_patterns={:?}",
explicit, self.config.compare_mode, expected_errors, proc_res.status,
self.props.error_patterns);
if !explicit && self.config.compare_mode.is_none() {
if !expected_errors.is_empty() || !proc_res.status.success() {
// "// error-pattern" comments
self.check_expected_errors(expected_errors, &proc_res);
} else if !self.props.error_patterns.is_empty() || !proc_res.status.success() {
if !expected_errors.is_empty() && !proc_res.status.success() {
// "//~ERROR comments"
self.check_expected_errors(expected_errors, &proc_res);
} else if !self.props.error_patterns.is_empty() && !proc_res.status.success() {
// "// error-pattern" comments
self.check_error_patterns(&proc_res.stderr, &proc_res);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册