Skip to content

compiletest: never truncate stderr if we'll use it as json #96976

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/tools/compiletest/src/read2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub use self::imp::read2;
use std::io;
use std::process::{Child, Output};

pub fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
pub fn read2_abbreviated(mut child: Child, allow_stderr_truncation: bool) -> io::Result<Output> {
use io::Write;
use std::mem::replace;

Expand Down Expand Up @@ -45,6 +45,17 @@ pub fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
*self = new_self;
}

fn extend_no_truncate(&mut self, data: &[u8]) {
match *self {
ProcOutput::Full(ref mut bytes) => {
bytes.extend_from_slice(data);
}
ProcOutput::Abbreviated { .. } => {
panic!("must not use extend_no_truncate on abbreviated output")
}
};
}

fn into_bytes(self) -> Vec<u8> {
match self {
ProcOutput::Full(bytes) => bytes,
Expand All @@ -65,7 +76,15 @@ pub fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
child.stdout.take().unwrap(),
child.stderr.take().unwrap(),
&mut |is_stdout, data, _| {
if is_stdout { &mut stdout } else { &mut stderr }.extend(data);
if is_stdout {
stdout.extend(data);
} else {
if allow_stderr_truncation {
stderr.extend(data);
} else {
stderr.extend_no_truncate(data);
}
}
data.clear();
},
)?;
Expand Down
7 changes: 5 additions & 2 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,8 +1769,10 @@ impl<'test> TestCx<'test> {
child.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
}

// For Ui tests we parse the stderr as json, which breaks if the output gets truncated.
let allow_truncation = self.config.mode != Ui;
let Output { status, stdout, stderr } =
read2_abbreviated(child).expect("failed to read output");
read2_abbreviated(child, allow_truncation).expect("failed to read output");

let result = ProcRes {
status,
Expand Down Expand Up @@ -2959,7 +2961,8 @@ impl<'test> TestCx<'test> {
}
}

let output = cmd.spawn().and_then(read2_abbreviated).expect("failed to spawn `make`");
let output =
cmd.spawn().and_then(|c| read2_abbreviated(c, true)).expect("failed to spawn `make`");
if !output.status.success() {
let res = ProcRes {
status: output.status,
Expand Down