Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty print json in ui tests #45737

Merged
merged 5 commits into from
Nov 6, 2017
Merged

Pretty print json in ui tests #45737

merged 5 commits into from
Nov 6, 2017

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 3, 2017

I found the json output in one line to not be useful for reviewing

r? @petrochenkov

@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 3, 2017
@petrochenkov
Copy link
Contributor

Nice, this annoyed me too.

@@ -1104,6 +1104,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"enable ThinLTO when possible"),
inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED],
"control whether #[inline] functions are in all cgus"),
pretty_json_error_format: bool = (false, parse_bool, [UNTRACKED],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to add a new option? can -Z unstable_options be reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, that works :D

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2017

📌 Commit e5c1d51 has been approved by petrochenkov

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2017
@kennytm
Copy link
Member

kennytm commented Nov 4, 2017

@bors r-

The two JSON UI tests failed in the CI:

[00:45:18] failures:
[00:45:18]     [ui] ui/lint/unused_parens_json_suggestion.rs
[00:45:18]     [ui] ui/lint/use_suggestion_json.rs
ui/lint/unused_parens_json_suggestion.rs diff
 {
   "message": "unnecessary parentheses around assigned value",
   "code": {
     "code": "unused_parens",
     "explanation": null
   },
   "level": "warning",
   "spans": [
     {
       "file_name": "$DIR/unused_parens_json_suggestion.rs",
-      "byte_start": 1035,
-      "byte_end": 1048,
+      "byte_start": 1027,
+      "byte_end": 1040,
       "line_start": 24,
       "line_end": 24,
       "column_start": 14,
       "column_end": 27,
       "is_primary": true,
       "text": [
         {
           "text": "    let _a = (1 / (2 + 3));",
           "highlight_start": 14,
           "highlight_end": 27
         }
       ],
       "label": null,
       "suggested_replacement": null,
       "expansion": null
     }
   ],
   "children": [
     {
       "message": "lint level defined here",
       "code": null,
       "level": "note",
       "spans": [
         {
           "file_name": "$DIR/unused_parens_json_suggestion.rs",
-          "byte_start": 881,
-          "byte_end": 894,
+          "byte_start": 873,
+          "byte_end": 886,
           "line_start": 19,
           "line_end": 19,
           "column_start": 9,
           "column_end": 22,
           "is_primary": true,
           "text": [
             {
               "text": "#![warn(unused_parens)]",
               "highlight_start": 9,
               "highlight_end": 22
             }
           ],
           "label": null,
           "suggested_replacement": null,
           "expansion": null
         }
       ],
       "children": [],
       "rendered": null
     },
     {
       "message": "remove these parentheses",
       "code": null,
       "level": "help",
       "spans": [
         {
           "file_name": "$DIR/unused_parens_json_suggestion.rs",
-          "byte_start": 1035,
-          "byte_end": 1048,
+          "byte_start": 1027,
+          "byte_end": 1040,
           "line_start": 24,
           "line_end": 24,
           "column_start": 14,
           "column_end": 27,
           "is_primary": true,
           "text": [
             {
               "text": "    let _a = (1 / (2 + 3));",
               "highlight_start": 14,
               "highlight_end": 27
             }
           ],
           "label": null,
           "suggested_replacement": "1 / (2 + 3)",
           "expansion": null
         }
       ],
       "children": [],
       "rendered": null
     }
   ],
   "rendered": null
 }
ui/lint/use_suggestion_json.rs
 {
   "message": "cannot find type `Iter` in this scope",
   "code": {
     "code": "E0412",
     "explanation": "/nThe type name used is not in scope./n/nErroneous code examples:/n/n```compile_fail,E0412/nimpl Something {} // error: type name `Something` is not in scope/n/n// or:/n/ntrait Foo {/n    fn bar(N); // error: type name `N` is not in scope/n}/n/n// or:/n/nfn foo(x: T) {} // type name `T` is not in scope/n```/n/nTo fix this error, please verify you didn't misspell the type name, you did/ndeclare it or imported it into the scope. Examples:/n/n```/nstruct Something;/n/nimpl Something {} // ok!/n/n// or:/n/ntrait Foo {/n    type N;/n/n    fn bar(_: Self::N); // ok!/n}/n/n// or:/n/nfn foo<T>(x: T) {} // ok!/n```/n/nAnother case that causes this error is when a type is imported into a parent/nmodule. To fix this, you can follow the suggestion and use File directly or/n`use super::File;` which will import the types from the parent namespace. An/nexample that causes this error is below:/n/n```compile_fail,E0412/nuse std::fs::File;/n/nmod foo {/n    fn some_function(f: File) {}/n}/n```/n/n```/nuse std::fs::File;/n/nmod foo {/n    // either/n    use super::File;/n    // or/n    // use std::fs::File;/n    fn foo(f: File) {}/n}/n# fn main() {} // don't insert it for us; that'll break imports/n```/n"
   },
   "level": "error",
   "spans": [
     {
       "file_name": "$DIR/use_suggestion_json.rs",
-      "byte_start": 896,
-      "byte_end": 900,
+      "byte_start": 888,
+      "byte_end": 892,
       "line_start": 20,
       "line_end": 20,
       "column_start": 12,
       "column_end": 16,
       "is_primary": true,
       "text": [
         {
           "text": "    let x: Iter;",
           "highlight_start": 12,
           "highlight_end": 16
         }
       ],
       "label": "not found in this scope",
       "suggested_replacement": null,
       "expansion": null
     }
   ],
   "children": [
     {
       "message": "possible candidates are found in other modules, you can import them into scope",
       "code": null,
       "level": "help",
       "spans": [
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::binary_heap::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::btree_map::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::btree_set::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::hash_map::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::hash_set::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::linked_list::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::collections::vec_deque::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::option::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::path::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::result::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::slice::Iter;/n/n",
           "expansion": null
         },
         {
           "file_name": "$DIR/use_suggestion_json.rs",
-          "byte_start": 873,
-          "byte_end": 873,
+          "byte_start": 865,
+          "byte_end": 865,
           "line_start": 19,
           "line_end": 19,
           "column_start": 1,
           "column_end": 1,
           "is_primary": true,
           "text": [
             {
               "text": "fn main() {",
               "highlight_start": 1,
               "highlight_end": 1
             }
           ],
           "label": null,
           "suggested_replacement": "use std::sync::mpsc::Iter;/n/n",
           "expansion": null
         }
       ],
       "children": [],
       "rendered": null
     }
   ],
   "rendered": null
 }
 {
   "message": "aborting due to previous error",
   "code": null,
   "level": "error",
   "spans": [],
   "children": [],
   "rendered": null
 }

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 6, 2017

