@@ -81,7 +81,9 @@ pub struct Assert {
81
81
expect_success : bool ,
82
82
expect_exit_code : Option < i32 > ,
83
83
expect_output : Option < String > ,
84
- fuzzy : bool ,
84
+ fuzzy_output : bool ,
85
+ expect_error_output : Option < String > ,
86
+ fuzzy_error_output : bool ,
85
87
}
86
88
87
89
impl std:: default:: Default for Assert {
@@ -93,7 +95,9 @@ impl std::default::Default for Assert {
93
95
expect_success : true ,
94
96
expect_exit_code : None ,
95
97
expect_output : None ,
96
- fuzzy : false ,
98
+ fuzzy_output : false ,
99
+ expect_error_output : None ,
100
+ fuzzy_error_output : false ,
97
101
}
98
102
}
99
103
}
@@ -226,7 +230,7 @@ impl Assert {
226
230
/// ```
227
231
pub fn prints < O : Into < String > > ( mut self , output : O ) -> Self {
228
232
self . expect_output = Some ( output. into ( ) ) ;
229
- self . fuzzy = true ;
233
+ self . fuzzy_output = true ;
230
234
self
231
235
}
232
236
@@ -243,7 +247,43 @@ impl Assert {
243
247
/// ```
244
248
pub fn prints_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
245
249
self . expect_output = Some ( output. into ( ) ) ;
246
- self . fuzzy = false ;
250
+ self . fuzzy_output = false ;
251
+ self
252
+ }
253
+
254
+ /// Expect the command's stderr output to contain `output`
255
+ ///
256
+ /// # Examples
257
+ ///
258
+ /// ```rust
259
+ /// extern crate assert_cli;
260
+ ///
261
+ /// assert_cli::Assert::command(&["cat", "non-exisiting-file"])
262
+ /// .fails()
263
+ /// .prints_error("non-exisiting-file")
264
+ /// .unwrap();
265
+ /// ```
266
+ pub fn prints_error < O : Into < String > > ( mut self , output : O ) -> Self {
267
+ self . expect_error_output = Some ( output. into ( ) ) ;
268
+ self . fuzzy_error_output = true ;
269
+ self
270
+ }
271
+
272
+ /// Expect the command to output exactly this `output` to stderr
273
+ ///
274
+ /// # Examples
275
+ ///
276
+ /// ```rust
277
+ /// extern crate assert_cli;
278
+ ///
279
+ /// assert_cli::Assert::command(&["cat", "non-exisiting-file"])
280
+ /// .fails()
281
+ /// .prints_error_exactly("cat: non-exisiting-file: No such file or directory")
282
+ /// .unwrap();
283
+ /// ```
284
+ pub fn prints_error_exactly < O : Into < String > > ( mut self , output : O ) -> Self {
285
+ self . expect_error_output = Some ( output. into ( ) ) ;
286
+ self . fuzzy_error_output = false ;
247
287
self
248
288
}
249
289
@@ -284,7 +324,7 @@ impl Assert {
284
324
}
285
325
286
326
let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
287
- match ( self . expect_output , self . fuzzy ) {
327
+ match ( self . expect_output , self . fuzzy_output ) {
288
328
( Some ( ref expected_output) , true ) if !stdout. contains ( expected_output) => {
289
329
bail ! ( ErrorKind :: OutputMismatch (
290
330
expected_output. clone( ) ,
@@ -301,6 +341,24 @@ impl Assert {
301
341
_ => { } ,
302
342
}
303
343
344
+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
345
+ match ( self . expect_error_output , self . fuzzy_error_output ) {
346
+ ( Some ( ref expected_output) , true ) if !stderr. contains ( expected_output) => {
347
+ bail ! ( ErrorKind :: ErrorOutputMismatch (
348
+ expected_output. clone( ) ,
349
+ stderr. into( ) ,
350
+ ) ) ;
351
+ } ,
352
+ ( Some ( ref expected_output) , false ) => {
353
+ let differences = Changeset :: new ( expected_output. trim ( ) , stderr. trim ( ) , "\n " ) ;
354
+ if differences. distance > 0 {
355
+ let nice_diff = diff:: render ( & differences) ?;
356
+ bail ! ( ErrorKind :: ExactErrorOutputMismatch ( nice_diff) ) ;
357
+ }
358
+ } ,
359
+ _ => { } ,
360
+ }
361
+
304
362
Ok ( ( ) )
305
363
}
306
364
0 commit comments