about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-03-03 11:17:32 -0500
committerNiko Matsakis <niko@alum.mit.edu>2016-03-03 11:17:32 -0500
commitaa19b41f2549b8456c3f99200d819a726b2c5aab (patch)
treeddaa5e8ada374b82f7545b74010aa5a0840ba684
parent9601e6f252f725f1aa90b15cab0e22732b0076ee (diff)
downloadrust-aa19b41f2549b8456c3f99200d819a726b2c5aab.tar.gz
rust-aa19b41f2549b8456c3f99200d819a726b2c5aab.zip
make pretty printer tests understand revisions, and make them ignore the
should-fail annotation
-rw-r--r--src/compiletest/compiletest.rs19
-rw-r--r--src/compiletest/runtest.rs33
2 files changed, 32 insertions, 20 deletions
diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs
index 1042359d05b..99745d840f7 100644
--- a/src/compiletest/compiletest.rs
+++ b/src/compiletest/compiletest.rs
@@ -355,15 +355,24 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
 
 pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn {
     let early_props = header::early_props(config, &testpaths.file);
+
+    // The `should-fail` annotation doesn't apply to pretty tests,
+    // since we run the pretty printer across all tests by default.
+    // If desired, we could add a `should-fail-pretty` annotation.
+    let should_panic = match config.mode {
+        Pretty => test::ShouldPanic::No,
+        _ => if early_props.should_fail {
+            test::ShouldPanic::Yes
+        } else {
+            test::ShouldPanic::No
+        }
+    };
+
     test::TestDescAndFn {
         desc: test::TestDesc {
             name: make_test_name(config, testpaths),
             ignore: early_props.ignore,
-            should_panic: if early_props.should_fail {
-                test::ShouldPanic::Yes
-            } else {
-                test::ShouldPanic::No
-            },
+            should_panic: should_panic,
         },
         testfn: make_test_closure(config, testpaths),
     }
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index c3a7d9c053a..1d2f560f5f6 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -213,12 +213,13 @@ fn run_valgrind_test(config: &Config, props: &TestProps, testpaths: &TestPaths)
 }
 
 fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
-    // Note: because we run the --pretty tests on the code in run-pass etc,
-    // we may see a list of revisions -- but we can just ignore them.
-    // We cannot assert that the list is empty as we do elsewhere.
-    //
-    // assert!(props.revisions.is_empty(), "revisions not relevant here");
+    for_each_revision(config, props, testpaths, run_pretty_test_revision);
+}
 
+fn run_pretty_test_revision(config: &Config,
+                            props: &TestProps,
+                            testpaths: &TestPaths,
+                            revision: Option<&str>) {
     if props.pp_exact.is_some() {
         logv(config, "testing for exact pretty-printing".to_owned());
     } else {
@@ -234,7 +235,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
 
     let mut round = 0;
     while round < rounds {
-        logv(config, format!("pretty-printing round {}", round));
+        logv(config, format!("pretty-printing round {} revision {:?}",
+                             round, revision));
         let proc_res = print_source(config,
                                     props,
                                     testpaths,
@@ -242,8 +244,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
                                     &props.pretty_mode);
 
         if !proc_res.status.success() {
-            fatal_proc_rec(None,
-                           &format!("pretty-printing failed in round {}", round),
+            fatal_proc_rec(revision,
+                           &format!("pretty-printing failed in round {} revision {:?}",
+                                    round, revision),
                            &proc_res);
         }
 
@@ -270,30 +273,30 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
         expected = expected.replace(&cr, "").to_owned();
     }
 
-    compare_source(&expected, &actual);
+    compare_source(revision, &expected, &actual);
 
     // If we're only making sure that the output matches then just stop here
     if props.pretty_compare_only { return; }
 
     // Finally, let's make sure it actually appears to remain valid code
     let proc_res = typecheck_source(config, props, testpaths, actual);
-
     if !proc_res.status.success() {
-        fatal_proc_rec(None, "pretty-printed source does not typecheck", &proc_res);
+        fatal_proc_rec(revision, "pretty-printed source does not typecheck", &proc_res);
     }
+
     if !props.pretty_expanded { return }
 
     // additionally, run `--pretty expanded` and try to build it.
     let proc_res = print_source(config, props, testpaths, srcs[round].clone(), "expanded");
     if !proc_res.status.success() {
-        fatal_proc_rec(None, "pretty-printing (expanded) failed", &proc_res);
+        fatal_proc_rec(revision, "pretty-printing (expanded) failed", &proc_res);
     }
 
     let ProcRes{ stdout: expanded_src, .. } = proc_res;
     let proc_res = typecheck_source(config, props, testpaths, expanded_src);
     if !proc_res.status.success() {
         fatal_proc_rec(
-            None,
+            revision,
             "pretty-printed source (expanded) does not typecheck",
             &proc_res);
     }
@@ -339,9 +342,9 @@ fn run_pretty_test(config: &Config, props: &TestProps, testpaths: &TestPaths) {
         };
     }
 
-    fn compare_source(expected: &str, actual: &str) {
+    fn compare_source(revision: Option<&str>, expected: &str, actual: &str) {
         if expected != actual {
-            error(None, "pretty-printed source does not match expected source");
+            error(revision, "pretty-printed source does not match expected source");
             println!("\n\
 expected:\n\
 ------------------------------------------\n\