#![cfg(unix)]
use std::io::{Read, Write};
use std::os::unix::process::ExitStatusExt;
use std::process::{Command, Stdio};
const SIGPIPE: i32 = 13;
#[test]
fn broken_pipe_terminates_via_sigpipe_not_panic() {
let big = format!(
"[{}]",
(0..200_000)
.map(|i| i.to_string())
.collect::<Vec<_>>()
.join(",")
);
let mut input = tempfile::NamedTempFile::new().unwrap();
input.write_all(big.as_bytes()).unwrap();
let mut child = Command::new(env!("CARGO_BIN_EXE_jpx"))
.arg("@")
.arg(input.path())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
{
let mut out = child.stdout.take().unwrap();
let mut buf = [0u8; 16];
let _ = out.read(&mut buf);
}
let status = child.wait().unwrap();
assert_eq!(
status.signal(),
Some(SIGPIPE),
"expected termination by SIGPIPE, got {status:?}"
);
}