Module assert_cmd::cargo [−][src]
Expand description
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:
use assert_cmd::prelude::*; 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
Error when finding crate binary.
Traits
Create a Command for a bin in the Cargo project.
Functions
Look up the path to a cargo-built binary within an integration test.