about summary refs log tree commit diff
path: root/src/tools/compiletest
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-05-03 11:26:58 -0700
committerAlex Crichton <alex@alexcrichton.com>2018-05-04 15:01:28 -0700
commit6f2d023028bbd666be2c211b923b32faf10a41da (patch)
treec53c956b4e906922c9de96ec644394b5c1114815 /src/tools/compiletest
parenta563027cb8f2cb1c46d2a1e59f3686d3f3a3213a (diff)
Fold rustfix tests back into the UI test suite
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/src/common.rs3
-rw-r--r--src/tools/compiletest/src/header.rs10
-rw-r--r--src/tools/compiletest/src/runtest.rs93
3 files changed, 44 insertions, 62 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs
index 733fc1f16d2..2df52816599 100644
--- a/src/tools/compiletest/src/common.rs
+++ b/src/tools/compiletest/src/common.rs
@@ -32,7 +32,6 @@ pub enum Mode {
     RunMake,
     Ui,
     MirOpt,
-    Rustfix,
 }
 
 impl Mode {
@@ -68,7 +67,6 @@ impl FromStr for Mode {
             "run-make" => Ok(RunMake),
             "ui" => Ok(Ui),
             "mir-opt" => Ok(MirOpt),
-            "rustfix" => Ok(Rustfix),
             _ => Err(()),
         }
     }
@@ -92,7 +90,6 @@ impl fmt::Display for Mode {
             RunMake => "run-make",
             Ui => "ui",
             MirOpt => "mir-opt",
-            Rustfix => "rustfix",
         };
         fmt::Display::fmt(s, f)
     }
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index 73dd079cf0c..7ac3f5b5b25 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -236,6 +236,7 @@ pub struct TestProps {
     pub normalize_stdout: Vec<(String, String)>,
     pub normalize_stderr: Vec<(String, String)>,
     pub failure_status: i32,
+    pub run_rustfix: bool,
 }
 
 impl TestProps {
@@ -267,6 +268,7 @@ impl TestProps {
             normalize_stdout: vec![],
             normalize_stderr: vec![],
             failure_status: 101,
+            run_rustfix: false,
         }
     }
 
@@ -403,6 +405,10 @@ impl TestProps {
             if let Some(code) = config.parse_failure_status(ln) {
                 self.failure_status = code;
             }
+
+            if !self.run_rustfix {
+                self.run_rustfix = config.parse_run_rustfix(ln);
+            }
         });
 
         for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
@@ -642,6 +648,10 @@ impl Config {
 
         None
     }
+
+    fn parse_run_rustfix(&self, line: &str) -> bool {
+        self.parse_name_directive(line, "run-rustfix")
+    }
 }
 
 pub fn lldb_version_to_int(version_string: &str) -> isize {
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index ea1863b2fd1..fae75c352da 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -11,7 +11,7 @@
 use common::{Config, TestPaths};
 use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
 use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc};
-use common::{Incremental, MirOpt, RunMake, Ui, Rustfix};
+use common::{Incremental, MirOpt, RunMake, Ui};
 use common::{expected_output_path, UI_STDERR, UI_STDOUT, UI_FIXED};
 use common::CompareMode;
 use diff;
@@ -242,7 +242,6 @@ impl<'test> TestCx<'test> {
             CodegenUnits => self.run_codegen_units_test(),
             Incremental => self.run_incremental_test(),
             RunMake => self.run_rmake_test(),
-            Rustfix => self.run_rustfix_test(),
             Ui => self.run_ui_test(),
             MirOpt => self.run_mir_opt_test(),
         }
@@ -1689,7 +1688,6 @@ impl<'test> TestCx<'test> {
 
                 rustc.arg(dir_opt);
             }
-            Rustfix |
             RunPass |
             RunFail |
             RunPassValgrind |
@@ -2555,6 +2553,7 @@ impl<'test> TestCx<'test> {
 
         let expected_stderr = self.load_expected_output(UI_STDERR);
         let expected_stdout = self.load_expected_output(UI_STDOUT);
+        let expected_fixed = self.load_expected_output(UI_FIXED);
 
         let normalized_stdout =
             self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout);