📌 Commit 6d6fb2e has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Nov 6, 2017

⌛ Testing commit 6d6fb2e with merge 74be072...

bors added a commit that referenced this pull request Nov 6, 2017
Pretty print json in ui tests

I found the json output in one line to not be useful for reviewing

r? @petrochenkov
@bors
Copy link
Contributor

bors commented Nov 6, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 74be072 to master...

@bors bors merged commit 6d6fb2e into rust-lang:master Nov 6, 2017
@oli-obk oli-obk deleted the json branch December 8, 2017 15:50
nnethercote added a commit to nnethercote/rust that referenced this pull request Jan 5, 2024
Currently for these two errors we go to the effort of switching to a
standard JSON emitter, for no obvious reason, and unlike any other
errors. This behaviour was added for `pretty-json` in rust-lang#45737, and then
`human-annotate-rs` copied it some time later when it was added.

This commit changes things to just using the requested emitter, which is
simpler and consistent with other errors.

Old output:
```
$ rustc --error-format pretty-json
{"$message_type":"diagnostic","message":"`--error-format=pretty-json` is unstable","code":null,"level":"error","spans":[],"children":[],"rendered":"error: `--error-format=pretty-json` is unstable\n\n"}

$ rustc --error-format human-annotate-rs
{"$message_type":"diagnostic","message":"`--error-format=human-annotate-rs` is unstable","code":null,"level":"error","spans":[],"children":[],"rendered":"error: `--error-format=human-annotate-rs` is unstable\n\n"}
```

New output:
```
$ rustc --error-format pretty-json
{
  "$message_type": "diagnostic",
  "message": "`--error-format=pretty-json` is unstable",
  "code": null,
  "level": "error",
  "spans": [],
  "children": [],
  "rendered": "error: `--error-format=pretty-json` is unstable\n\n"
}

$ rustc --error-format human-annotate-rs
error: `--error-format=human-annotate-rs` is unstable
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants