use super::scripted_runner::NEVER_MS;
use crate::runner::ExitOutcome;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ProcScript {
pub delay_ms: u64,
pub outcome: ExitOutcome,
pub obeys_signal: bool,
pub obeys_kill: bool,
pub lamb_holds_the_pipe: bool,
pub reads_stdin: bool,
}
impl ProcScript {
#[must_use]
pub fn const_exit(code: i32) -> Self {
Self::stable_then_exit(0, code)
}
#[must_use]
pub fn stable_then_exit(ms: u64, code: i32) -> Self {
Self {
delay_ms: ms,
outcome: ExitOutcome {
code: Some(code),
signal: None,
},
obeys_signal: true,
obeys_kill: true,
lamb_holds_the_pipe: false,
reads_stdin: true,
}
}
#[must_use]
pub fn never_exits() -> Self {
Self {
delay_ms: NEVER_MS,
outcome: ExitOutcome {
code: None,
signal: None,
},
obeys_signal: true,
obeys_kill: true,
lamb_holds_the_pipe: false,
reads_stdin: true,
}
}
#[must_use]
pub fn ignores_signals() -> Self {
Self {
obeys_signal: false,
..Self::never_exits()
}
}
#[must_use]
pub fn never_reports_its_exit() -> Self {
Self {
obeys_kill: false,
..Self::ignores_signals()
}
}
#[must_use]
pub fn with_a_lamb_holding_the_pipe(self) -> Self {
Self {
lamb_holds_the_pipe: true,
..self
}
}
#[must_use]
pub fn never_reads_its_stdin() -> Self {
Self {
reads_stdin: false,
..Self::never_exits()
}
}
}