Skip to content

Commit 7af59b9

Browse files
authored
Merge pull request #282 from epage/deprecated
fix: Un-deprecate `cargo_bin`
2 parents 4bb85f9 + 80fe94c commit 7af59b9

File tree

5 files changed

+79
-47
lines changed

5 files changed

+79
-47
lines changed

src/cargo.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ where
102102
/// this method with [cross](https://github.com/cross-rs/cross), no extra configuration is
103103
/// needed.
104104
///
105-
/// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo
105+
/// Cargo support:
106+
/// - `>1.94`: works
107+
/// - `>=1.91,<=1.93`: works with default `build-dir`
108+
/// - `<=1.92`: works
106109
///
107110
/// # Examples
108111
///
@@ -130,16 +133,11 @@ where
130133
/// ```
131134
///
132135
/// [`Command`]: std::process::Command
133-
#[deprecated(
134-
since = "2.1.0",
135-
note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin!`"
136-
)]
137136
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError>;
138137
}
139138

140139
impl CommandCargoExt for crate::cmd::Command {
141140
fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, CargoError> {
142-
#[allow(deprecated)]
143141
crate::cmd::Command::cargo_bin(name)
144142
}
145143
}
@@ -151,7 +149,6 @@ impl CommandCargoExt for process::Command {
151149
}
152150

153151
pub(crate) fn cargo_bin_cmd<S: AsRef<str>>(name: S) -> Result<process::Command, CargoError> {
154-
#[allow(deprecated)]
155152
let path = cargo_bin(name);
156153
if path.is_file() {
157154
if let Some(runner) = cargo_runner() {
@@ -217,13 +214,12 @@ impl fmt::Display for NotFoundError {
217214
}
218215
}
219216

220-
/// Look up the path to a cargo-built binary within an integration test.
217+
/// Look up the path to a cargo-built binary within an integration test
221218
///
222-
/// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo
223-
#[deprecated(
224-
since = "2.1.0",
225-
note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin!`"
226-
)]
219+
/// Cargo support:
220+
/// - `>1.94`: works
221+
/// - `>=1.91,<=1.93`: works with default `build-dir`
222+
/// - `<=1.92`: works
227223
pub fn cargo_bin<S: AsRef<str>>(name: S) -> path::PathBuf {
228224
cargo_bin_str(name.as_ref())
229225
}

