diff --git a/src/cargo.rs b/src/cargo.rs index ba1119f..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 /// @@ -130,16 +133,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 +149,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() { @@ -217,13 +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 -#[deprecated( - since = "2.1.0", - note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin!`" -)] +/// 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 1d50a79..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 /// @@ -60,10 +63,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..19838c3 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();