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;
fn with_stdout_file<P: AsRef<Path>>(&self, filename: P);
fn with_stderr_file<P: AsRef<Path>>(&self, filename: P);
}
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!!");
}
}
Sourcefn with_stdout_file<P: AsRef<Path>>(&self, filename: P)
fn with_stdout_file<P: AsRef<Path>>(&self, filename: P)
Checks that the stdout is corresponding with a file (usually “
§Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stdout_file("cool-args-test.stdout");
Sourcefn with_stderr_file<P: AsRef<Path>>(&self, filename: P)
fn with_stderr_file<P: AsRef<Path>>(&self, filename: P)
Checks that the stderr is corresponding with a file (usually “
§Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stderr_file("cool-args-test.stderr");
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.