Struct Command
pub struct Command {
cmd: Command,
stdin: Option<Data>,
timeout: Option<Duration>,
_stderr_to_stdout: bool,
config: Assert,
}Expand description
Process spawning for testing of non-interactive commands
Fields§
§cmd: Command§stdin: Option<Data>§timeout: Option<Duration>§_stderr_to_stdout: bool§config: AssertImplementations§
§impl Command
§Builder API
impl Command
§Builder API
pub fn new(program: impl AsRef<OsStr>) -> Command
pub fn with_assert(self, config: Assert) -> Command
pub fn with_assert(self, config: Assert) -> Command
Customize the assertion behavior
pub fn arg(self, arg: impl AsRef<OsStr>) -> Command
pub fn arg(self, arg: impl AsRef<OsStr>) -> Command
Adds an argument to pass to the program.
Only one argument can be passed per use. So instead of:
.arg("-C /path/to/repo")usage would be:
.arg("-C")
.arg("/path/to/repo")To pass multiple arguments see args.
§Examples
Basic usage:
use snapbox::cmd::Command;
Command::new("ls")
.arg("-l")
.arg("-a")
.assert()
.success();pub fn args(self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> Command
pub fn args(self, args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> Command
pub fn env(self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Command
pub fn env(self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Command
Inserts or updates an environment variable mapping.
Note that environment variable names are case-insensitive (but case-preserving) on Windows, and case-sensitive on all other platforms.
§Examples
Basic usage:
use snapbox::cmd::Command;
Command::new("ls")
.env("PATH", "/bin")
.assert()
.failure();pub fn envs(
self,
vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
) -> Command
pub fn envs( self, vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>, ) -> Command
Adds or updates multiple environment variable mappings.
§Examples
Basic usage:
use snapbox::cmd::Command;
use std::process::Stdio;
use std::env;
use std::collections::HashMap;
let filtered_env : HashMap<String, String> =
env::vars().filter(|&(ref k, _)|
k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
).collect();
Command::new("printenv")
.env_clear()
.envs(&filtered_env)
.assert()
.success();pub fn env_remove(self, key: impl AsRef<OsStr>) -> Command
pub fn env_remove(self, key: impl AsRef<OsStr>) -> Command
Removes an environment variable mapping.
§Examples
Basic usage:
use snapbox::cmd::Command;
Command::new("ls")
.env_remove("PATH")
.assert()
.failure();pub fn env_clear(self) -> Command
pub fn env_clear(self) -> Command
Clears the entire environment map for the child process.
§Examples
Basic usage:
use snapbox::cmd::Command;
Command::new("ls")
.env_clear()
.assert()
.failure();pub fn current_dir(self, dir: impl AsRef<Path>) -> Command
pub fn current_dir(self, dir: impl AsRef<Path>) -> Command
Sets the working directory for the child process.
§Platform-specific behavior
If the program path is relative (e.g., "./script.sh"), it’s ambiguous
whether it should be interpreted relative to the parent’s working
directory or relative to current_dir. The behavior in this case is
platform specific and unstable, and it’s recommended to use
canonicalize to get an absolute program path instead.
§Examples
Basic usage:
use snapbox::cmd::Command;
Command::new("ls")
.current_dir("/bin")
.assert()
.success();Trait Implementations§
Source§impl ArgLineCommandExt for Command
impl ArgLineCommandExt for Command
Source§impl ChannelChangerCommandExt for Command
impl ChannelChangerCommandExt for Command
Source§fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self
fn masquerade_as_nightly_cargo(self, _reasons: &[&str]) -> Self
&["print-im-a-teapot"].Auto Trait Implementations§
impl Freeze for Command
impl !RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnsafeUnpin for Command
impl !UnwindSafe for Command
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 408 bytes