From cb3b590f15d002c6d40d44337dfba9a093379b50 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 10 Mar 2026 15:10:33 -0500 Subject: [PATCH 1/3] Revert "fix: Deprecate cargo_bin (runtime version)" This reverts commit b744e271b74fb70109cdff6b2c0567e03e69f68e. Cargo now provides `CARGO_BIN_EXE_*` at runtime. --- src/cargo.rs | 10 -------- src/cmd.rs | 4 ---- tests/assert.rs | 60 ++++++++++++++++++++++++++++++----------------- tests/cargo.rs | 24 +++++++++++++++---- tests/examples.rs | 11 +++++---- 5 files changed, 66 insertions(+), 43 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index ba1119f..547e698 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -130,16 +130,11 @@ where /// ``` /// /// [`Command`]: std::process::Command - #[deprecated( - since = "2.1.0", - note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin!`" - )] fn cargo_bin>(name: S) -> Result; } impl CommandCargoExt for crate::cmd::Command { fn cargo_bin>(name: S) -> Result { - #[allow(deprecated)] crate::cmd::Command::cargo_bin(name) } } @@ -151,7 +146,6 @@ impl CommandCargoExt for process::Command { } pub(crate) fn cargo_bin_cmd>(name: S) -> Result { - #[allow(deprecated)] let path = cargo_bin(name); if path.is_file() { if let Some(runner) = cargo_runner() { @@ -220,10 +214,6 @@ impl fmt::Display for NotFoundError { /// Look up the path to a cargo-built binary within an integration test. /// /// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo -#[deprecated( - since = "2.1.0", - note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin!`" -)] pub fn cargo_bin>(name: S) -> path::PathBuf { cargo_bin_str(name.as_ref()) } diff --git a/src/cmd.rs b/src/cmd.rs index 1d50a79..cd4e142 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -60,10 +60,6 @@ impl Command { /// println!("{:?}", output); /// ``` /// - #[deprecated( - since = "2.1.0", - note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin_cmd!`" - )] pub fn cargo_bin>(name: S) -> Result { let cmd = crate::cargo::cargo_bin_cmd(name)?; Ok(Self::from_std(cmd)) diff --git a/tests/assert.rs b/tests/assert.rs index 477370c..ec852f5 100644 --- a/tests/assert.rs +++ b/tests/assert.rs @@ -1,13 +1,13 @@ use std::process::Command; -use assert_cmd::cargo_bin; use assert_cmd::prelude::*; use predicates::prelude::*; #[test] fn stdout_string() { let expected = "hello\n".to_owned(); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() @@ -16,25 +16,26 @@ fn stdout_string() { #[test] fn trait_example() { - let mut cmd = Command::new(cargo_bin!("bin_fixture")); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.assert().success(); } #[test] fn trait_assert_example() { - let mut cmd = Command::new(cargo_bin!("bin_fixture")); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.assert().success(); } #[test] fn struct_example() { - let mut cmd = Command::new(cargo_bin!("bin_fixture")); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.assert().success(); } #[test] fn append_context_example() { - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .assert() .append_context("main", "no args") .success(); @@ -42,12 +43,16 @@ fn append_context_example() { #[test] fn success_example() { - Command::new(cargo_bin!("bin_fixture")).assert().success(); + Command::cargo_bin("bin_fixture") + .unwrap() + .assert() + .success(); } #[test] fn failure_example() { - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("exit", "1") .assert() .failure(); @@ -55,17 +60,20 @@ fn failure_example() { #[test] fn code_example() { - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("exit", "42") .assert() .code(predicate::eq(42)); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("exit", "42") .assert() .code(42); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("exit", "42") .assert() .code(&[2, 42] as &[i32]); @@ -73,31 +81,36 @@ fn code_example() { #[test] fn stdout_example() { - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(predicate::eq(b"hello\n" as &[u8])); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(predicate::str::diff("hello\n")); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(b"hello\n" as &[u8]); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stdout(vec![b'h', b'e', b'l', b'l', b'o', b'\n']); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() @@ -106,31 +119,36 @@ fn stdout_example() { #[test] fn stderr_example() { - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(predicate::eq(b"world\n" as &[u8])); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(predicate::str::diff("world\n")); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(b"world\n" as &[u8]); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() .stderr(vec![b'w', b'o', b'r', b'l', b'd', b'\n']); - Command::new(cargo_bin!("bin_fixture")) + Command::cargo_bin("bin_fixture") + .unwrap() .env("stdout", "hello") .env("stderr", "world") .assert() diff --git a/tests/cargo.rs b/tests/cargo.rs index bf6d5c4..4861ad3 100644 --- a/tests/cargo.rs +++ b/tests/cargo.rs @@ -1,19 +1,19 @@ use std::process::Command; -use assert_cmd::cargo_bin; +use assert_cmd::pkg_name; use assert_cmd::prelude::*; use escargot::CURRENT_TARGET; #[test] fn cargo_binary() { - let mut cmd = Command::new(cargo_bin!("bin_fixture")); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.env("stdout", "42"); cmd.assert().success().stdout("42\n"); } #[test] fn cargo_binary_with_empty_env() { - let mut cmd = Command::new(cargo_bin!("bin_fixture")); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.env_clear().env("stdout", "42"); cmd.assert().success().stdout("42\n"); } @@ -39,9 +39,25 @@ fn mod_example() { } } +#[test] +#[should_panic] // No bin named `assert_cmd +fn trait_example() { + let mut cmd = Command::cargo_bin(pkg_name!()).unwrap(); + let output = cmd.unwrap(); + println!("{output:?}"); +} + +#[test] +#[should_panic] // No bin named `assert_cmd +fn cargo_bin_example_1() { + let mut cmd = Command::cargo_bin(pkg_name!()).unwrap(); + let output = cmd.unwrap(); + println!("{output:?}"); +} + #[test] fn cargo_bin_example_2() { - let mut cmd = Command::new(cargo_bin!("bin_fixture")); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); let output = cmd.unwrap(); println!("{output:?}"); } diff --git a/tests/examples.rs b/tests/examples.rs index fadedca..eca5df3 100644 --- a/tests/examples.rs +++ b/tests/examples.rs @@ -1,11 +1,11 @@ -use assert_cmd::cargo::cargo_bin_cmd; +use assert_cmd::Command; #[test] fn lib_example() { - let mut cmd = cargo_bin_cmd!("bin_fixture"); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); cmd.assert().success(); - let mut cmd = cargo_bin_cmd!("bin_fixture"); + let mut cmd = Command::cargo_bin("bin_fixture").unwrap(); let assert = cmd .arg("-A") .env("stdout", "hello") @@ -17,7 +17,10 @@ fn lib_example() { #[test] fn timeout_example() { - let assert = cargo_bin_cmd!("bin_fixture") + use assert_cmd::Command; + + let assert = Command::cargo_bin("bin_fixture") + .unwrap() .timeout(std::time::Duration::from_secs(1)) .env("sleep", "100") .assert(); From 0246aa60d76c97156b6ae85e4ca18934c845ebfb Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 10 Mar 2026 15:12:07 -0500 Subject: [PATCH 2/3] test: Close markdown quotes --- tests/cargo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cargo.rs b/tests/cargo.rs index 4861ad3..19838c3 100644 --- a/tests/cargo.rs +++ b/tests/cargo.rs @@ -40,7 +40,7 @@ fn mod_example() { } #[test] -#[should_panic] // No bin named `assert_cmd +#[should_panic] // No bin named `assert_cmd` fn trait_example() { let mut cmd = Command::cargo_bin(pkg_name!()).unwrap(); let output = cmd.unwrap(); @@ -48,7 +48,7 @@ fn trait_example() { } #[test] -#[should_panic] // No bin named `assert_cmd +#[should_panic] // No bin named `assert_cmd` fn cargo_bin_example_1() { let mut cmd = Command::cargo_bin(pkg_name!()).unwrap(); let output = cmd.unwrap(); From 80fe94c9088c65b1353293767afa1f4cb2e0bc91 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 10 Mar 2026 15:19:38 -0500 Subject: [PATCH 3/3] docs(cargo): Specify support for different versions --- src/cargo.rs | 12 +++++++++--- src/cmd.rs | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index 547e698..1321602 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -102,7 +102,10 @@ where /// this method with [cross](https://github.com/cross-rs/cross), no extra configuration is /// needed. /// - /// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo + /// Cargo support: + /// - `>1.94`: works + /// - `>=1.91,<=1.93`: works with default `build-dir` + /// - `<=1.92`: works /// /// # Examples /// @@ -211,9 +214,12 @@ impl fmt::Display for NotFoundError { } } -/// Look up the path to a cargo-built binary within an integration test. +/// Look up the path to a cargo-built binary within an integration test /// -/// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo +/// Cargo support: +/// - `>1.94`: works +/// - `>=1.91,<=1.93`: works with default `build-dir` +/// - `<=1.92`: works pub fn cargo_bin>(name: S) -> path::PathBuf { cargo_bin_str(name.as_ref()) } diff --git a/src/cmd.rs b/src/cmd.rs index cd4e142..0df8c0b 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -37,7 +37,10 @@ impl Command { /// /// See the [`cargo` module documentation][crate::cargo] for caveats and workarounds. /// - /// **NOTE:** Prefer [`cargo_bin!`][crate::cargo::cargo_bin!] as this makes assumptions about cargo + /// Cargo support: + /// - `>1.94`: works + /// - `>=1.91,<=1.93`: works with default `build-dir` + /// - `<=1.92`: works /// /// # Examples ///