#[cfg(unix)]
use std::os::unix::process::ExitStatusExt;
#[cfg(windows)]
use std::os::windows::process::ExitStatusExt;
use std::{
cell::{
Cell,
RefCell,
},
ffi::OsStr,
process::ExitStatus,
};
mod defensive_paths;
mod failing_flush;
mod failing_reader;
mod failing_write;
mod fake_child_guard;
mod no_stdin_child;
mod synthetic_children;
use failing_flush::FailingFlush;
use failing_reader::FailingReader;
use failing_write::FailingWrite;
use fake_child_guard::FakeChildGuard;
use no_stdin_child::NoStdinChild;
use crate::{
OutputStream,
command_runner::managed_child_process::ManagedChildProcess,
};
thread_local! {
static FAKE_CHILDREN_ENABLED: Cell<bool> = const { Cell::new(false) };
static COLLECT_OUTPUT_COMMANDS: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) };
}
pub fn with_fake_children_enabled<T>(operation: impl FnOnce() -> T) -> T {
let _guard = enable_fake_children();
operation()
}
pub(crate) fn fake_children_enabled() -> bool {
FAKE_CHILDREN_ENABLED.get()
}
pub(crate) fn record_collect_output(command: &str) {
COLLECT_OUTPUT_COMMANDS.with_borrow_mut(|commands| commands.push(command.to_owned()));
}
pub fn take_collect_output_commands() -> Vec<String> {
COLLECT_OUTPUT_COMMANDS.take()
}
fn enable_fake_children() -> FakeChildGuard {
let previous = fake_children_enabled();
FAKE_CHILDREN_ENABLED.set(true);
FakeChildGuard { previous }
}
pub fn exercise_defensive_paths() -> Vec<String> {
defensive_paths::exercise_defensive_paths()
}
fn success_status() -> ExitStatus {
ExitStatus::from_raw(0)
}
pub(crate) fn fake_child_for(program: &OsStr) -> Option<ManagedChildProcess> {
synthetic_children::fake_child_for(program)
}
pub(crate) fn forced_collect_output_error(command: &str) -> Option<OutputStream> {
synthetic_children::forced_collect_output_error(command)
}