use std::io::Write;
use std::process::{Command, Output, Stdio};
const STDIN_CHILD_ENV: &str = "PARASEQ_STDIN_CHILD";
pub(crate) fn run_with_piped_stdin(test_path: &str, stdin_data: &[u8]) -> Output {
let exe = std::env::current_exe().expect("failed to resolve current test executable");
let mut child = Command::new(exe)
.args([test_path, "--exact", "--nocapture"])
.env(STDIN_CHILD_ENV, "1")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.expect("failed to spawn piped-stdin child test process");
child
.stdin
.take()
.expect("child stdin was not piped")
.write_all(stdin_data)
.expect("failed to write to child stdin");
child
.wait_with_output()
.expect("failed to wait for piped-stdin child test process")
}
pub(crate) fn is_stdin_child() -> bool {
std::env::var_os(STDIN_CHILD_ENV).is_some()
}