use crate::pipe::windows::is_overlapped;
use crate::pipe::ParentEnd;
use crate::stdio::{Direction, Fd, Stdio};
use crate::test_child::Console;
fn overlapped(end: &ParentEnd) -> bool {
is_overlapped(crate::test_child::parent_handle(end)).expect("query the mode")
}
#[skuld::test]
async fn the_async_spawns_parent_ends_are_overlapped() {
type Row<'a> = (&'a str, &'a [(i32, Direction)], Option<(i32, i32)>);
let rows: [Row; 3] = [
(
"std path",
&[(0, Direction::In), (1, Direction::Out), (2, Direction::Out)],
None,
),
(
"raw backend",
&[
(0, Direction::In),
(1, Direction::Out),
(2, Direction::Out),
(3, Direction::Out),
(4, Direction::In),
],
None,
),
("merge target", &[(1, Direction::Out)], Some((2, 1))),
];
for (row, pipes, merge) in rows {
let mut cmd = crate::test_child::tokio_command(Console::Hidden);
cmd.args(["cmd", "/C", "exit 0"]);
for &(slot, dir) in pipes {
cmd.fd(
slot,
match dir {
Direction::In => Stdio::pipe_in(),
Direction::Out => Stdio::pipe_out(),
},
)
.expect("set the pipe");
}
if let Some((slot, target)) = merge {
cmd.fd(slot, Stdio::merge(Fd::from(target))).expect("set the merge");
}
let mut child = cmd.spawn().expect("spawn");
let kept: Vec<(Fd, &ParentEnd)> = child.os.pipes.iter().map(|(fd, end)| (*fd, end)).collect();
let mut slots: Vec<i32> = kept.iter().map(|(fd, _)| fd.raw()).collect();
slots.sort_unstable();
let mut expected: Vec<i32> = pipes.iter().map(|&(slot, _)| slot).collect();
expected.sort_unstable();
assert_eq!(slots, expected, "{row}: the spawn keeps these parent ends");
for (fd, end) in kept {
assert!(overlapped(end), "{row}: the parent's end for {fd} is synchronous");
}
child.wait().await.expect("reap");
}
}