1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! A module for getting the crate binary in an integration test.
//!
//! If you are writing a command-line interface app then it is useful to write
//! an integration test that uses the binary. You most likely want to launch the
//! binary and inspect the output. This module lets you get the binary so it can
//! be tested.
//!
//! # Examples
//!
//! basic usage:
//!
//! ```ignore
//! let output = test_bin::get_test_bin("my_cli_app")
//! .output()
//! .expect("Failed to start my_cli_app");
//! assert_eq!(
//! String::from_utf8_lossy(&output.stdout),
//! "Output from my CLI app!\n"
//! );
//! ```
//!
//! Refer to the [`std::process::Command` documentation](https://doc.rust-lang.org/std/process/struct.Command.html)
//! for how to pass arguments, check exit status and more.
//!
//! NOTE: The `get_test_bin` function was deprecated in version 0.5.0 in favor
//! of the `get_test_bin!` macro and then undeprecated in version 0.6.0. The
//! macro was added because there was talk of changing cargo so the function
//! wouldn't work. Fortunately, cargo was changed so that the macro wasn't
//! needed. The `get_test_bin` function is the recommended way of using
//! this crate. See [Cargo issue 14125](https://github.com/rust-lang/cargo/issues/14125).
//!
//! The `get_test_bin!` macro uses the `CARGO_BIN_EXE_<name>` environment
//! variable which was introduced in [Rust 1.43 released on 23 April 2020](https://releases.rs/docs/1.43.0/).
//!
/// Returns the crate's binary as a `Command` that can be used for integration
/// tests.
///
/// # Arguments
///
/// * `bin_name` - The name of the binary you want to test.
///
/// # Remarks
///
/// It panics on error. This is by design so the test that uses it fails.
/// Returns the directory of the crate's binary.
///
/// # Remarks
///
/// It panics on error. This is by design so the test that uses it fails.
/// Returns the crate's binary as a `Command` that can be used for integration
/// tests.
///
/// # Arguments
///
/// * `bin_name` - The name of the binary you want to test. It must be a string literal.
///
/// # Remarks
///
/// It will fail to compile if the `bin_name` is incorrect. The `bin_name` is
/// used for creating an environment variable.
///
/// If you want to not use a string literal every time then you can define a
/// macro that returns a string literal:
/// ```rust
/// macro_rules! my_cli_app {
/// () => ( "my_cli_app" )
/// }
/// ```
/// And then use `my_cli_app!()` as the argument.