Navigation Menu

Skip to content

Commit

Permalink
Check error-patterns on UI tests. Fixes #52531.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
davidtwco committed Aug 14, 2018
1 parent a8763b5 commit fe28bcf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/common.rs
Expand Up @@ -96,7 +96,7 @@ impl fmt::Display for Mode {
}
}

#[derive(Clone, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum CompareMode {
Nll,
Polonius,
Expand Down
43 changes: 23 additions & 20 deletions src/tools/compiletest/src/runtest.rs
Expand Up @@ -1126,6 +1126,7 @@ impl<'test> TestCx<'test> {
}

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;
Expand All @@ -1136,34 +1137,29 @@ impl<'test> TestCx<'test> {
));
}
}
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]),
proc_res,
);
} 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);
}
Expand All @@ -1186,6 +1182,8 @@ impl<'test> TestCx<'test> {
}

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()
Expand Down Expand Up @@ -2668,12 +2666,17 @@ impl<'test> TestCx<'test> {
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);
}
}
Expand Down

0 comments on commit fe28bcf

Please sign in to comment.