Struct assert_cli::Assert [−][src]
#[must_use]pub struct Assert { /* fields omitted */ }
Assertions for a specific command.
Methods
impl Assert[src]
impl Assertpub fn main_binary() -> Self[src]
pub fn main_binary() -> SelfRun the crate's main binary.
Defaults to asserting successful execution.
pub fn cargo_binary<S: AsRef<OsStr>>(name: S) -> Self[src]
pub fn cargo_binary<S: AsRef<OsStr>>(name: S) -> SelfRun a specific binary of the current crate.
Defaults to asserting successful execution.
pub fn example<S: AsRef<OsStr>>(name: S) -> Self[src]
pub fn example<S: AsRef<OsStr>>(name: S) -> SelfRun a specific example of the current crate.
Defaults to asserting successful execution.
pub fn command<S: AsRef<OsStr>>(cmd: &[S]) -> Self[src]
pub fn command<S: AsRef<OsStr>>(cmd: &[S]) -> SelfRun a custom command.
Defaults to asserting successful execution.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "1337"]) .unwrap();
pub fn with_args<S: AsRef<OsStr>>(self, args: &[S]) -> Self[src]
pub fn with_args<S: AsRef<OsStr>>(self, args: &[S]) -> SelfAdd arguments to the command.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo"]) .with_args(&["42"]) .stdout().contains("42") .unwrap();
pub fn stdin<S: Into<Vec<u8>>>(self, contents: S) -> Self[src]
pub fn stdin<S: Into<Vec<u8>>>(self, contents: S) -> SelfAdd stdin to the command.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["cat"]) .stdin("42") .stdout().contains("42") .unwrap();
pub fn current_dir<P: Into<PathBuf>>(self, dir: P) -> Self[src]
pub fn current_dir<P: Into<PathBuf>>(self, dir: P) -> SelfSets 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();
pub fn with_env<E: Into<Environment>>(self, env: E) -> Self[src]
pub fn with_env<E: Into<Environment>>(self, env: E) -> SelfSets environments variables for the command.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["printenv"]) .with_env(&[("TEST_ENV", "OK")]) .stdout().contains("TEST_ENV=OK") .execute() .unwrap(); let env = assert_cli::Environment::empty() .insert("FOO", "BAR"); assert_cli::Assert::command(&["printenv"]) .with_env(&env) .stdout().is("FOO=BAR") .execute() .unwrap(); ::std::env::set_var("BAZ", "BAR"); assert_cli::Assert::command(&["printenv"]) .stdout().contains("BAZ=BAR") .execute() .unwrap();
pub fn and(self) -> Self[src]
pub fn and(self) -> SelfSmall helper to make chains more readable.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["cat", "non-existing-file"]) .fails() .and() .stderr().contains("non-existing-file") .unwrap();
pub fn succeeds(self) -> Self[src]
pub fn succeeds(self) -> SelfExpect the command to be executed successfully.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "42"]) .succeeds() .unwrap();
pub fn fails(self) -> Self[src]
pub fn fails(self) -> SelfExpect 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();
pub fn fails_with(self, expect_exit_code: i32) -> Self[src]
pub fn fails_with(self, expect_exit_code: i32) -> SelfExpect 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();
pub fn ignore_status(self) -> Self[src]
pub fn ignore_status(self) -> SelfDo not care whether the command exits successfully or if it fails.
This function removes any assertions that were already set, including
any expected exit code that was set with fails_with.
Examples
extern crate assert_cli; assert_cli::Assert::command(&["cat", "non-existing-file"]) .ignore_status() .and() .stderr().is("cat: non-existing-file: No such file or directory") .unwrap();
pub fn stdout(self) -> OutputAssertionBuilder[src]
pub fn stdout(self) -> OutputAssertionBuilderCreate an assertion for stdout's contents
Examples
extern crate assert_cli; assert_cli::Assert::command(&["echo", "42"]) .stdout().contains("42") .unwrap();
pub fn stderr(self) -> OutputAssertionBuilder[src]
pub fn stderr(self) -> OutputAssertionBuilderCreate 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();
pub fn execute(self) -> Result<(), AssertionError>[src]
pub fn execute(self) -> Result<(), AssertionError>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());
pub fn unwrap(self)[src]
pub fn unwrap(self)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
Trait Implementations
impl Debug for Assert[src]
impl Debug for Assertfn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl Default for Assert[src]
impl Default for Assert