11use std:: fs;
22
3+ use assert_cmd:: cargo_bin;
34use assert_cmd:: Command ;
45use predicates:: prelude:: * ;
56
67use clap_stdin:: StdinError ;
78
89#[ test]
910fn test_maybe_stdin_positional_arg ( ) {
10- Command :: cargo_bin ( "maybe_stdin_positional_arg" )
11- . unwrap ( )
11+ Command :: new ( cargo_bin ! ( "maybe_stdin_positional_arg" ) )
1212 . args ( [ "FIRST" , "--second" , "SECOND" ] )
1313 . assert ( )
1414 . success ( )
1515 . stdout ( predicate:: str:: starts_with (
1616 r#"Args { first: "FIRST", second: Some("SECOND") }"# ,
1717 ) ) ;
18- Command :: cargo_bin ( "maybe_stdin_positional_arg" )
19- . unwrap ( )
18+ Command :: new ( cargo_bin ! ( "maybe_stdin_positional_arg" ) )
2019 . args ( [ "-" , "--second" , "SECOND" ] )
2120 . write_stdin ( "TESTING" )
2221 . assert ( )
2322 . success ( )
2423 . stdout ( predicate:: str:: starts_with (
2524 r#"Args { first: "TESTING", second: Some("SECOND") }"# ,
2625 ) ) ;
27- Command :: cargo_bin ( "maybe_stdin_positional_arg" )
28- . unwrap ( )
26+ Command :: new ( cargo_bin ! ( "maybe_stdin_positional_arg" ) )
2927 . args ( [ "FIRST" ] )
3028 . write_stdin ( "TESTING" )
3129 . assert ( )
@@ -37,25 +35,22 @@ fn test_maybe_stdin_positional_arg() {
3735
3836#[ test]
3937fn test_maybe_stdin_optional_arg ( ) {
40- Command :: cargo_bin ( "maybe_stdin_optional_arg" )
41- . unwrap ( )
38+ Command :: new ( cargo_bin ! ( "maybe_stdin_optional_arg" ) )
4239 . args ( [ "FIRST" , "--second" , "2" ] )
4340 . assert ( )
4441 . success ( )
4542 . stdout ( predicate:: str:: starts_with (
4643 r#"Args { first: "FIRST", second: Some(2) }"# ,
4744 ) ) ;
48- Command :: cargo_bin ( "maybe_stdin_optional_arg" )
49- . unwrap ( )
45+ Command :: new ( cargo_bin ! ( "maybe_stdin_optional_arg" ) )
5046 . write_stdin ( "2\n " )
5147 . args ( [ "FIRST" , "--second" , "-" ] )
5248 . assert ( )
5349 . success ( )
5450 . stdout ( predicate:: str:: starts_with (
5551 r#"Args { first: "FIRST", second: Some(2) }"# ,
5652 ) ) ;
57- Command :: cargo_bin ( "maybe_stdin_optional_arg" )
58- . unwrap ( )
53+ Command :: new ( cargo_bin ! ( "maybe_stdin_optional_arg" ) )
5954 . args ( [ "FIRST" ] )
6055 . write_stdin ( "TESTING" )
6156 . assert ( )
@@ -67,16 +62,14 @@ fn test_maybe_stdin_optional_arg() {
6762
6863#[ test]
6964fn test_maybe_stdin_twice ( ) {
70- Command :: cargo_bin ( "maybe_stdin_twice" )
71- . unwrap ( )
65+ Command :: new ( cargo_bin ! ( "maybe_stdin_twice" ) )
7266 . args ( [ "FIRST" , "2" ] )
7367 . assert ( )
7468 . success ( )
7569 . stdout ( predicate:: str:: starts_with (
7670 r#"Args { first: "FIRST", second: 2 }"# ,
7771 ) ) ;
78- Command :: cargo_bin ( "maybe_stdin_twice" )
79- . unwrap ( )
72+ Command :: new ( cargo_bin ! ( "maybe_stdin_twice" ) )
8073 . write_stdin ( "2" )
8174 . args ( [ "FIRST" , "-" ] )
8275 . assert ( )
@@ -86,8 +79,7 @@ fn test_maybe_stdin_twice() {
8679 ) ) ;
8780
8881 // Actually using stdin twice will fail because there's no value the second time
89- Command :: cargo_bin ( "maybe_stdin_twice" )
90- . unwrap ( )
82+ Command :: new ( cargo_bin ! ( "maybe_stdin_twice" ) )
9183 . write_stdin ( "3" )
9284 . args ( [ "-" , "-" ] )
9385 . assert ( )
@@ -103,25 +95,22 @@ fn test_file_or_stdin_positional_arg() {
10395 fs:: write ( & tmp, "FILE" ) . expect ( "couldn't write to temp file" ) ;
10496 let tmp_path = tmp. path ( ) . to_str ( ) . unwrap ( ) ;
10597
106- Command :: cargo_bin ( "file_or_stdin_positional_arg" )
107- . unwrap ( )
98+ Command :: new ( cargo_bin ! ( "file_or_stdin_positional_arg" ) )
10899 . args ( [ & tmp_path, "--second" , "SECOND" ] )
109100 . assert ( )
110101 . success ( )
111102 . stdout ( predicate:: str:: starts_with (
112103 r#"FIRST: FILE; SECOND: Some("SECOND")"# ,
113104 ) ) ;
114- Command :: cargo_bin ( "file_or_stdin_positional_arg" )
115- . unwrap ( )
105+ Command :: new ( cargo_bin ! ( "file_or_stdin_positional_arg" ) )
116106 . args ( [ "--second" , "SECOND" ] )
117107 . write_stdin ( "STDIN" )
118108 . assert ( )
119109 . success ( )
120110 . stdout ( predicate:: str:: starts_with (
121111 r#"FIRST: STDIN; SECOND: Some("SECOND")"# ,
122112 ) ) ;
123- Command :: cargo_bin ( "file_or_stdin_positional_arg" )
124- . unwrap ( )
113+ Command :: new ( cargo_bin ! ( "file_or_stdin_positional_arg" ) )
125114 . args ( [ & tmp_path] )
126115 . write_stdin ( "TESTING" )
127116 . assert ( )
@@ -136,25 +125,22 @@ fn test_file_or_stdin_optional_arg() {
136125 fs:: write ( & tmp, "2" ) . expect ( "couldn't write to temp file" ) ;
137126 let tmp_path = tmp. path ( ) . to_str ( ) . unwrap ( ) ;
138127
139- Command :: cargo_bin ( "file_or_stdin_optional_arg" )
140- . unwrap ( )
128+ Command :: new ( cargo_bin ! ( "file_or_stdin_optional_arg" ) )
141129 . args ( [ "FIRST" , "--second" , & tmp_path] )
142130 . assert ( )
143131 . success ( )
144132 . stdout ( predicate:: str:: starts_with (
145133 r#"FIRST: FIRST, SECOND: Some(2)"# ,
146134 ) ) ;
147- Command :: cargo_bin ( "file_or_stdin_optional_arg" )
148- . unwrap ( )
135+ Command :: new ( cargo_bin ! ( "file_or_stdin_optional_arg" ) )
149136 . write_stdin ( "2\n " )
150137 . args ( [ "FIRST" , "--second" , "-" ] )
151138 . assert ( )
152139 . success ( )
153140 . stdout ( predicate:: str:: starts_with (
154141 r#"FIRST: FIRST, SECOND: Some(2)"# ,
155142 ) ) ;
156- Command :: cargo_bin ( "file_or_stdin_optional_arg" )
157- . unwrap ( )
143+ Command :: new ( cargo_bin ! ( "file_or_stdin_optional_arg" ) )
158144 . args ( [ "FIRST" ] )
159145 . write_stdin ( "TESTING" )
160146 . assert ( )
@@ -168,23 +154,20 @@ fn test_file_or_stdin_twice() {
168154 fs:: write ( & tmp, "FILE" ) . expect ( "couldn't write to temp file" ) ;
169155 let tmp_path = tmp. path ( ) . to_str ( ) . unwrap ( ) ;
170156
171- Command :: cargo_bin ( "file_or_stdin_twice" )
172- . unwrap ( )
157+ Command :: new ( cargo_bin ! ( "file_or_stdin_twice" ) )
173158 . args ( [ & tmp_path, "2" ] )
174159 . assert ( )
175160 . success ( )
176161 . stdout ( predicate:: str:: starts_with ( r#"FIRST: FILE; SECOND: 2"# ) ) ;
177- Command :: cargo_bin ( "file_or_stdin_twice" )
178- . unwrap ( )
162+ Command :: new ( cargo_bin ! ( "file_or_stdin_twice" ) )
179163 . write_stdin ( "2" )
180164 . args ( [ & tmp_path, "-" ] )
181165 . assert ( )
182166 . success ( )
183167 . stdout ( predicate:: str:: starts_with ( r#"FIRST: FILE; SECOND: 2"# ) ) ;
184168
185169 // Actually using stdin twice will fail because there's no value the second time
186- Command :: cargo_bin ( "file_or_stdin_twice" )
187- . unwrap ( )
170+ Command :: new ( cargo_bin ! ( "file_or_stdin_twice" ) )
188171 . write_stdin ( "3" )
189172 . args ( [ "-" , "-" ] )
190173 . assert ( )
@@ -200,25 +183,22 @@ fn test_is_stdin() {
200183 fs:: write ( & tmp, "FILE" ) . expect ( "couldn't write to temp file" ) ;
201184 let tmp_path = tmp. path ( ) . to_str ( ) . unwrap ( ) ;
202185
203- Command :: cargo_bin ( "is_stdin" )
204- . unwrap ( )
186+ Command :: new ( cargo_bin ! ( "is_stdin" ) )
205187 . args ( [ & tmp_path, "2" ] )
206188 . assert ( )
207189 . success ( )
208190 . stdout ( predicate:: str:: contains (
209191 r#"FIRST is_stdin: false; SECOND is_stdin: false"# ,
210192 ) ) ;
211- Command :: cargo_bin ( "is_stdin" )
212- . unwrap ( )
193+ Command :: new ( cargo_bin ! ( "is_stdin" ) )
213194 . write_stdin ( "2" )
214195 . args ( [ & tmp_path, "-" ] )
215196 . assert ( )
216197 . success ( )
217198 . stdout ( predicate:: str:: contains (
218199 r#"FIRST is_stdin: false; SECOND is_stdin: true"# ,
219200 ) ) ;
220- Command :: cargo_bin ( "is_stdin" )
221- . unwrap ( )
201+ Command :: new ( cargo_bin ! ( "is_stdin" ) )
222202 . write_stdin ( "testing" )
223203 . args ( [ "-" , "2" ] )
224204 . assert ( )
@@ -233,23 +213,20 @@ fn test_file_or_stdout_positional_args() {
233213 let tmp = tempfile:: NamedTempFile :: new ( ) . expect ( "couldn't create temp file" ) ;
234214 let tmp_path = tmp. path ( ) . to_str ( ) . unwrap ( ) ;
235215
236- Command :: cargo_bin ( "file_or_stdout_positional_arg" )
237- . unwrap ( )
216+ Command :: new ( cargo_bin ! ( "file_or_stdout_positional_arg" ) )
238217 . args ( [ "-v" , "FILE" , tmp_path] )
239218 . assert ( )
240219 . success ( ) ;
241220 let output = String :: from_utf8_lossy ( & std:: fs:: read ( & tmp_path) . unwrap ( ) ) . to_string ( ) ;
242221 assert_eq ! ( & output, "FILE\n " ) ;
243222
244- Command :: cargo_bin ( "file_or_stdout_positional_arg" )
245- . unwrap ( )
223+ Command :: new ( cargo_bin ! ( "file_or_stdout_positional_arg" ) )
246224 . args ( [ "-v" , "FILE" , "-" ] )
247225 . assert ( )
248226 . success ( )
249227 . stdout ( predicate:: str:: starts_with ( r#"FILE"# ) ) ;
250228
251- Command :: cargo_bin ( "file_or_stdout_positional_arg" )
252- . unwrap ( )
229+ Command :: new ( cargo_bin ! ( "file_or_stdout_positional_arg" ) )
253230 . args ( [ "-v" , "FILE" ] )
254231 . assert ( )
255232 . success ( )
@@ -261,23 +238,20 @@ fn test_file_or_stdout_optional_args() {
261238 let tmp = tempfile:: NamedTempFile :: new ( ) . expect ( "couldn't create temp file" ) ;
262239 let tmp_path = tmp. path ( ) . to_str ( ) . unwrap ( ) ;
263240
264- Command :: cargo_bin ( "file_or_stdout_optional_arg" )
265- . unwrap ( )
241+ Command :: new ( cargo_bin ! ( "file_or_stdout_optional_arg" ) )
266242 . args ( [ "-v" , "FILE" , "--output" , tmp_path] )
267243 . assert ( )
268244 . success ( ) ;
269245 let output = String :: from_utf8_lossy ( & std:: fs:: read ( & tmp_path) . unwrap ( ) ) . to_string ( ) ;
270246 assert_eq ! ( & output, "FILE\n " ) ;
271247
272- Command :: cargo_bin ( "file_or_stdout_optional_arg" )
273- . unwrap ( )
248+ Command :: new ( cargo_bin ! ( "file_or_stdout_optional_arg" ) )
274249 . args ( [ "-v" , "FILE" , "--output" , "-" ] )
275250 . assert ( )
276251 . success ( )
277252 . stdout ( predicate:: str:: starts_with ( r#"FILE"# ) ) ;
278253
279- Command :: cargo_bin ( "file_or_stdout_optional_arg" )
280- . unwrap ( )
254+ Command :: new ( cargo_bin ! ( "file_or_stdout_optional_arg" ) )
281255 . args ( [ "-v" , "FILE" ] )
282256 . assert ( )
283257 . success ( )
0 commit comments