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 escargot for a more flexible API.
  • Only reuses your existing feature flags, targets, or build mode.
  • Only works with cargo binaries (cargo test ensures 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:

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.