Skip to content

Commit b8f7ded

Browse files
committed
feat: Provide cargo_bin_cmd!
1 parent e60035f commit b8f7ded

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/cargo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ use std::process;
6363

6464
#[doc(inline)]
6565
pub use crate::cargo_bin;
66+
#[doc(inline)]
67+
pub use crate::cargo_bin_cmd;
6668

6769
/// Create a [`Command`] for a `bin` in the Cargo project.
6870
///

src/macros.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,33 @@ macro_rules! cargo_bin {
6262
::std::path::Path::new(env!(concat!("CARGO_BIN_EXE_", $bin_target_name)))
6363
};
6464
}
65+
66+
/// The absolute path to a binary target's executable.
67+
///
68+
/// The `bin_target_name` is the name of the binary
69+
/// target, exactly as-is.
70+
///
71+
/// **NOTE:** This is only set when building an integration test or benchmark.
72+
///
73+
/// ## Example
74+
///
75+
/// ```rust,ignore
76+
/// use assert_cmd::prelude::*;
77+
/// use assert_cmd::cargo::cargo_bin_cmd;
78+
///
79+
/// use std::process::Command;
80+
///
81+
/// let mut cmd = cargo_bin_cmd!()
82+
/// .unwrap();
83+
/// let output = cmd.unwrap();
84+
/// ```
85+
#[macro_export]
86+
#[doc(hidden)]
87+
macro_rules! cargo_bin_cmd {
88+
() => {
89+
$crate::cargo::cargo_bin_cmd!($crate::pkg_name!())
90+
};
91+
($bin_target_name:expr) => {
92+
$crate::Command::new($crate::cargo::cargo_bin!($bin_target_name))
93+
};
94+
}

0 commit comments

Comments
 (0)