about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-08-08 13:31:42 +0200
committerDavid Wood <david@davidtw.co>2018-08-14 10:37:54 +0200
commitfe28bcf1db02afe184e3677ee034b2a5804f2466 (patch)
tree8e9f570b434a3581ac054af973f26b526d7bdf28
parenta8763b5370ed044b6e703981217f074e8ddf1e7c (diff)
downloadrust-fe28bcf1db02afe184e3677ee034b2a5804f2466.tar.gz
rust-fe28bcf1db02afe184e3677ee034b2a5804f2466.zip
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).
-rw-r--r--src/tools/compiletest/src/common.rs2
-rw-r--r--src/tools/compiletest/src/runtest.rs43
2 files changed, 24 insertions, 21 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
index 951a72fec68..6679ec79c1d 100644
--- a/src/tools/compiletest/src/common.rs
+++ b/src/tools/compiletest/src/common.rs
@@ -96,7 +96,7 @@ impl fmt::Display for Mode {
     }
 }
 
-#[derive(Clone, PartialEq)]
+#[derive(Clone, Debug, PartialEq)]
 pub enum CompareMode {
     Nll,
     Polonius,
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index c8f3956415d..56cf553dc82 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -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;
@@ -1136,26 +1137,21 @@ 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]),
@@ -1163,7 +1159,7 @@ impl<'test> TestCx<'test> {
             );
         } 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 @@ 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()
@@ -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);
             }
         }