use std::collections::BTreeMap;
use crate::child::owned::OwnedChild;
use crate::containment::{Attached, Attachment, Containment};
use crate::graceful::GracefulMechanism;
use crate::identity::{Key, ProcessId};
use crate::os_process::child::ExitRecord;
use crate::os_process::fake::{FakeProcess, ReapAnswer};
use crate::{Child, Unreaped};
const ABSENT_PID: u32 = 0x7fff_fffe;
pub(crate) fn child_over(fake: &FakeProcess) -> Child {
Child::from_parts(
OwnedChild::new(Box::new(fake.clone().with_pid(ABSENT_PID))),
Some(ProcessId::from_parts_for_test(ABSENT_PID, Key::for_test(1))),
BTreeMap::new(),
false,
Attachment {
containment: Containment::None,
attached: Attached::None,
graceful: if cfg!(windows) {
GracefulMechanism::None
} else {
GracefulMechanism::Process
},
},
)
}
pub(crate) fn unreaped_over(fake: &FakeProcess, id: Option<ProcessId>) -> Unreaped {
Unreaped::new(OwnedChild::new(Box::new(fake.clone())), id, false)
}
pub(crate) fn exited_unreaped(id: ProcessId) -> Box<Unreaped> {
let exit = ExitRecord::Status(std::process::ExitStatus::default());
let fake = FakeProcess::new([])
.with_pid(id.pid())
.reaps([ReapAnswer::Reaped(exit)]);
Box::new(unreaped_over(&fake, Some(id)))
}