Struct assert_cli::Assert[][src]

#[must_use]
pub struct Assert { /* fields omitted */ }

Assertions for a specific command.

Methods

impl Assert
[src]

Run the crate's main binary.

Defaults to asserting successful execution.

Run a specific binary of the current crate.

Defaults to asserting successful execution.

Run a specific example of the current crate.

Defaults to asserting successful execution.

Run a custom command.

Defaults to asserting successful execution.

Examples

extern crate assert_cli;

assert_cli::Assert::command(&["echo", "1337"])
    .unwrap();

Add arguments to the command.

Examples

extern crate assert_cli;

assert_cli::Assert::command(&["echo"])
    .with_args(&["42"])
    .stdout().contains("42")
    .unwrap();

Add stdin to the command.

Examples

extern crate assert_cli;

assert_cli::Assert::command(&["cat"])
    .stdin("42")
    .stdout().contains("42")
    .unwrap();

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();

Sets 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();

Small 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();

Expect the command to be executed successfully.

Examples

extern crate assert_cli;

assert_cli::Assert::command(&["echo", "42"])
    .succeeds()
    .unwrap();

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();

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();

Do 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();

Create an assertion for stdout's contents

Examples

extern crate assert_cli;

assert_cli::Assert::command(&["echo", "42"])
    .stdout().contains("42")
    .unwrap();

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();

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());

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]

Formats the value using the given formatter. Read more

impl Default for Assert
[src]

Construct an assert using cargo run -- as command.

Defaults to asserting successful execution.

Auto Trait Implementations

impl !Send for Assert

impl !Sync for Assert