pub trait OutputWithName {
// Required method
fn named(self, s: impl AsRef<str>) -> NamedOutput;
}Expand description
Extension trait for Output to generate NamedOutput
The primary use case is exercising a function that takes NamedOutput in its arguments in a test.
§Examples
use fun_run::OutputWithName;
let output = std::process::Output {
status: std::process::ExitStatus::default(),
stdout: Vec::new(),
stderr: Vec::new()
};
let named: fun_run::NamedOutput = output.named("exit 0");
assert_eq!(String::from("exit 0"), named.name());For generating an Output with a non-zero status on Unix you can use ExitStatusFromCode::from_code,
which builds the ExitStatus from a plain exit code without you having to bit-shift the raw wait status yourself:
use fun_run::{OutputWithName, ExitStatusFromCode};
let output = std::process::Output {
status: std::process::ExitStatus::from_code(42),
stdout: Vec::new(),
stderr: Vec::new()
};
assert_eq!(42, output.status.code().unwrap());
let named: fun_run::NamedOutput = output.named("exit 42");
let result = named.nonzero_captured();
assert!(result.is_err());Required Methods§
fn named(self, s: impl AsRef<str>) -> NamedOutput
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".