Skip to main content

MockShell

Struct MockShell 

Source
pub struct MockShell {
    pub calls: RefCell<Vec<String>>,
    pub run_success: bool,
    pub command_exists_result: bool,
    pub command_output_value: String,
    pub command_output_ok: bool,
    pub exec_capture_results: RefCell<VecDeque<CommandResult>>,
}
Expand description

Mock shell for unit tests: records calls and returns configurable results.

Intended for testing use. Not gated behind #[cfg(test)] so that downstream crates can use it in their own test suites; LTO eliminates it from production builds.

Fields§

§calls: RefCell<Vec<String>>

Ordered log of every call made to this shell, formatted as "program arg1 arg2".

§run_success: bool

Value returned by run_command / shell_exec / exec_capture. Defaults to true.

§command_exists_result: bool

Value returned by command_exists. Defaults to true.

§command_output_value: String

Stdout value returned by command_output when command_output_ok is true.

§command_output_ok: bool

When false, command_output returns Err (e.g. to simulate a tool not installed).

§exec_capture_results: RefCell<VecDeque<CommandResult>>

Queue of results for exec_capture calls; pops front on each call. If empty, falls back to CommandResult { success: run_success, stderr: "" }.

Implementations§

Source§

impl MockShell

Source

pub fn new() -> Self

Create a new MockShell with all success flags set to true and empty recorded calls.

Source

pub fn calls(&self) -> Vec<String>

Return a snapshot of all calls recorded so far.

Trait Implementations§

Source§

impl Default for MockShell

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Shell for MockShell

Source§

fn run_command( &self, _label: &str, program: &str, args: &[&str], _output: &mut dyn Output, _mode: OutputMode, ) -> Result<CommandResult, ShellError>

Run program with args, displaying progress under label. Read more
Source§

fn shell_exec( &self, script: &str, _output: &mut dyn Output, _mode: OutputMode, ) -> Result<CommandResult, ShellError>

Run an arbitrary shell script string (passed to bash -c / powershell -Command).
Source§

fn command_exists(&self, _program: &str) -> bool

Return true when program can be found on PATH.
Source§

fn command_output( &self, program: &str, args: &[&str], ) -> Result<String, ShellError>

Run program args and return its captured stdout as a trimmed String.
Source§

fn exec_capture( &self, cmd: &str, _output: &mut dyn Output, _mode: OutputMode, ) -> Result<CommandResult, ShellError>

Run a shell command, capturing stdout/stderr silently without display. In dry-run mode (DryRunShell), logs the command and returns success without executing.
Source§

fn exec_interactive( &self, cmd: &str, _output: &mut dyn Output, _mode: OutputMode, ) -> Result<(), ShellError>

Run a shell command with inherited stdio (for interactive flows like aws sso login). In dry-run mode (DryRunShell), logs the command and returns success without executing.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.