@@ -18,6 +18,7 @@ use std::{
18
18
} ;
19
19
20
20
use enum_map:: { Enum , EnumMap , enum_map} ;
21
+ use similar_asserts:: SimpleDiff ;
21
22
use tempfile:: TempDir ;
22
23
use url:: Url ;
23
24
@@ -236,12 +237,14 @@ impl Config {
236
237
let out = self . run ( args[ 0 ] , & args[ 1 ..] , env) . await ;
237
238
if !out. ok || out. stdout != stdout || out. stderr != stderr {
238
239
print_command ( args, & out) ;
239
- println ! ( "expected.ok: true" ) ;
240
- print_indented ( "expected.stdout" , stdout) ;
241
- print_indented ( "expected.stderr" , stderr) ;
242
- dbg ! ( out. stdout == stdout) ;
243
- dbg ! ( out. stderr == stderr) ;
244
- panic ! ( ) ;
240
+ print_diff ( stdout, & out. stdout ) ;
241
+ print_diff ( stderr, & out. stderr ) ;
242
+ panic ! (
243
+ "expected OK, differences found: ok = {}, stdout = {}, stderr = {}" ,
244
+ out. ok,
245
+ out. stdout == stdout,
246
+ out. stderr == stderr
247
+ ) ;
245
248
}
246
249
}
247
250
@@ -250,18 +253,14 @@ impl Config {
250
253
let out = self . run ( args[ 0 ] , & args[ 1 ..] , & [ ] ) . await ;
251
254
if out. ok || out. stdout != stdout || out. stderr != stderr {
252
255
print_command ( args, & out) ;
253
- println ! ( "expected.ok: false" ) ;
254
- print_indented ( "expected.stdout" , stdout) ;
255
- print_indented ( "expected.stderr" , stderr) ;
256
- if out. ok {
257
- panic ! ( "expected command to fail" ) ;
258
- } else if out. stdout != stdout {
259
- panic ! ( "expected stdout to match" ) ;
260
- } else if out. stderr != stderr {
261
- panic ! ( "expected stderr to match" ) ;
262
- } else {
263
- unreachable ! ( )
264
- }
256
+ print_diff ( stdout, & out. stdout ) ;
257
+ print_diff ( stderr, & out. stderr ) ;
258
+ panic ! (
259
+ "expected error, differences found: ok = {}, stdout = {}, stderr = {}" ,
260
+ out. ok,
261
+ out. stdout == stdout,
262
+ out. stderr == stderr
263
+ ) ;
265
264
}
266
265
}
267
266
@@ -430,6 +429,17 @@ impl Config {
430
429
}
431
430
}
432
431
432
+ fn print_diff ( expected : & str , actual : & str ) {
433
+ if expected == actual {
434
+ return ;
435
+ }
436
+
437
+ println ! (
438
+ "{}" ,
439
+ SimpleDiff :: from_str( expected, actual, "expected" , "actual" )
440
+ ) ;
441
+ }
442
+
433
443
// Describes all the features of the mock dist server.
434
444
// Building the mock server is slow, so use simple scenario when possible.
435
445
#[ derive( Copy , Clone , Debug , Eq , PartialEq , Enum ) ]
0 commit comments