@@ -2571,6 +2570,21 @@ impl<'test> TestCx<'test> {
         errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
         errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr);
 
+        if self.config.compare_mode.is_some() {
+            // don't test rustfix with nll right now
+        } else if self.props.run_rustfix {
+            // Apply suggestions from rustc to the code itself
+            let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file)
+                .unwrap();
+            let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap();
+            let fixed_code = apply_suggestions(&unfixed_code, &suggestions);
+
+            errors += self.compare_output("fixed", &fixed_code, &expected_fixed);
+        } else if !expected_fixed.is_empty() {
+            panic!("the `// run-rustfix` directive wasn't found but a `*.fixed` \
+                    file was found");
+        }
+
         if errors > 0 {
             println!("To update references, run this command from build directory:");
             let relative_path_to_file = self.testpaths
@@ -2606,6 +2620,23 @@ impl<'test> TestCx<'test> {
                 self.check_error_patterns(&proc_res.stderr, &proc_res);
             }
         }
+
+        if self.props.run_rustfix && self.config.compare_mode.is_none() {
+            // And finally, compile the fixed code and make sure it both
+            // succeeds and has no diagnostics.
+            let mut rustc = self.make_compile_args(
+                &self.testpaths.file.with_extension(UI_FIXED),
+                TargetLocation::ThisFile(self.make_exe_name()),
+            );
+            rustc.arg("-L").arg(&self.aux_output_dir_name());
+            let res = self.compose_and_run_compiler(rustc, None);
+            if !res.status.success() {
+                self.fatal_proc_rec("failed to compile fixed code", &res);
+            }
+            if !res.stderr.is_empty() {
+                self.fatal_proc_rec("fixed code is still producing diagnostics", &res);
+            }
+        }
     }
 
     fn run_mir_opt_test(&self) {
@@ -2930,62 +2961,6 @@ impl<'test> TestCx<'test> {
         println!("Actual {} saved to {}", kind, output_file.display());
         1
     }
-
-    fn run_rustfix_test(&self) {
-        // First up, compile the test with --error-format=json
-        let mut rustc = self.make_compile_args(
-            &self.testpaths.file,
-            TargetLocation::ThisFile(self.make_exe_name()),
-        );
-        rustc.arg("--error-format").arg("json")
-            .arg("-L").arg(&self.aux_output_dir_name());
-        let proc_res = self.compose_and_run_compiler(rustc, None);
-
-        // Now apply suggestions from rustc to the code itself
-        let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file)
-            .unwrap();
-        let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap();
-        let fixed_code = apply_suggestions(&unfixed_code, &suggestions);
-
-        // Load up what the expected result of fixing should be
-        let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED);
-        let expected_fixed = self.load_expected_output_from_path(&fixture_path)
-            .unwrap_or(String::new());
-
-        // Make sure our fixed code is the same as what we're expecting
-        let errors = self.compare_output(UI_FIXED, &fixed_code, &expected_fixed);
-        if errors > 0 {
-            println!("To update references, run this command from build directory:");
-            let relative_path_to_file = self.testpaths
-                .relative_dir
-                .join(self.testpaths.file.file_name().unwrap());
-            println!(
-                "{}/update-references.sh '{}' '{}'",
-                self.config.src_base.display(),
-                self.config.build_base.display(),
-                relative_path_to_file.display()
-            );
-            self.fatal_proc_rec(
-                &format!("{} errors occurred comparing output.", errors),
-                &proc_res,
-            );
-        }
-
-        // And finally, compile the fixed code and make sure it both succeeds
-        // and has no diagnostics.
-        let mut rustc = self.make_compile_args(
-            &self.testpaths.file.with_extension(UI_FIXED),
-            TargetLocation::ThisFile(self.make_exe_name()),
-        );
-        rustc.arg("-L").arg(&self.aux_output_dir_name());
-        let res = self.compose_and_run_compiler(rustc, None);
-        if !res.status.success() {
-            self.fatal_proc_rec("failed to compile fixed code", &res);
-        }
-        if !res.stderr.is_empty() {
-            self.fatal_proc_rec("fixed code is still producing diagnostics", &res);
-        }
-    }
 }
 
 struct ProcArgs {