Skip to content

Commit ec3a4e4

Browse files
authored
Rollup merge of #59128 - oli-obk:colorful_json, r=mark-i-m,eddyb
Emit ansi color codes in the `rendered` field of json diagnostics cc @ljedrz Implemented for rust-lang/rust#56595 (comment) (x.py clippy)
2 parents a4b8cc1 + 17719dc commit ec3a4e4

File tree

2 files changed

+8
-45
lines changed

2 files changed

+8
-45
lines changed

src/json.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,20 @@ struct DiagnosticCode {
6262
explanation: Option<String>,
6363
}
6464

65-
pub fn extract_rendered(output: &str, proc_res: &ProcRes) -> String {
65+
pub fn extract_rendered(output: &str) -> String {
6666
output
6767
.lines()
6868
.filter_map(|line| {
6969
if line.starts_with('{') {
7070
match serde_json::from_str::<Diagnostic>(line) {
7171
Ok(diagnostic) => diagnostic.rendered,
7272
Err(error) => {
73-
proc_res.fatal(Some(&format!(
73+
print!(
7474
"failed to decode compiler output as json: \
7575
`{}`\nline: {}\noutput: {}",
7676
error, line, output
77-
)));
77+
);
78+
panic!()
7879
}
7980
}
8081
} else {

src/runtest.rs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,50 +2090,10 @@ impl<'test> TestCx<'test> {
20902090
}
20912091

20922092
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
2093-
self.try_print_open_handles();
20942093
self.error(err);
20952094
proc_res.fatal(None);
20962095
}
20972096

2098-
// This function is a poor man's attempt to debug rust-lang/rust#38620, if
2099-
// that's closed then this should be deleted
2100-
//
2101-
// This is a very "opportunistic" debugging attempt, so we ignore all
2102-
// errors here.
2103-
fn try_print_open_handles(&self) {
2104-
if !cfg!(windows) {
2105-
return;
2106-
}
2107-
if self.config.mode != Incremental {
2108-
return;
2109-
}
2110-
2111-
let filename = match self.testpaths.file.file_stem() {
2112-
Some(path) => path,
2113-
None => return,
2114-
};
2115-
2116-
let mut cmd = Command::new("handle.exe");
2117-
cmd.arg("-a").arg("-u");
2118-
cmd.arg(filename);
2119-
cmd.arg("-nobanner");
2120-
cmd.stdout(Stdio::piped());
2121-
cmd.stderr(Stdio::piped());
2122-
let output = match cmd.spawn().and_then(read2_abbreviated) {
2123-
Ok(output) => output,
2124-
Err(_) => return,
2125-
};
2126-
println!("---------------------------------------------------");
2127-
println!("ran extra command to debug rust-lang/rust#38620: ");
2128-
println!("{:?}", cmd);
2129-
println!("result: {}", output.status);
2130-
println!("--- stdout ----------------------------------------");
2131-
println!("{}", String::from_utf8_lossy(&output.stdout));
2132-
println!("--- stderr ----------------------------------------");
2133-
println!("{}", String::from_utf8_lossy(&output.stderr));
2134-
println!("---------------------------------------------------");
2135-
}
2136-
21372097
// codegen tests (using FileCheck)
21382098

21392099
fn compile_test_and_save_ir(&self) -> ProcRes {
@@ -2844,7 +2804,7 @@ impl<'test> TestCx<'test> {
28442804
let stderr = if explicit {
28452805
proc_res.stderr.clone()
28462806
} else {
2847-
json::extract_rendered(&proc_res.stderr, &proc_res)
2807+
json::extract_rendered(&proc_res.stderr)
28482808
};
28492809

28502810
let normalized_stderr = self.normalize_output(&stderr, &self.props.normalize_stderr);
@@ -3464,7 +3424,9 @@ impl ProcRes {
34643424
{}\n\
34653425
------------------------------------------\n\
34663426
\n",
3467-
self.status, self.cmdline, self.stdout, self.stderr
3427+
self.status, self.cmdline,
3428+
json::extract_rendered(&self.stdout),
3429+
json::extract_rendered(&self.stderr),
34683430
);
34693431
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
34703432
// compiletest, which is unnecessary noise.

0 commit comments

Comments
 (0)