1
1
use std:: default;
2
2
use std:: process:: Command ;
3
3
use std:: path:: PathBuf ;
4
+ use std:: vec:: Vec ;
4
5
5
6
use errors:: * ;
6
7
use output:: { OutputAssertion , StdErr , StdOut } ;
@@ -12,8 +13,8 @@ pub struct Assert {
12
13
current_dir : Option < PathBuf > ,
13
14
expect_success : Option < bool > ,
14
15
expect_exit_code : Option < i32 > ,
15
- expect_stdout : Option < OutputAssertion < StdOut > > ,
16
- expect_stderr : Option < OutputAssertion < StdErr > > ,
16
+ expect_stdout : Vec < OutputAssertion < StdOut > > ,
17
+ expect_stderr : Vec < OutputAssertion < StdErr > > ,
17
18
}
18
19
19
20
impl default:: Default for Assert {
@@ -27,8 +28,8 @@ impl default::Default for Assert {
27
28
current_dir : None ,
28
29
expect_success : Some ( true ) ,
29
30
expect_exit_code : None ,
30
- expect_stdout : None ,
31
- expect_stderr : None ,
31
+ expect_stdout : vec ! [ ] ,
32
+ expect_stderr : vec ! [ ] ,
32
33
}
33
34
}
34
35
}
@@ -189,7 +190,7 @@ impl Assert {
189
190
/// .unwrap();
190
191
/// ```
191
192
pub fn prints < O : Into < String > > ( mut self , output : O ) -> Self {
192
- self . expect_stdout = Some ( OutputAssertion {
193
+ self . expect_stdout . push ( OutputAssertion {
193
194
expect : output. into ( ) ,
194
195
fuzzy : true ,
195
196
expected_result : true ,
@@ -210,7 +211,7 @@ impl Assert {
210
211
/// .unwrap();
211
212
/// ```
212
213
pub fn prints_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
213
- self . expect_stdout = Some ( OutputAssertion {
214
+ self . expect_stdout . push ( OutputAssertion {
214
215
expect : output. into ( ) ,
215
216
fuzzy : false ,
216
217
expected_result : true ,
@@ -233,7 +234,7 @@ impl Assert {
233
234
/// .unwrap();
234
235
/// ```
235
236
pub fn prints_error < O : Into < String > > ( mut self , output : O ) -> Self {
236
- self . expect_stderr = Some ( OutputAssertion {
237
+ self . expect_stderr . push ( OutputAssertion {
237
238
expect : output. into ( ) ,
238
239
fuzzy : true ,
239
240
expected_result : true ,
@@ -256,7 +257,7 @@ impl Assert {
256
257
/// .unwrap();
257
258
/// ```
258
259
pub fn prints_error_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
259
- self . expect_stderr = Some ( OutputAssertion {
260
+ self . expect_stderr . push ( OutputAssertion {
260
261
expect : output. into ( ) ,
261
262
fuzzy : false ,
262
263
expected_result : true ,
@@ -278,7 +279,7 @@ impl Assert {
278
279
/// .unwrap();
279
280
/// ```
280
281
pub fn doesnt_print < O : Into < String > > ( mut self , output : O ) -> Self {
281
- self . expect_stdout = Some ( OutputAssertion {
282
+ self . expect_stdout . push ( OutputAssertion {
282
283
expect : output. into ( ) ,
283
284
fuzzy : true ,
284
285
expected_result : false ,
@@ -300,7 +301,7 @@ impl Assert {
300
301
/// .unwrap();
301
302
/// ```
302
303
pub fn doesnt_print_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
303
- self . expect_stdout = Some ( OutputAssertion {
304
+ self . expect_stdout . push ( OutputAssertion {
304
305
expect : output. into ( ) ,
305
306
fuzzy : false ,
306
307
expected_result : false ,
@@ -324,7 +325,7 @@ impl Assert {
324
325
/// .unwrap();
325
326
/// ```
326
327
pub fn doesnt_print_error < O : Into < String > > ( mut self , output : O ) -> Self {
327
- self . expect_stderr = Some ( OutputAssertion {
328
+ self . expect_stderr . push ( OutputAssertion {
328
329
expect : output. into ( ) ,
329
330
fuzzy : true ,
330
331
expected_result : false ,
@@ -348,7 +349,7 @@ impl Assert {
348
349
/// .unwrap();
349
350
/// ```
350
351
pub fn doesnt_print_error_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
351
- self . expect_stderr = Some ( OutputAssertion {
352
+ self . expect_stderr . push ( OutputAssertion {
352
353
expect : output. into ( ) ,
353
354
fuzzy : false ,
354
355
expected_result : false ,
@@ -380,7 +381,6 @@ impl Assert {
380
381
} ;
381
382
let output = command. output ( ) ?;
382
383
383
-
384
384
if let Some ( expect_success) = self . expect_success {
385
385
if expect_success != output. status . success ( ) {
386
386
bail ! ( ErrorKind :: StatusMismatch (
@@ -399,15 +399,14 @@ impl Assert {
399
399
) ) ;
400
400
}
401
401
402
- if let Some ( ref ouput_assertion) = self . expect_stdout {
403
- ouput_assertion. execute ( & output)
404
- . map_err ( |e| ErrorKind :: StdoutMismatch ( self . cmd . clone ( ) , e) ) ?;
405
- }
406
-
407
- if let Some ( ref ouput_assertion) = self . expect_stderr {
408
- ouput_assertion. execute ( & output)
409
- . map_err ( |e| ErrorKind :: StderrMismatch ( self . cmd . clone ( ) , e) ) ?;
410
- }
402
+ self . expect_stdout
403
+ . iter ( )
404
+ . map ( |a| a. execute ( & output) . map_err ( |e| ErrorKind :: StdoutMismatch ( self . cmd . clone ( ) , e) . into ( ) ) )
405
+ . collect :: < Result < Vec < ( ) > > > ( ) ?;
406
+ self . expect_stderr
407
+ . iter ( )
408
+ . map ( |a| a. execute ( & output) . map_err ( |e| ErrorKind :: StderrMismatch ( self . cmd . clone ( ) , e) . into ( ) ) )
409
+ . collect :: < Result < Vec < ( ) > > > ( ) ?;
411
410
412
411
Ok ( ( ) )
413
412
}
0 commit comments