cosca 0.9.0

Unified cross-platform subprocess management: spawning, stdio, process trees, stable identity, and elevation.
Documentation
//! Tests only: put stated answers in front of a spawned child's real [`OsChild`].

use super::OwnedChild;
use crate::os_process::fake::FakeProcess;

impl OwnedChild {
    /// Answer from the tables `script` gives a [`FakeProcess`] put over this child's own
    /// [`OsChild`](crate::os_process::child::OsChild): a call a table has an answer for gets it, and
    /// every other call, `os_handle` included, is the real one. The test keeps the returned fake to
    /// read what the child asked of it.
    pub(crate) fn script_over(&mut self, script: impl FnOnce(FakeProcess) -> FakeProcess) -> FakeProcess {
        let real = std::mem::replace(&mut self.os, Box::new(FakeProcess::new([])));
        let fake = script(FakeProcess::over(real));
        self.os = Box::new(fake.clone());
        fake
    }

    /// Every read of this child's number answers `read`, as the number of a reaped root reads.
    #[cfg(unix)]
    pub(crate) fn number_reads_always(&mut self, read: crate::identity::Resolved<crate::identity::ProcessId>) {
        self.script_over(|fake| fake.number_reads_always(read));
    }
}