Struct snapbox::cmd::OutputAssert

source ·
pub struct OutputAssert { /* private fields */ }
Expand description

Assert the state of a Command’s Output.

Create an OutputAssert through the Command::assert.

Implementations§

Create an Assert for a given Output.

Customize the assertion behavior

Access the contained Output.

Ensure the command succeeded.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .assert()
    .success();

Ensure the command failed.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("exit", "1")
    .assert()
    .failure();

Ensure the command aborted before returning a code.

Ensure the command returned the expected code.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("exit", "42")
    .assert()
    .code(42);

Ensure the command wrote the expected data to stdout.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stdout_eq("hello");

Ensure the command wrote the expected data to stdout.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stdout_eq_path("tests/snapshots/output.txt");

Ensure the command wrote the expected data to stdout.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stdout_matches("he[..]o");

Ensure the command wrote the expected data to stdout.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stdout_matches_path("tests/snapshots/output.txt");

Ensure the command wrote the expected data to stderr.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stderr_eq("world");

Ensure the command wrote the expected data to stderr.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stderr_eq_path("tests/snapshots/err.txt");

Ensure the command wrote the expected data to stderr.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stderr_matches("wo[..]d");

Ensure the command wrote the expected data to stderr.

use snapbox::cmd::Command;
use snapbox::cmd::cargo_bin;

let assert = Command::new(cargo_bin("snap-fixture"))
    .env("stdout", "hello")
    .env("stderr", "world")
    .assert()
    .stderr_matches_path("tests/snapshots/err.txt");

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.