Struct assert_cli::Assert
[−]
[src]
pub struct Assert { /* fields omitted */ }
Assertions for a specific command.
Methods
impl Assert
[src]
fn main_binary() -> Self
[src]
Run the crate's main binary.
Defaults to asserting successful execution.
fn cargo_binary(name: &str) -> Self
[src]
Run a specific binary of the current crate.
Defaults to asserting successful execution.
fn command(cmd: &[&str]) -> Self
[src]
Run a custom command.
Defaults to asserting successful execution.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "1337"]) .unwrap();
fn with_args(self, args: &[&str]) -> Self
[src]
Add arguments to the command.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo"]) .with_args(&["42"]) .stdout().contains("42") .unwrap();
fn current_dir<P: Into<PathBuf>>(self, dir: P) -> Self
[src]
Sets the working directory for the command.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["wc", "lib.rs"]) .current_dir(std::path::Path::new("src")) .stdout().contains("lib.rs") .execute() .unwrap();
fn and(self) -> Self
[src]
Small helper to make chains more readable.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "42"]) .stdout().contains("42") .unwrap();
fn succeeds(self) -> Self
[src]
Expect the command to be executed successfully.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "42"]) .unwrap();
fn fails(self) -> Self
[src]
Expect the command to fail.
Note: This does not include shell failures like command not found
. I.e. the
command must run and fail for this assertion to pass.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["cat", "non-existing-file"]) .fails() .and() .stderr().contains("non-existing-file") .unwrap();
fn fails_with(self, expect_exit_code: i32) -> Self
[src]
Expect the command to fail and return a specific error code.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["cat", "non-existing-file"]) .fails_with(1) .and() .stderr().is("cat: non-existing-file: No such file or directory") .unwrap();
fn stdout(self) -> OutputAssertionBuilder
[src]
Create an assertion for stdout's contents
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "42"]) .stdout().contains("42") .unwrap();
fn stderr(self) -> OutputAssertionBuilder
[src]
Create an assertion for stdout's contents
Examples
extern crate assert_cli; assert_cli::Assert::command(&["cat", "non-existing-file"]) .fails_with(1) .and() .stderr().is("cat: non-existing-file: No such file or directory") .unwrap();
fn execute(self) -> Result<(), Error>
[src]
Execute the command and check the assertions.
Examples
extern crate assert_cli; let test = assert_cli::Assert::command(&["echo", "42"]) .stdout().contains("42") .execute(); assert!(test.is_ok());
fn unwrap(self)
[src]
Execute the command, check the assertions, and panic when they fail.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "42"]) .fails() .unwrap(); // panics