@@ -17,7 +17,7 @@ use crate::{
17
17
} ;
18
18
use std:: {
19
19
collections:: HashMap ,
20
- fmt:: { Debug , Write as _} ,
20
+ fmt:: { Debug , Display , Write as _} ,
21
21
io:: Write as _,
22
22
num:: NonZeroUsize ,
23
23
panic:: RefUnwindSafe ,
@@ -243,17 +243,14 @@ impl TestStatus for TextTest {
243
243
stderr : & ' a [ u8 ] ,
244
244
stdout : & ' a [ u8 ] ,
245
245
) -> Box < dyn Debug + ' a > {
246
+ let mut path = self . path . display ( ) . to_string ( ) ;
247
+ if !self . revision . is_empty ( ) {
248
+ write ! ( path, " (revision `{}`)" , self . revision) . unwrap ( ) ;
249
+ }
250
+ let text = format ! ( "{} {path}" , "FAILED TEST:" . red( ) ) ;
251
+
246
252
println ! ( ) ;
247
- let path = self . path . display ( ) . to_string ( ) ;
248
- print ! ( "{}" , path. underline( ) . bold( ) ) ;
249
- let revision = if self . revision . is_empty ( ) {
250
- String :: new ( )
251
- } else {
252
- format ! ( " (revision `{}`)" , self . revision)
253
- } ;
254
- print ! ( "{revision}" ) ;
255
- print ! ( " {}" , "FAILED:" . red( ) . bold( ) ) ;
256
- println ! ( ) ;
253
+ println ! ( "{}" , text. bold( ) . underline( ) ) ;
257
254
println ! ( "command: {cmd:?}" ) ;
258
255
println ! ( ) ;
259
256
@@ -264,10 +261,10 @@ impl TestStatus for TextTest {
264
261
}
265
262
impl < ' a > Drop for Guard < ' a > {
266
263
fn drop ( & mut self ) {
267
- println ! ( "full stderr:" ) ;
264
+ println ! ( "{}" , " full stderr:". bold ( ) ) ;
268
265
std:: io:: stdout ( ) . write_all ( self . stderr ) . unwrap ( ) ;
269
266
println ! ( ) ;
270
- println ! ( "full stdout:" ) ;
267
+ println ! ( "{}" , " full stdout:". bold ( ) ) ;
271
268
std:: io:: stdout ( ) . write_all ( self . stdout ) . unwrap ( ) ;
272
269
println ! ( ) ;
273
270
println ! ( ) ;
@@ -405,16 +402,27 @@ impl StatusEmitter for Text {
405
402
}
406
403
407
404
fn print_error ( error : & Error , path : & Path ) {
405
+ /// Every error starts with a header like that, to make them all easy to find.
406
+ /// It is made to look like the headers printed for spanned errors.
407
+ fn print_error_header ( msg : impl Display ) {
408
+ let text = format ! ( "{} {msg}" , "error:" . red( ) ) ;
409
+ println ! ( "{}" , text. bold( ) ) ;
410
+ }
411
+
408
412
match error {
409
413
Error :: ExitStatus {
410
414
mode,
411
415
status,
412
416
expected,
413
417
} => {
414
- println ! ( "{mode} test got {status}, but expected {expected}" )
418
+ // `status` prints as `exit status: N`.
419
+ print_error_header ( format_args ! (
420
+ "{mode} test got {status}, but expected {expected}"
421
+ ) )
415
422
}
416
423
Error :: Command { kind, status } => {
417
- println ! ( "{kind} failed with {status}" ) ;
424
+ // `status` prints as `exit status: N`.
425
+ print_error_header ( format_args ! ( "{kind} failed with {status}" ) ) ;
418
426
}
419
427
Error :: PatternNotFound {
420
428
pattern,
@@ -432,6 +440,7 @@ fn print_error(error: &Error, path: &Path) {
432
440
format ! ( "`/{r}/` does not match diagnostics {line}" , )
433
441
}
434
442
} ;
443
+ // This will print a suitable error header.
435
444
create_error (
436
445
msg,
437
446
& [ (
@@ -442,7 +451,7 @@ fn print_error(error: &Error, path: &Path) {
442
451
) ;
443
452
}
444
453
Error :: NoPatternsFound => {
445
- println ! ( "{}" , " no error patterns found in fail test". red ( ) ) ;
454
+ print_error_header ( " no error patterns found in fail test") ;
446
455
}
447
456
Error :: PatternFoundInPassTest { mode, span } => {
448
457
let annot = [ ( "expected because of this annotation" , Some ( * span) ) ] ;
@@ -451,6 +460,7 @@ fn print_error(error: &Error, path: &Path) {
451
460
if let Some ( mode) = mode {
452
461
lines. push ( ( & annot, mode. line_start ) )
453
462
}
463
+ // This will print a suitable error header.
454
464
create_error ( "error pattern found in pass test" , & lines, path) ;
455
465
}
456
466
Error :: OutputDiffers {
@@ -459,7 +469,7 @@ fn print_error(error: &Error, path: &Path) {
459
469
expected,
460
470
bless_command,
461
471
} => {
462
- println ! ( "{}" , " actual output differed from expected". underline ( ) ) ;
472
+ print_error_header ( " actual output differed from expected") ;
463
473
println ! (
464
474
"Execute `{}` to update `{}` to the actual output" ,
465
475
bless_command,
@@ -483,6 +493,7 @@ fn print_error(error: &Error, path: &Path) {
483
493
. iter ( )
484
494
. map ( |msg| ( format ! ( "{:?}: {}" , msg. level, msg. message) , msg. line_col ) )
485
495
. collect :: < Vec < _ > > ( ) ;
496
+ // This will print a suitable error header.
486
497
create_error (
487
498
format ! ( "There were {} unmatched diagnostics" , msgs. len( ) ) ,
488
499
& [ (
@@ -495,10 +506,10 @@ fn print_error(error: &Error, path: &Path) {
495
506
path,
496
507
) ;
497
508
} else {
498
- println ! (
499
- "There were {} unmatched diagnostics that occurred outside the testfile and had no pattern" ,
509
+ print_error_header ( format_args ! (
510
+ "there were {} unmatched diagnostics that occurred outside the testfile and had no pattern" ,
500
511
msgs. len( ) ,
501
- ) ;
512
+ ) ) ;
502
513
for Message {
503
514
level,
504
515
message,
@@ -510,10 +521,12 @@ fn print_error(error: &Error, path: &Path) {
510
521
}
511
522
}
512
523
Error :: InvalidComment { msg, span } => {
524
+ // This will print a suitable error header.
513
525
create_error ( msg, & [ ( & [ ( "" , Some ( * span) ) ] , span. line_start ) ] , path)
514
526
}
515
527
Error :: MultipleRevisionsWithResults { kind, lines } => {
516
528
let title = format ! ( "multiple {kind} found" ) ;
529
+ // This will print a suitable error header.
517
530
create_error (
518
531
title,
519
532
& lines
@@ -524,23 +537,28 @@ fn print_error(error: &Error, path: &Path) {
524
537
)
525
538
}
526
539
Error :: Bug ( msg) => {
527
- println ! ( "A bug in `ui_test` occurred: {msg}" ) ;
540
+ print_error_header ( "a bug in `ui_test` occurred" ) ;
541
+ println ! ( "{msg}" ) ;
528
542
}
529
543
Error :: Aux {
530
544
path : aux_path,
531
545
errors,
532
546
line,
533
547
} => {
534
- println ! ( "Aux build from {}:{line} failed" , path. display( ) ) ;
548
+ print_error_header ( format_args ! (
549
+ "aux build from {}:{line} failed" ,
550
+ path. display( )
551
+ ) ) ;
535
552
for error in errors {
536
553
print_error ( error, aux_path) ;
537
554
}
538
555
}
539
556
Error :: Rustfix ( error) => {
540
- println ! (
541
- "failed to apply suggestions for {} with rustfix: {error} " ,
557
+ print_error_header ( format_args ! (
558
+ "failed to apply suggestions for {} with rustfix" ,
542
559
path. display( )
543
- ) ;
560
+ ) ) ;
561
+ println ! ( "{error}" ) ;
544
562
println ! ( "Add //@no-rustfix to the test file to ignore rustfix suggestions" ) ;
545
563
}
546
564
}
0 commit comments