Trait 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;
    fn with_stdout_file<P: AsRef<Path>>(&self, filename: P);
    fn with_stderr_file<P: AsRef<Path>>(&self, filename: P);
}

Required Methods§

Source

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");
Source

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");
Source

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>");
Source

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>");
Source

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...
}
}
Source

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...
}
}
Source

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!!");
}
}
Source

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!!");
}
}
Source

fn with_stdout_file<P: AsRef<Path>>(&self, filename: P)

Checks that the stdout is corresponding with a file (usually “.stdout”);

§Example
let proj = project()?;
let cmd = proj.command(["my", "cool", "--args"])?;
cmd.with_stdout_file("cool-args-test.stdout");
Source

fn with_stderr_file<P: AsRef<Path>>(&self, filename: P)

Checks that the stderr is corresponding with a file (usually “.stderr”);

§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.

Implementations on Foreign Types§

Source§

impl WithStdout for Output

Source§

fn with_stdout<S: AsRef<str>>(&self, stdout: S)

Source§

fn with_stderr<S: AsRef<str>>(&self, stderr: S)

Source§

fn with_stderr_regex<S: AsRef<str>>(&self, regex: S)

Source§

fn with_stdout_regex<S: AsRef<str>>(&self, regex: S)

Source§

fn stdout_warns(&self) -> bool

Source§

fn stderr_warns(&self) -> bool

Source§

fn empty_stderr(&self) -> bool

Source§

fn empty_stdout(&self) -> bool

Source§

fn with_stdout_file<P: AsRef<Path>>(&self, filename: P)

Source§

fn with_stderr_file<P: AsRef<Path>>(&self, filename: P)

Implementors§