Skip to content

Commit 69a021f

Browse files
authored
Fix compiletest: don't abbreviate the output (rust-lang#1354)
1 parent cb1a606 commit 69a021f

File tree

2 files changed

+9
-64
lines changed

2 files changed

+9
-64
lines changed

tools/compiletest/src/read2.rs

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,26 @@
33
// Modifications Copyright Kani Contributors
44
// See GitHub history for details.
55

6-
// FIXME: This is a complete copy of `cargo/src/cargo/util/read2.rs`
7-
// Consider unify the read2() in libstd, cargo and this to prevent further code duplication.
8-
9-
pub use self::imp::read2;
106
use std::io;
117
use std::process::{Child, Output};
128

13-
pub fn read2_abbreviated(mut child: Child) -> io::Result<Output> {
14-
use io::Write;
15-
use std::mem::replace;
16-
17-
const HEAD_LEN: usize = 160 * 1024;
18-
const TAIL_LEN: usize = 256 * 1024;
19-
20-
enum ProcOutput {
21-
Full(Vec<u8>),
22-
Abbreviated { head: Vec<u8>, skipped: usize, tail: Box<[u8]> },
23-
}
24-
25-
impl ProcOutput {
26-
fn extend(&mut self, data: &[u8]) {
27-
let new_self = match *self {
28-
ProcOutput::Full(ref mut bytes) => {
29-
bytes.extend_from_slice(data);
30-
let new_len = bytes.len();
31-
if new_len <= HEAD_LEN + TAIL_LEN {
32-
return;
33-
}
34-
let tail = bytes.split_off(new_len - TAIL_LEN).into_boxed_slice();
35-
let head = replace(bytes, Vec::new());
36-
let skipped = new_len - HEAD_LEN - TAIL_LEN;
37-
ProcOutput::Abbreviated { head, skipped, tail }
38-
}
39-
ProcOutput::Abbreviated { ref mut skipped, ref mut tail, .. } => {
40-
*skipped += data.len();
41-
if data.len() <= TAIL_LEN {
42-
tail[..data.len()].copy_from_slice(data);
43-
tail.rotate_left(data.len());
44-
} else {
45-
tail.copy_from_slice(&data[(data.len() - TAIL_LEN)..]);
46-
}
47-
return;
48-
}
49-
};
50-
*self = new_self;
51-
}
52-
53-
fn into_bytes(self) -> Vec<u8> {
54-
match self {
55-
ProcOutput::Full(bytes) => bytes,
56-
ProcOutput::Abbreviated { mut head, skipped, tail } => {
57-
write!(&mut head, "\n\n<<<<<< SKIPPED {} BYTES >>>>>>\n\n", skipped).unwrap();
58-
head.extend_from_slice(&tail);
59-
head
60-
}
61-
}
62-
}
63-
}
64-
65-
let mut stdout = ProcOutput::Full(Vec::new());
66-
let mut stderr = ProcOutput::Full(Vec::new());
9+
pub fn read2(mut child: Child) -> io::Result<Output> {
10+
let mut stdout = Vec::new();
11+
let mut stderr = Vec::new();
6712

6813
drop(child.stdin.take());
69-
read2(
14+
self::imp::read2(
7015
child.stdout.take().unwrap(),
7116
child.stderr.take().unwrap(),
7217
&mut |is_stdout, data, _| {
73-
if is_stdout { &mut stdout } else { &mut stderr }.extend(data);
18+
let out = if is_stdout { &mut stdout } else { &mut stderr };
19+
out.extend(data.iter());
7420
data.clear();
7521
},
7622
)?;
7723
let status = child.wait()?;
7824

79-
Ok(Output { status, stdout: stdout.into_bytes(), stderr: stderr.into_bytes() })
25+
Ok(Output { status, stdout, stderr })
8026
}
8127

8228
#[cfg(not(any(unix, windows)))]

tools/compiletest/src/runtest.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::common::{CargoKani, Expected, Kani, KaniFixme, Stub};
1111
use crate::common::{Config, TestPaths};
1212
use crate::header::TestProps;
1313
use crate::json;
14-
use crate::read2::read2_abbreviated;
14+
use crate::read2::read2;
1515
use crate::util::logv;
1616
use regex::Regex;
1717

@@ -87,8 +87,7 @@ impl<'test> TestCx<'test> {
8787
let child = disable_error_reporting(|| command.spawn())
8888
.unwrap_or_else(|_| panic!("failed to exec `{:?}`", &command));
8989

90-
let Output { status, stdout, stderr } =
91-
read2_abbreviated(child).expect("failed to read output");
90+
let Output { status, stdout, stderr } = read2(child).expect("failed to read output");
9291

9392
let result = ProcRes {
9493
status,

0 commit comments

Comments
 (0)