Some examples:
|
Here's a trivial example: |
|
|
|
```rust,no_run |
|
use assert_cmd::Command; |
|
|
|
let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); |
|
cmd.assert().success(); |
|
``` |
|
//! And a little of everything: |
|
//! ```rust,no_run |
|
//! use assert_cmd::Command; |
|
//! |
|
//! let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); |
|
//! let assert = cmd |
|
//! .arg("-A") |
|
//! .env("stdout", "hello") |
|
//! .env("exit", "42") |
|
//! .write_stdin("42") |
|
//! .assert(); |
|
//! assert |
|
//! .failure() |
|
//! .code(42) |
|
//! .stdout("hello\n"); |
|
//! ``` |
|
//! # Examples |
|
//! |
|
//! Simple case: |
|
//! |
|
//! ```rust,no_run |
|
//! use assert_cmd::prelude::*; |
|
//! use assert_cmd::pkg_name; |
|
//! |
|
//! use std::process::Command; |
|
//! |
|
//! let mut cmd = Command::cargo_bin(pkg_name!()) |
|
//! .unwrap(); |
|
//! let output = cmd.unwrap(); |
|
//! ``` |
Perhaps beyond the scope of this issue, but I haven't been able to make use of the proposed alternatives to Command::cargo_bin:
https://github.com/oxidecomputer/oxide.rs/blob/06f4a01170f2decf81d4d39ca3a5f02a3c5345a6/cli/src/cmd_auth.rs#L651-L663
In particular, we're using this in a unit test which appears to be either something that worked by accident or a newly broken use case.
Some examples:
assert_cmd/README.md
Lines 15 to 22 in ee88946
assert_cmd/src/lib.rs
Lines 48 to 63 in ee88946
assert_cmd/src/cargo.rs
Lines 6 to 19 in ee88946
Perhaps beyond the scope of this issue, but I haven't been able to make use of the proposed alternatives to
Command::cargo_bin:https://github.com/oxidecomputer/oxide.rs/blob/06f4a01170f2decf81d4d39ca3a5f02a3c5345a6/cli/src/cmd_auth.rs#L651-L663
In particular, we're using this in a unit test which appears to be either something that worked by accident or a newly broken use case.