Skip to content

Commit ea62b8e

Browse files
committed
Add regression test for rustc/rustdoc broken pipe ICEs
1 parent 328bc7e commit ea62b8e

File tree

1 file changed

+43
-0
lines changed
  • tests/run-make/broken-pipe-no-ice

1 file changed

+43
-0
lines changed
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//! Check that `rustc` and `rustdoc` does not ICE upon encountering a broken pipe due to unhandled
2+
//! panics from raw std `println!` usages.
3+
//!
4+
//! Regression test for <https://github.com/rust-lang/rust/issues/34376>.
5+
6+
//@ ignore-cross-compile (needs to run test binary)
7+
8+
#![feature(anonymous_pipe)]
9+
10+
use std::io::Read;
11+
use std::os::unix::process::ExitStatusExt;
12+
use std::process::{Command, Stdio};
13+
14+
use run_make_support::{env_var, libc};
15+
16+
fn check_broken_pipe_handled_gracefully(name: &str, mut cmd: Command) {
17+
let (reader, writer) = std::pipe::pipe().unwrap();
18+
drop(reader); // close read-end
19+
cmd.stdout(writer).stderr(Stdio::piped());
20+
21+
let mut child = cmd.spawn().unwrap();
22+
23+
let mut stderr = String::new();
24+
child.stderr.as_mut().unwrap().read_to_string(&mut stderr).unwrap();
25+
let status = child.wait().unwrap();
26+
27+
assert!(!status.success(), "{name}");
28+
29+
const PANIC_ICE_EXIT_STATUS: i32 = 101;
30+
assert_ne!(status.code(), Some(101), "{name}");
31+
32+
assert!(stderr.is_empty(), "{name} stderr:\n{}", stderr);
33+
}
34+
35+
fn main() {
36+
let mut rustc = Command::new(env_var("RUSTC"));
37+
rustc.arg("--print=sysroot");
38+
check_broken_pipe_handled_gracefully("rustc", rustc);
39+
40+
let mut rustdoc = Command::new(env_var("RUSTDOC"));
41+
rustdoc.arg("--version");
42+
check_broken_pipe_handled_gracefully("rustdoc", rustdoc);
43+
}

0 commit comments

Comments
 (0)