about summary refs log tree commit diff
path: root/src/tools/compiletest
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-11-22 01:12:59 +0800
committerGitHub <noreply@github.com>2017-11-22 01:12:59 +0800
commit0af67a4df0219d518ecba6711ff8ff6680a9a2ec (patch)
tree850fd666fcd77c62c2cdf792282e7bd106ef8ebc /src/tools/compiletest
parent9b090a026108fab89cfe5f39bfd3492597e76ad4 (diff)
parente7b2702172b91624406e8c90716a225e8ec1a299 (diff)
downloadrust-0af67a4df0219d518ecba6711ff8ff6680a9a2ec.tar.gz
rust-0af67a4df0219d518ecba6711ff8ff6680a9a2ec.zip
Rollup merge of #46052 - oli-obk:rendered_diagnostics_in_json, r=petrochenkov
Include rendered diagnostic in json

r? @petrochenkov
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/src/runtest.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 749d1f4c378..1fd48881ba2 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -2424,15 +2424,25 @@ actual:\n\
     fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String {
         let parent_dir = self.testpaths.file.parent().unwrap();
         let cflags = self.props.compile_flags.join(" ");
-        let parent_dir_str = if cflags.contains("--error-format json")
-                             || cflags.contains("--error-format pretty-json") {
+        let json = cflags.contains("--error-format json") ||
+                   cflags.contains("--error-format pretty-json");
+        let parent_dir_str = if json {
             parent_dir.display().to_string().replace("\\", "\\\\")
         } else {
             parent_dir.display().to_string()
         };
 
-        let mut normalized = output.replace(&parent_dir_str, "$DIR")
-              .replace("\\\\", "\\") // denormalize for paths on windows
+        let mut normalized = output.replace(&parent_dir_str, "$DIR");
+
+        if json {
+            // escaped newlines in json strings should be readable
+            // in the stderr files. There's no point int being correct,
+            // since only humans process the stderr files.
+            // Thus we just turn escaped newlines back into newlines.
+            normalized = normalized.replace("\\n", "\n");
+        }
+
+        normalized = normalized.replace("\\\\", "\\") // denormalize for paths on windows
               .replace("\\", "/") // normalize for paths on windows
               .replace("\r\n", "\n") // normalize for linebreaks on windows
               .replace("\t", "\\t"); // makes tabs visible