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 assert_cmd::pkg_name;
use std::process::Command;
let mut cmd = Command::cargo_bin(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.
Macros§
- cargo_
bin - The absolute path to a binary target’s executable.
- cargo_
bin_ cmd - The absolute path to a binary target’s executable.
Structs§
- Cargo
Error - Error when finding crate binary.
Traits§
- Command
Cargo Ext - Create a
Commandfor abinin the Cargo project.
Functions§
- cargo_
bin Deprecated - Look up the path to a cargo-built binary within an integration test.