File tree 4 files changed +60
-25
lines changed
4 files changed +60
-25
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ use std::fmt;
60
60
use std:: path;
61
61
use std:: process;
62
62
63
+ #[ doc( inline) ]
64
+ pub use crate :: cargo_bin;
65
+
63
66
/// Create a [`Command`] for a `bin` in the Cargo project.
64
67
///
65
68
/// `CommandCargoExt` is an extension trait for [`Command`][std::process::Command] to easily launch a crate's
95
98
/// this method with [cross](https://github.com/cross-rs/cross), no extra configuration is
96
99
/// needed.
97
100
///
101
+ /// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo
102
+ ///
98
103
/// # Examples
99
104
///
100
105
/// ```rust,no_run
@@ -217,6 +222,8 @@ fn target_dir() -> path::PathBuf {
217
222
}
218
223
219
224
/// Look up the path to a cargo-built binary within an integration test.
225
+ ///
226
+ /// **NOTE:** Prefer [`cargo_bin!`] as this makes assumptions about cargo
220
227
pub fn cargo_bin < S : AsRef < str > > ( name : S ) -> path:: PathBuf {
221
228
cargo_bin_str ( name. as_ref ( ) )
222
229
}
Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ impl Command {
37
37
///
38
38
/// See the [`cargo` module documentation][crate::cargo] for caveats and workarounds.
39
39
///
40
+ /// **NOTE:** Prefer [`cargo_bin!`][crate::cargo::cargo_bin!] as this makes assumptions about cargo
41
+ ///
40
42
/// # Examples
41
43
///
42
44
/// ```rust,no_run
Original file line number Diff line number Diff line change 104
104
#![ warn( clippy:: print_stderr) ]
105
105
#![ warn( clippy:: print_stdout) ]
106
106
107
- /// Allows you to pull the name from your Cargo.toml at compile time.
108
- ///
109
- /// # Examples
110
- ///
111
- /// ```should_panic
112
- /// use assert_cmd::Command;
113
- ///
114
- /// let mut cmd = Command::cargo_bin(assert_cmd::crate_name!()).unwrap();
115
- /// let assert = cmd
116
- /// .arg("-A")
117
- /// .env("stdout", "hello")
118
- /// .env("exit", "42")
119
- /// .write_stdin("42")
120
- /// .assert();
121
- /// assert
122
- /// .failure()
123
- /// .code(42)
124
- /// .stdout("hello\n");
125
- /// ```
126
- #[ macro_export]
127
- macro_rules! crate_name {
128
- ( ) => {
129
- env!( "CARGO_PKG_NAME" )
130
- } ;
131
- }
107
+ mod macros;
132
108
133
109
pub mod assert;
134
110
pub mod cargo;
Original file line number Diff line number Diff line change
1
+ /// Allows you to pull the name from your Cargo.toml at compile time.
2
+ ///
3
+ /// # Examples
4
+ ///
5
+ /// ```should_panic
6
+ /// use assert_cmd::Command;
7
+ ///
8
+ /// let mut cmd = Command::cargo_bin(assert_cmd::crate_name!()).unwrap();
9
+ /// let assert = cmd
10
+ /// .arg("-A")
11
+ /// .env("stdout", "hello")
12
+ /// .env("exit", "42")
13
+ /// .write_stdin("42")
14
+ /// .assert();
15
+ /// assert
16
+ /// .failure()
17
+ /// .code(42)
18
+ /// .stdout("hello\n");
19
+ /// ```
20
+ #[ macro_export]
21
+ macro_rules! crate_name {
22
+ ( ) => {
23
+ env!( "CARGO_PKG_NAME" )
24
+ } ;
25
+ }
26
+
27
+ /// The absolute path to a binary target's executable.
28
+ ///
29
+ /// The `bin_target_name` is the name of the binary
30
+ /// target, exactly as-is.
31
+ ///
32
+ /// **NOTE:** This is only set when building an integration test or benchmark.
33
+ ///
34
+ /// ## Example
35
+ ///
36
+ /// ```rust,no_run
37
+ /// #[test]
38
+ /// fn cli_tests() {
39
+ /// trycmd::TestCases::new()
40
+ /// .default_bin_path(trycmd::cargo_bin!("bin-fixture"))
41
+ /// .case("tests/cmd/*.trycmd");
42
+ /// }
43
+ /// ```
44
+ #[ macro_export]
45
+ #[ doc( hidden) ]
46
+ macro_rules! cargo_bin {
47
+ ( $bin_target_name: expr) => {
48
+ :: std:: path:: Path :: new( env!( concat!( "CARGO_BIN_EXE_" , $bin_target_name) ) )
49
+ } ;
50
+ }
You can’t perform that action at this time.
0 commit comments