]> git.lizzy.rs Git - rust.git/commitdiff
compiletest: A more verbose matching failure for mir tests
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Sat, 10 Dec 2016 21:24:29 +0000 (22:24 +0100)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Sat, 10 Dec 2016 21:27:40 +0000 (22:27 +0100)
This makes it easier to work with mir test failures during development.

- Show which expected line was not found
- Show full expected output
- Show full actual output

src/tools/compiletest/src/runtest.rs

index 3cc14541fcdf2ad02b3b99f87d749422e7df9a65..d65205fe65aa9cd0a527d65a91f7029100321278 100644 (file)
@@ -2294,7 +2294,18 @@ fn compare_mir_test_output(&self, test_name: &str, expected_content: &Vec<&str>)
                 };
             }
             if !found {
-                panic!("ran out of mir dump output to match against");
+                let normalize_all = dumped_string.lines()
+                                                 .map(nocomment_mir_line)
+                                                 .filter(|l| !l.is_empty())
+                                                 .collect::<Vec<_>>()
+                                                 .join("\n");
+                panic!("ran out of mir dump output to match against.\n\
+                        Did not find expected line: {:?}\n\
+                        Expected:\n{}\n\
+                        Actual:\n{}",
+                        expected_line,
+                        expected_content.join("\n"),
+                        normalize_all);
             }
         }
     }
@@ -2439,11 +2450,14 @@ enum TargetLocation {
 }
 
 fn normalize_mir_line(line: &str) -> String {
-    let no_comments = if let Some(idx) = line.find("//") {
+    nocomment_mir_line(line).replace(char::is_whitespace, "")
+}
+
+fn nocomment_mir_line(line: &str) -> &str {
+    if let Some(idx) = line.find("//") {
         let (l, _) = line.split_at(idx);
-        l
+        l.trim_right()
     } else {
         line
-    };
-    no_comments.replace(char::is_whitespace, "")
+    }
 }