[−][src]Module assert_cmd::cargo
Simplify running bins in a Cargo project.
CommandCargoExt is an extension trait for Command to easily launch a crate's
binaries.
Examples
Simple case:
use assert_cmd::prelude::*; use std::process::Command; let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")) .unwrap(); let output = cmd.unwrap();
Limitations
- Only works within the context of integration tests. See
escargotfor a more flexible API. - Only reuses your existing feature flags, targets, or build mode.
- Only works with cargo binaries (
cargo testensures they are built).
If you run into these limitations, we recommend trying out escargot:
extern crate assert_cmd; extern crate escargot; use assert_cmd::prelude::*; use escargot; use std::process::Command; let bin_under_test = escargot::CargoBuild::new() .bin("bin_fixture") .current_release() .current_target() .run() .unwrap(); let mut cmd = bin_under_test.command(); let output = cmd.unwrap(); println!("{:?}", output);
Notes:
- There is a noticeable per-call overhead for
CargoBuild. We recommend caching the binary location (.path()instead of.command()) withlazy_static. .current_target()improves platform coverage at the cost of slower test runs if you don't explicitly pass--target <TRIPLET>on the command line.
Structs
| CargoError | Error when finding crate binary. |
Traits
| CommandCargoExt | Create a |
Functions
| cargo_bin | Look up the path to a cargo-built binary within an integration test. |