@@ -8,6 +8,8 @@ use std::str;
8
8
9
9
use predicates;
10
10
use predicates:: str:: PredicateStrExt ;
11
+ use predicates_core;
12
+ use predicates_tree:: CaseTreeExt ;
11
13
12
14
use errors:: dump_buffer;
13
15
use errors:: output_fmt;
@@ -185,23 +187,15 @@ impl Assert {
185
187
/// ```
186
188
pub fn failure ( self ) -> Self {
187
189
if self . output . status . success ( ) {
188
- panic ! (
189
- "Unexpected success\n stdout=```{}```\n {}" ,
190
- dump_buffer( & self . output. stdout) ,
191
- self
192
- ) ;
190
+ panic ! ( "Unexpected success\n {}" , self ) ;
193
191
}
194
192
self
195
193
}
196
194
197
195
/// Ensure the command aborted before returning a code.
198
196
pub fn interrupted ( self ) -> Self {
199
197
if self . output . status . code ( ) . is_some ( ) {
200
- panic ! (
201
- "Unexpected completion\n stdout=```{}```\n {}" ,
202
- dump_buffer( & self . output. stdout) ,
203
- self
204
- ) ;
198
+ panic ! ( "Unexpected completion\n {}" , self ) ;
205
199
}
206
200
self
207
201
}
@@ -224,26 +218,21 @@ impl Assert {
224
218
pub fn code < I , P > ( self , pred : I ) -> Self
225
219
where
226
220
I : IntoCodePredicate < P > ,
227
- P : predicates :: Predicate < i32 > ,
221
+ P : predicates_core :: Predicate < i32 > ,
228
222
{
229
223
self . code_impl ( & pred. into_code ( ) )
230
224
}
231
225
232
- fn code_impl ( self , pred : & predicates :: Predicate < i32 > ) -> Self {
226
+ fn code_impl ( self , pred : & predicates_core :: Predicate < i32 > ) -> Self {
233
227
let actual_code = self . output . status . code ( ) . unwrap_or_else ( || {
234
228
panic ! (
235
229
"Command interrupted\n stderr=```{}```\n {}" ,
236
230
dump_buffer( & self . output. stderr) ,
237
231
self
238
232
)
239
233
} ) ;
240
- if !pred. eval ( & actual_code) {
241
- panic ! (
242
- "Unexpected return code\n stdout=```{}```\n stderr=```{}```\n {}" ,
243
- dump_buffer( & self . output. stdout) ,
244
- dump_buffer( & self . output. stderr) ,
245
- self
246
- ) ;
234
+ if let Some ( case) = pred. find_case ( false , & actual_code) {
235
+ panic ! ( "Unexpected return code, failed {}\n {}" , case. tree( ) , self ) ;
247
236
}
248
237
self
249
238
}
@@ -267,16 +256,16 @@ impl Assert {
267
256
pub fn stdout < I , P > ( self , pred : I ) -> Self
268
257
where
269
258
I : IntoOutputPredicate < P > ,
270
- P : predicates :: Predicate < [ u8 ] > ,
259
+ P : predicates_core :: Predicate < [ u8 ] > ,
271
260
{
272
261
self . stdout_impl ( & pred. into_output ( ) )
273
262
}
274
263
275
- fn stdout_impl ( self , pred : & predicates :: Predicate < [ u8 ] > ) -> Self {
264
+ fn stdout_impl ( self , pred : & predicates_core :: Predicate < [ u8 ] > ) -> Self {
276
265
{
277
266
let actual = & self . output . stdout ;
278
- if ! pred. eval ( actual) {
279
- panic ! ( "Unexpected stdout\n {}" , self ) ;
267
+ if let Some ( case ) = pred. find_case ( false , & actual) {
268
+ panic ! ( "Unexpected stdout, failed {} \n {}" , case . tree ( ) , self ) ;
280
269
}
281
270
}
282
271
self
@@ -301,16 +290,16 @@ impl Assert {
301
290
pub fn stderr < I , P > ( self , pred : I ) -> Self
302
291
where
303
292
I : IntoOutputPredicate < P > ,
304
- P : predicates :: Predicate < [ u8 ] > ,
293
+ P : predicates_core :: Predicate < [ u8 ] > ,
305
294
{
306
295
self . stderr_impl ( & pred. into_output ( ) )
307
296
}
308
297
309
- fn stderr_impl ( self , pred : & predicates :: Predicate < [ u8 ] > ) -> Self {
298
+ fn stderr_impl ( self , pred : & predicates_core :: Predicate < [ u8 ] > ) -> Self {
310
299
{
311
300
let actual = & self . output . stderr ;
312
- if ! pred. eval ( actual) {
313
- panic ! ( "Unexpected stderr\n {}" , self ) ;
301
+ if let Some ( case ) = pred. find_case ( false , & actual) {
302
+ panic ! ( "Unexpected stderr, failed {} \n \n {}" , case . tree ( ) , self ) ;
314
303
}
315
304
}
316
305
self
@@ -358,10 +347,10 @@ impl fmt::Debug for Assert {
358
347
/// ```
359
348
///
360
349
/// [`Assert::code`]: struct.Assert.html#method.code
361
- /// [`Predicate<i32>`]: https://docs.rs/predicates/0.5.2/predicates /trait.Predicate.html
350
+ /// [`Predicate<i32>`]: https://docs.rs/predicates-core /0.9.0/predicates_core /trait.Predicate.html
362
351
pub trait IntoCodePredicate < P >
363
352
where
364
- P : predicates :: Predicate < i32 > ,
353
+ P : predicates_core :: Predicate < i32 > ,
365
354
{
366
355
/// The type of the predicate being returned.
367
356
type Predicate ;
@@ -372,7 +361,7 @@ where
372
361
373
362
impl < P > IntoCodePredicate < P > for P
374
363
where
375
- P : predicates :: Predicate < i32 > ,
364
+ P : predicates_core :: Predicate < i32 > ,
376
365
{
377
366
type Predicate = P ;
378
367
@@ -410,10 +399,10 @@ impl IntoCodePredicate<predicates::iter::InPredicate<i32>> for &'static [i32] {
410
399
///
411
400
/// [`Assert::stdout`]: struct.Assert.html#method.stdout
412
401
/// [`Assert::stderr`]: struct.Assert.html#method.stderr
413
- /// [`Predicate<[u8]>`]: https://docs.rs/predicates/0.5.2/predicates /trait.Predicate.html
402
+ /// [`Predicate<[u8]>`]: https://docs.rs/predicates-core /0.9.0/predicates_core /trait.Predicate.html
414
403
pub trait IntoOutputPredicate < P >
415
404
where
416
- P : predicates :: Predicate < [ u8 ] > ,
405
+ P : predicates_core :: Predicate < [ u8 ] > ,
417
406
{
418
407
/// The type of the predicate being returned.
419
408
type Predicate ;
@@ -424,7 +413,7 @@ where
424
413
425
414
impl < P > IntoOutputPredicate < P > for P
426
415
where
427
- P : predicates :: Predicate < [ u8 ] > ,
416
+ P : predicates_core :: Predicate < [ u8 ] > ,
428
417
{
429
418
type Predicate = P ;
430
419
@@ -437,7 +426,7 @@ where
437
426
/// [Predicate] used by [`IntoOutputPredicate`] for bytes.
438
427
///
439
428
/// [`IntoOutputPredicate`]: trait.IntoOutputPredicate.html
440
- /// [Predicate]: https://docs.rs/predicates/0.5.2/predicates /trait.Predicate.html
429
+ /// [Predicate]: https://docs.rs/predicates-core /0.9.0/predicates_core /trait.Predicate.html
441
430
#[ derive( Debug ) ]
442
431
pub struct BytesContentOutputPredicate ( predicates:: ord:: EqPredicate < & ' static [ u8 ] > ) ;
443
432
@@ -448,10 +437,31 @@ impl BytesContentOutputPredicate {
448
437
}
449
438
}
450
439
451
- impl predicates:: Predicate < [ u8 ] > for BytesContentOutputPredicate {
440
+ impl predicates_core:: reflection:: PredicateReflection for BytesContentOutputPredicate {
441
+ fn parameters < ' a > (
442
+ & ' a self ,
443
+ ) -> Box < Iterator < Item = predicates_core:: reflection:: Parameter < ' a > > + ' a > {
444
+ self . 0 . parameters ( )
445
+ }
446
+
447
+ /// Nested `Predicate`s of the current `Predicate`.
448
+ fn children < ' a > ( & ' a self ) -> Box < Iterator < Item = predicates_core:: reflection:: Child < ' a > > + ' a > {
449
+ self . 0 . children ( )
450
+ }
451
+ }
452
+
453
+ impl predicates_core:: Predicate < [ u8 ] > for BytesContentOutputPredicate {
452
454
fn eval ( & self , item : & [ u8 ] ) -> bool {
453
455
self . 0 . eval ( item)
454
456
}
457
+
458
+ fn find_case < ' a > (
459
+ & ' a self ,
460
+ expected : bool ,
461
+ variable : & [ u8 ] ,
462
+ ) -> Option < predicates_core:: reflection:: Case < ' a > > {
463
+ self . 0 . find_case ( expected, variable)
464
+ }
455
465
}
456
466
457
467
impl fmt:: Display for BytesContentOutputPredicate {
@@ -472,7 +482,7 @@ impl IntoOutputPredicate<BytesContentOutputPredicate> for &'static [u8] {
472
482
/// [Predicate] used by [`IntoOutputPredicate`] for [`str`].
473
483
///
474
484
/// [`IntoOutputPredicate`]: trait.IntoOutputPredicate.html
475
- /// [Predicate]: https://docs.rs/predicates/0.5.2/predicates /trait.Predicate.html
485
+ /// [Predicate]: https://docs.rs/predicates-core /0.9.0/predicates_core /trait.Predicate.html
476
486
/// [`str`]: https://doc.rust-lang.org/std/primitive.str.html
477
487
#[ derive( Debug , Clone ) ]
478
488
pub struct StrContentOutputPredicate (
@@ -486,10 +496,31 @@ impl StrContentOutputPredicate {
486
496
}
487
497
}
488
498
489
- impl predicates:: Predicate < [ u8 ] > for StrContentOutputPredicate {
499
+ impl predicates_core:: reflection:: PredicateReflection for StrContentOutputPredicate {
500
+ fn parameters < ' a > (
501
+ & ' a self ,
502
+ ) -> Box < Iterator < Item = predicates_core:: reflection:: Parameter < ' a > > + ' a > {
503
+ self . 0 . parameters ( )
504
+ }
505
+
506
+ /// Nested `Predicate`s of the current `Predicate`.
507
+ fn children < ' a > ( & ' a self ) -> Box < Iterator < Item = predicates_core:: reflection:: Child < ' a > > + ' a > {
508
+ self . 0 . children ( )
509
+ }
510
+ }
511
+
512
+ impl predicates_core:: Predicate < [ u8 ] > for StrContentOutputPredicate {
490
513
fn eval ( & self , item : & [ u8 ] ) -> bool {
491
514
self . 0 . eval ( item)
492
515
}
516
+
517
+ fn find_case < ' a > (
518
+ & ' a self ,
519
+ expected : bool ,
520
+ variable : & [ u8 ] ,
521
+ ) -> Option < predicates_core:: reflection:: Case < ' a > > {
522
+ self . 0 . find_case ( expected, variable)
523
+ }
493
524
}
494
525
495
526
impl fmt:: Display for StrContentOutputPredicate {
@@ -517,7 +548,7 @@ mod test {
517
548
fn convert_code < I , P > ( pred : I ) -> P
518
549
where
519
550
I : IntoCodePredicate < P > ,
520
- P : predicates :: Predicate < i32 > ,
551
+ P : predicates_core :: Predicate < i32 > ,
521
552
{
522
553
pred. into_code ( )
523
554
}
@@ -551,7 +582,7 @@ mod test {
551
582
fn convert_output < I , P > ( pred : I ) -> P
552
583
where
553
584
I : IntoOutputPredicate < P > ,
554
- P : predicates :: Predicate < [ u8 ] > ,
585
+ P : predicates_core :: Predicate < [ u8 ] > ,
555
586
{
556
587
pred. into_output ( )
557
588
}
0 commit comments