Trait cli_sandbox::WithStdout
source · pub trait WithStdout {
// Required methods
fn with_stdout<S: AsRef<str>>(&self, stdout: S);
fn with_stderr<S: AsRef<str>>(&self, stderr: S);
fn with_stdout_regex<S: AsRef<str>>(&self, stdout: S);
fn with_stderr_regex<S: AsRef<str>>(&self, stderr: S);
fn stdout_warns(&self) -> bool;
fn stderr_warns(&self) -> bool;
fn empty_stderr(&self) -> bool;
fn empty_stdout(&self) -> bool;
}Required Methods§
sourcefn with_stdout<S: AsRef<str>>(&self, stdout: S)
fn with_stdout<S: AsRef<str>>(&self, stdout: S)
Checks that the standard output of a command is what’s expected. If they aren’t the same, it will show the differences if the pretty_asssertions feature is enabled
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stdout("Expected stdout");sourcefn with_stderr<S: AsRef<str>>(&self, stderr: S)
fn with_stderr<S: AsRef<str>>(&self, stderr: S)
Checks that the standard error of a command is what’s expected. If they aren’t the same, it will show the differences if the pretty_asssertions feature is enabled
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stderr("Expected stderr");sourcefn with_stdout_regex<S: AsRef<str>>(&self, stdout: S)
fn with_stdout_regex<S: AsRef<str>>(&self, stdout: S)
Checks that the standard output of a command is what’s expected (Using regex). If they aren’t the same, it will show the differences if the pretty_asssertions feature is enabled
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stdout_regex("<Regex that matches expected stdout>");sourcefn with_stderr_regex<S: AsRef<str>>(&self, stderr: S)
fn with_stderr_regex<S: AsRef<str>>(&self, stderr: S)
Checks that the standard error of a command is what’s expected (Using regex). If they aren’t the same, it will show the differences if the pretty_asssertions feature is enabled
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stderr("<Regex that matches expected stderr>");sourcefn stdout_warns(&self) -> bool
fn stdout_warns(&self) -> bool
Returns how many times the program contains the word “warning:” in the stderr. Useful for checking compile-time warnings.
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
if cmd.stderr_warns() {
// Maybe there's something to check with that code...
}
}sourcefn stderr_warns(&self) -> bool
fn stderr_warns(&self) -> bool
Returns how many times the program contains the word “warning:” in the stderr. Useful for checking compile-time warnings.
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
if cmd.stderr_warns() {
// Maybe there's something to check with that code...
}
}sourcefn empty_stderr(&self) -> bool
fn empty_stderr(&self) -> bool
Checks that the stderr is empty. It’s different from .with_stderr("") in that this won’t print a whole diff. Useful for when ANY presence of a stderr would mean that there were errors, and the output is invalid.
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
if !cmd.empty_stderr() {
panic!("HELP!!! THE OUTPUT IS INVALID!!");
}
}sourcefn empty_stdout(&self) -> bool
fn empty_stdout(&self) -> bool
Checks that the stdout is empty. It’s different from .with_stdout("") in that this won’t print a whole diff. Useful for when ANY presence of a stdout, would mean that there were errors, and the output is invalid.
Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
if !cmd.empty_stdout() {
panic!("HELP!!! THE OUTPUT IS INVALID!!");
}
}