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: boolValue returned by run_command / shell_exec / exec_capture. Defaults to true.
command_exists_result: boolValue returned by command_exists. Defaults to true.
command_output_value: StringStdout value returned by command_output when command_output_ok is true.
command_output_ok: boolWhen 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§
Trait Implementations§
Source§impl Shell for MockShell
impl Shell for MockShell
Source§fn run_command(
&self,
_label: &str,
program: &str,
args: &[&str],
_output: &mut dyn Output,
_mode: OutputMode,
) -> Result<CommandResult, ShellError>
fn run_command( &self, _label: &str, program: &str, args: &[&str], _output: &mut dyn Output, _mode: OutputMode, ) -> Result<CommandResult, ShellError>
Source§fn shell_exec(
&self,
script: &str,
_output: &mut dyn Output,
_mode: OutputMode,
) -> Result<CommandResult, ShellError>
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
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>
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>
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>
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§
impl !Freeze for MockShell
impl !RefUnwindSafe for MockShell
impl Send for MockShell
impl !Sync for MockShell
impl Unpin for MockShell
impl UnsafeUnpin for MockShell
impl UnwindSafe for MockShell
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more