pub struct Command {
cmd: Command,
stdin_buf: Option<Box<[u8]>>,
stdin: Option<Stdio>,
stdout: Option<Stdio>,
stderr: Option<Stdio>,
drop_bomb: DropBomb,
already_executed: bool,
}
Expand description
This is a custom command wrapper that simplifies working with commands and makes it easier to ensure that we check the exit status of executed processes.
§A Command
must be executed exactly once
A Command
is armed by a [DropBomb
] on construction to enforce that it will be executed. If
a Command
is constructed but never executed, the drop bomb will explode and cause the test
to panic. Execution methods run
and run_fail
will defuse the drop bomb. A test
containing constructed but never executed commands is dangerous because it can give a false
sense of confidence.
Each Command
invocation can also only be executed once, because we want to enforce
std{in,out,err}
config via std::process::Stdio
but std::process::Stdio
is not
cloneable.
In this sense, Command
exhibits linear type semantics but enforced at run-time.
Fields§
§cmd: Command
§stdin_buf: Option<Box<[u8]>>
§stdin: Option<Stdio>
§stdout: Option<Stdio>
§stderr: Option<Stdio>
§drop_bomb: DropBomb
§already_executed: bool
Implementations§
source§impl Command
impl Command
pub fn new<P: AsRef<OsStr>>(program: P) -> Self
sourcepub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self
pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self
Specify a stdin input buffer. This is a convenience helper,
sourcepub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Configuration for the child process’s standard input (stdin) handle.
sourcepub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Configuration for the child process’s standard output (stdout) handle.
sourcepub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Self
Configuration for the child process’s standard error (stderr) handle.
sourcepub fn env_remove<K>(&mut self, key: K) -> &mut Self
pub fn env_remove<K>(&mut self, key: K) -> &mut Self
Remove an environmental variable.
sourcepub fn arg<S>(&mut self, arg: S) -> &mut Self
pub fn arg<S>(&mut self, arg: S) -> &mut Self
Generic command argument provider. Prefer specific helper methods if possible. Note that for some executables, arguments might be platform specific. For C/C++ compilers, arguments might be platform and compiler specific.
sourcepub fn args<S, V>(&mut self, args: V) -> &mut Self
pub fn args<S, V>(&mut self, args: V) -> &mut Self
Generic command arguments provider. Prefer specific helper methods if possible. Note that for some executables, arguments might be platform specific. For C/C++ compilers, arguments might be platform and compiler specific.
sourcepub fn inspect<I>(&mut self, inspector: I) -> &mut Selfwhere
I: FnOnce(&StdCommand),
pub fn inspect<I>(&mut self, inspector: I) -> &mut Selfwhere
I: FnOnce(&StdCommand),
Inspect what the underlying std::process::Command
is up to the
current construction.
sourcepub fn current_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self
pub fn current_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self
Set the path where the command will be run.
sourcepub fn run(&mut self) -> CompletedProcess
pub fn run(&mut self) -> CompletedProcess
Run the constructed command and assert that it is successfully run.
By default, std{in,out,err} are Stdio::piped()
.
sourcepub fn run_fail(&mut self) -> CompletedProcess
pub fn run_fail(&mut self) -> CompletedProcess
Run the constructed command and assert that it does not successfully run.
By default, std{in,out,err} are Stdio::piped()
.
sourcepub fn run_unchecked(&mut self) -> CompletedProcess
pub fn run_unchecked(&mut self) -> CompletedProcess
Run the command but do not check its exit status. Only use if you explicitly don’t care about the exit status.
Prefer to use Self::run
and Self::run_fail
whenever possible.
fn command_output(&mut self) -> CompletedProcess
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Command
impl !RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin 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
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: 312 bytes