]> git.lizzy.rs Git - rust.git/commitdiff
Update tools code
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 19 Feb 2018 19:53:04 +0000 (20:53 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 25 Feb 2018 11:14:43 +0000 (12:14 +0100)
src/tools/compiletest/src/json.rs
src/tools/compiletest/src/runtest.rs

index 99d7dc78166491209b1733aa6c068c983f9432ff..8e9cd1a12faacf79d96fa2f1bb6b909cf3e9d7f6 100644 (file)
@@ -57,25 +57,6 @@ struct DiagnosticCode {
     explanation: Option<String>,
 }
 
-pub fn extract_rendered(output: &str, proc_res: &ProcRes) -> String {
-    output.lines()
-        .filter_map(|line| if line.starts_with('{') {
-            match json::decode::<Diagnostic>(line) {
-                Ok(diagnostic) => diagnostic.rendered,
-                Err(error) => {
-                    proc_res.fatal(Some(&format!("failed to decode compiler output as json: \
-                                                `{}`\noutput: {}\nline: {}",
-                                                error,
-                                                line,
-                                                output)));
-                }
-            }
-        } else {
-            None
-        })
-        .collect()
-}
-
 pub fn parse_output(file_name: &str, output: &str, proc_res: &ProcRes) -> Vec<Error> {
     output.lines()
         .flat_map(|line| parse_line(file_name, line, output, proc_res))
index c0f82d56d80312963b149f5726656d0e7989fe4c..e5bee56de803515969be0d1f7d529c4157f77f69 100644 (file)
@@ -248,7 +248,7 @@ fn check_if_test_should_compile(&self, proc_res: &ProcRes) {
     }
 
     fn run_cfail_test(&self) {
-        let proc_res = self.compile_test();
+        let proc_res = self.compile_test(&[]);
         self.check_if_test_should_compile(&proc_res);
         self.check_no_compiler_crash(&proc_res);
 
@@ -267,7 +267,7 @@ fn run_cfail_test(&self) {
     }
 
     fn run_rfail_test(&self) {
-        let proc_res = self.compile_test();
+        let proc_res = self.compile_test(&[]);
 
         if !proc_res.status.success() {
             self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -309,7 +309,7 @@ fn check_correct_failure_status(&self, proc_res: &ProcRes) {
     }
 
     fn run_rpass_test(&self) {
-        let proc_res = self.compile_test();
+        let proc_res = self.compile_test(&[]);
 
         if !proc_res.status.success() {
             self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -336,7 +336,7 @@ fn run_valgrind_test(&self) {
             return self.run_rpass_test();
         }
 
-        let mut proc_res = self.compile_test();
+        let mut proc_res = self.compile_test(&[]);
 
         if !proc_res.status.success() {
             self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -578,7 +578,7 @@ fn run_debuginfo_gdb_test_no_opt(&self) {
         let mut cmds = commands.join("\n");
 
         // compile test file (it should have 'compile-flags:-g' in the header)
-        let compiler_run_result = self.compile_test();
+        let compiler_run_result = self.compile_test(&[]);
         if !compiler_run_result.status.success() {
             self.fatal_proc_rec("compilation failed!", &compiler_run_result);
         }
@@ -835,7 +835,7 @@ fn run_debuginfo_lldb_test(&self) {
 
     fn run_debuginfo_lldb_test_no_opt(&self) {
         // compile test file (it should have 'compile-flags:-g' in the header)
-        let compile_result = self.compile_test();
+        let compile_result = self.compile_test(&[]);
         if !compile_result.status.success() {
             self.fatal_proc_rec("compilation failed!", &compile_result);
         }
@@ -1272,12 +1272,15 @@ fn is_unexpected_compiler_message(
         }
     }
 
-    fn compile_test(&self) -> ProcRes {
+    fn compile_test(&self, extra_args: &[&'static str]) -> ProcRes {
         let mut rustc = self.make_compile_args(
             &self.testpaths.file,
             TargetLocation::ThisFile(self.make_exe_name()),
         );
 
+        if !extra_args.is_empty() {
+            rustc.args(extra_args);
+        }
         rustc.arg("-L").arg(&self.aux_output_dir_name());
 
         match self.config.mode {
@@ -1629,8 +1632,11 @@ fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> C
                 .iter()
                 .any(|s| s.starts_with("--error-format"))
             {
-                rustc.args(&["--error-format", "json"]);
-            },
+                // In case no "--error-format" has been given in the test, we'll compile
+                // a first time to get the compiler's output then compile with
+                // "--error-format json" to check if all expected errors are actually there
+                // and that no new one appeared.
+            }
             MirOpt => {
                 rustc.args(&[
                     "-Zdump-mir=all",
@@ -2109,7 +2115,7 @@ fn check_rustdoc_test_option(&self, res: ProcRes) {
     fn run_codegen_units_test(&self) {
         assert!(self.revision.is_none(), "revisions not relevant here");
 
-        let proc_res = self.compile_test();
+        let proc_res = self.compile_test(&[]);
 
         if !proc_res.status.success() {
             self.fatal_proc_rec("compilation failed!", &proc_res);
@@ -2493,7 +2499,7 @@ fn run_ui_test(&self) {
             .iter()
             .any(|s| s.contains("--error-format"));
 
-        let proc_res = self.compile_test();
+        let proc_res = self.compile_test(&[]);
         self.check_if_test_should_compile(&proc_res);
 
         let expected_stderr_path = self.expected_output_path(UI_STDERR);
@@ -2505,13 +2511,8 @@ fn run_ui_test(&self) {
         let normalized_stdout =
             self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout);
 
-        let stderr = if explicit {
-            proc_res.stderr.clone()
-        } else {
-            json::extract_rendered(&proc_res.stderr, &proc_res)
-        };
-
-        let normalized_stderr = self.normalize_output(&stderr, &self.props.normalize_stderr);
+        let normalized_stderr = self.normalize_output(&proc_res.stderr,
+                                                      &self.props.normalize_stderr);
 
         let mut errors = 0;
         errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
@@ -2544,6 +2545,7 @@ fn run_ui_test(&self) {
             }
         }
         if !explicit {
+            let proc_res = self.compile_test(&["--error-format", "json"]);
             if !expected_errors.is_empty() || !proc_res.status.success() {
                 // "// error-pattern" comments
                 self.check_expected_errors(expected_errors, &proc_res);
@@ -2555,7 +2557,7 @@ fn run_ui_test(&self) {
     }
 
     fn run_mir_opt_test(&self) {
-        let proc_res = self.compile_test();
+        let proc_res = self.compile_test(&[]);
 
         if !proc_res.status.success() {
             self.fatal_proc_rec("compilation failed!", &proc_res);