src/cmd.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ impl Command {
3737
///
3838
/// See the [`cargo` module documentation][crate::cargo] for caveats and workarounds.
3939
///
40-
/// **NOTE:** Prefer [`cargo_bin!`][crate::cargo::cargo_bin!] as this makes assumptions about cargo
40+
/// Cargo support:
41+
/// - `>1.94`: works
42+
/// - `>=1.91,<=1.93`: works with default `build-dir`
43+
/// - `<=1.92`: works
4144
///
4245
/// # Examples
4346
///
@@ -60,10 +63,6 @@ impl Command {
6063
/// println!("{:?}", output);
6164
/// ```
6265
///
63-
#[deprecated(
64-
since = "2.1.0",
65-
note = "incompatible with a custom cargo build-dir, see instead `cargo::cargo_bin_cmd!`"
66-
)]
6766
pub fn cargo_bin<S: AsRef<str>>(name: S) -> Result<Self, crate::cargo::CargoError> {
6867
let cmd = crate::cargo::cargo_bin_cmd(name)?;
6968
Ok(Self::from_std(cmd))

tests/assert.rs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::process::Command;
22

3-
use assert_cmd::cargo_bin;
43
use assert_cmd::prelude::*;
54
use predicates::prelude::*;
65

76
#[test]
87
fn stdout_string() {
98
let expected = "hello\n".to_owned();
10-
Command::new(cargo_bin!("bin_fixture"))
9+
Command::cargo_bin("bin_fixture")
10+
.unwrap()
1111
.env("stdout", "hello")
1212
.env("stderr", "world")
1313
.assert()
@@ -16,88 +16,101 @@ fn stdout_string() {
1616

1717
#[test]
1818
fn trait_example() {
19-
let mut cmd = Command::new(cargo_bin!("bin_fixture"));
19+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
2020
cmd.assert().success();
2121
}
2222

2323
#[test]
2424
fn trait_assert_example() {
25-
let mut cmd = Command::new(cargo_bin!("bin_fixture"));
25+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
2626
cmd.assert().success();
2727
}
2828

2929
#[test]
3030
fn struct_example() {
31-
let mut cmd = Command::new(cargo_bin!("bin_fixture"));
31+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
3232
cmd.assert().success();
3333
}
3434

3535
#[test]
3636
fn append_context_example() {
37-
Command::new(cargo_bin!("bin_fixture"))
37+
Command::cargo_bin("bin_fixture")
38+
.unwrap()
3839
.assert()
3940
.append_context("main", "no args")
4041
.success();
4142
}
4243

4344
#[test]
4445
fn success_example() {
45-
Command::new(cargo_bin!("bin_fixture")).assert().success();
46+
Command::cargo_bin("bin_fixture")
47+
.unwrap()
48+
.assert()
49+
.success();
4650
}
4751

4852
#[test]
4953
fn failure_example() {
50-
Command::new(cargo_bin!("bin_fixture"))
54+
Command::cargo_bin("bin_fixture")
55+
.unwrap()
5156
.env("exit", "1")
5257
.assert()
5358
.failure();
5459
}
5560

5661
#[test]
5762
fn code_example() {
58-
Command::new(cargo_bin!("bin_fixture"))
63+
Command::cargo_bin("bin_fixture")
64+
.unwrap()
5965
.env("exit", "42")
6066
.assert()
6167
.code(predicate::eq(42));
6268

63-
Command::new(cargo_bin!("bin_fixture"))
69+
Command::cargo_bin("bin_fixture")
70+
.unwrap()
6471
.env("exit", "42")
6572
.assert()
6673
.code(42);
6774

68-
Command::new(cargo_bin!("bin_fixture"))
75+
Command::cargo_bin("bin_fixture")
76+
.unwrap()
6977
.env("exit", "42")
7078
.assert()
7179
.code(&[2, 42] as &[i32]);
7280
}
7381

7482
#[test]
7583
fn stdout_example() {
76-
Command::new(cargo_bin!("bin_fixture"))
84+
Command::cargo_bin("bin_fixture")
85+
.unwrap()
7786
.env("stdout", "hello")
7887
.env("stderr", "world")
7988
.assert()
8089
.stdout(predicate::eq(b"hello\n" as &[u8]));
8190

82-
Command::new(cargo_bin!("bin_fixture"))
91+
Command::cargo_bin("bin_fixture")
92+
.unwrap()
8393
.env("stdout", "hello")
8494
.env("stderr", "world")
8595
.assert()
8696
.stdout(predicate::str::diff("hello\n"));
8797

88-
Command::new(cargo_bin!("bin_fixture"))
98+
Command::cargo_bin("bin_fixture")
99+
.unwrap()
89100
.env("stdout", "hello")
90101
.env("stderr", "world")
91102
.assert()
92103
.stdout(b"hello\n" as &[u8]);
93104

94-
Command::new(cargo_bin!("bin_fixture"))
105+
Command::cargo_bin("bin_fixture")
106+
.unwrap()
95107
.env("stdout", "hello")
96108
.env("stderr", "world")
97109
.assert()
98110
.stdout(vec![b'h', b'e', b'l', b'l', b'o', b'\n']);
99111

100-
Command::new(cargo_bin!("bin_fixture"))
112+
Command::cargo_bin("bin_fixture")
113+
.unwrap()
101114
.env("stdout", "hello")
102115
.env("stderr", "world")
103116
.assert()
@@ -106,31 +119,36 @@ fn stdout_example() {
106119

107120
#[test]
108121
fn stderr_example() {
109-
Command::new(cargo_bin!("bin_fixture"))
122+
Command::cargo_bin("bin_fixture")
123+
.unwrap()
110124
.env("stdout", "hello")
111125
.env("stderr", "world")
112126
.assert()
113127
.stderr(predicate::eq(b"world\n" as &[u8]));
114128

115-
Command::new(cargo_bin!("bin_fixture"))
129+
Command::cargo_bin("bin_fixture")
130+
.unwrap()
116131
.env("stdout", "hello")
117132
.env("stderr", "world")
118133
.assert()
119134
.stderr(predicate::str::diff("world\n"));
120135

121-
Command::new(cargo_bin!("bin_fixture"))
136+
Command::cargo_bin("bin_fixture")
137+
.unwrap()
122138
.env("stdout", "hello")
123139
.env("stderr", "world")
124140
.assert()
125141
.stderr(b"world\n" as &[u8]);
126142

127-
Command::new(cargo_bin!("bin_fixture"))
143+
Command::cargo_bin("bin_fixture")
144+
.unwrap()
128145
.env("stdout", "hello")
129146
.env("stderr", "world")
130147
.assert()
131148
.stderr(vec![b'w', b'o', b'r', b'l', b'd', b'\n']);
132149

133-
Command::new(cargo_bin!("bin_fixture"))
150+
Command::cargo_bin("bin_fixture")
151+
.unwrap()
134152
.env("stdout", "hello")
135153
.env("stderr", "world")
136154
.assert()

tests/cargo.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use std::process::Command;
22

3-
use assert_cmd::cargo_bin;
3+
use assert_cmd::pkg_name;
44
use assert_cmd::prelude::*;
55
use escargot::CURRENT_TARGET;
66

77
#[test]
88
fn cargo_binary() {
9-
let mut cmd = Command::new(cargo_bin!("bin_fixture"));
9+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
1010
cmd.env("stdout", "42");
1111
cmd.assert().success().stdout("42\n");
1212
}
1313

1414
#[test]
1515
fn cargo_binary_with_empty_env() {
16-
let mut cmd = Command::new(cargo_bin!("bin_fixture"));
16+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
1717
cmd.env_clear().env("stdout", "42");
1818
cmd.assert().success().stdout("42\n");
1919
}
@@ -39,9 +39,25 @@ fn mod_example() {
3939
}
4040
}
4141

42+
#[test]
43+
#[should_panic] // No bin named `assert_cmd`
44+
fn trait_example() {
45+
let mut cmd = Command::cargo_bin(pkg_name!()).unwrap();
46+
let output = cmd.unwrap();
47+
println!("{output:?}");
48+
}
49+
50+
#[test]
51+
#[should_panic] // No bin named `assert_cmd`
52+
fn cargo_bin_example_1() {
53+
let mut cmd = Command::cargo_bin(pkg_name!()).unwrap();
54+
let output = cmd.unwrap();
55+
println!("{output:?}");
56+
}
57+
4258
#[test]
4359
fn cargo_bin_example_2() {
44-
let mut cmd = Command::new(cargo_bin!("bin_fixture"));
60+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
4561
let output = cmd.unwrap();
4662
println!("{output:?}");
4763
}

tests/examples.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use assert_cmd::cargo::cargo_bin_cmd;
1+
use assert_cmd::Command;
22

33
#[test]
44
fn lib_example() {
5-
let mut cmd = cargo_bin_cmd!("bin_fixture");
5+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
66
cmd.assert().success();
77

8-
let mut cmd = cargo_bin_cmd!("bin_fixture");
8+
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
99
let assert = cmd
1010
.arg("-A")
1111
.env("stdout", "hello")
@@ -17,7 +17,10 @@ fn lib_example() {
1717

1818
#[test]
1919
fn timeout_example() {
20-
let assert = cargo_bin_cmd!("bin_fixture")
20+
use assert_cmd::Command;
21+
22+
let assert = Command::cargo_bin("bin_fixture")
23+
.unwrap()
2124
.timeout(std::time::Duration::from_secs(1))
2225
.env("sleep", "100")
2326
.assert();

0 commit comments

Comments
 (0)