@@ -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 ,
@@ -201,11 +201,12 @@ struct TextTest {
201
201
}
202
202
203
203
impl TextTest {
204
+ /// Prints the user-visible name for this test.
204
205
fn msg ( & self ) -> String {
205
206
if self . revision . is_empty ( ) {
206
207
self . path . display ( ) . to_string ( )
207
208
} else {
208
- format ! ( "{} ({} )" , self . path. display( ) , self . revision)
209
+ format ! ( "{} (revision `{}` )" , self . path. display( ) , self . revision)
209
210
}
210
211
}
211
212
}
@@ -218,7 +219,7 @@ impl TestStatus for TextTest {
218
219
} else {
219
220
let result = match result {
220
221
Ok ( TestOk :: Ok ) => "ok" . green ( ) ,
221
- Err ( Errored { .. } ) => "FAILED" . red ( ) . bold ( ) ,
222
+ Err ( Errored { .. } ) => "FAILED" . bright_red ( ) . bold ( ) ,
222
223
Ok ( TestOk :: Ignored ) => "ignored (in-test comment)" . yellow ( ) ,
223
224
Ok ( TestOk :: Filtered ) => return ,
224
225
} ;
@@ -243,17 +244,10 @@ impl TestStatus for TextTest {
243
244
stderr : & ' a [ u8 ] ,
244
245
stdout : & ' a [ u8 ] ,
245
246
) -> Box < dyn Debug + ' a > {
247
+ let text = format ! ( "{} {}" , "FAILED TEST:" . bright_red( ) , self . msg( ) ) ;
248
+
246
249
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 ! ( ) ;
250
+ println ! ( "{}" , text. bold( ) . underline( ) ) ;
257
251
println ! ( "command: {cmd:?}" ) ;
258
252
println ! ( ) ;
259
253
@@ -264,10 +258,10 @@ impl TestStatus for TextTest {
264
258
}
265
259
impl < ' a > Drop for Guard < ' a > {
266
260
fn drop ( & mut self ) {
267
- println ! ( "full stderr:" ) ;
261
+ println ! ( "{}" , " full stderr:". bold ( ) ) ;
268
262
std:: io:: stdout ( ) . write_all ( self . stderr ) . unwrap ( ) ;
269
263
println ! ( ) ;
270
- println ! ( "full stdout:" ) ;
264
+ println ! ( "{}" , " full stdout:". bold ( ) ) ;
271
265
std:: io:: stdout ( ) . write_all ( self . stdout ) . unwrap ( ) ;
272
266
println ! ( ) ;
273
267
println ! ( ) ;
@@ -374,12 +368,12 @@ impl StatusEmitter for Text {
374
368
375
369
impl Drop for Summarizer {
376
370
fn drop ( & mut self ) {
377
- println ! ( "{}" , "FAILURES:" . red ( ) . underline( ) . bold( ) ) ;
371
+ println ! ( "{}" , "FAILURES:" . bright_red ( ) . underline( ) . bold( ) ) ;
378
372
for line in & self . failures {
379
373
println ! ( "{line}" ) ;
380
374
}
381
375
println ! ( ) ;
382
- print ! ( "test result: {}." , "FAIL" . red ( ) ) ;
376
+ print ! ( "test result: {}." , "FAIL" . bright_red ( ) ) ;
383
377
print ! ( " {} failed;" , self . failures. len( ) . to_string( ) . green( ) ) ;
384
378
if self . succeeded > 0 {
385
379
print ! ( " {} passed;" , self . succeeded. to_string( ) . green( ) ) ;
@@ -405,16 +399,27 @@ impl StatusEmitter for Text {
405
399
}
406
400
407
401
fn print_error ( error : & Error , path : & Path ) {
402
+ /// Every error starts with a header like that, to make them all easy to find.
403
+ /// It is made to look like the headers printed for spanned errors.
404
+ fn print_error_header ( msg : impl Display ) {
405
+ let text = format ! ( "{} {msg}" , "error:" . bright_red( ) ) ;
406
+ println ! ( "{}" , text. bold( ) ) ;
407
+ }
408
+
408
409
match error {
409
410
Error :: ExitStatus {
410
411
mode,
411
412
status,
412
413
expected,
413
414
} => {
414
- println ! ( "{mode} test got {status}, but expected {expected}" )
415
+ // `status` prints as `exit status: N`.
416
+ print_error_header ( format_args ! (
417
+ "{mode} test got {status}, but expected {expected}"
418
+ ) )
415
419
}
416
420
Error :: Command { kind, status } => {
417
- println ! ( "{kind} failed with {status}" ) ;
421
+ // `status` prints as `exit status: N`.
422
+ print_error_header ( format_args ! ( "{kind} failed with {status}" ) ) ;
418
423
}
419
424
Error :: PatternNotFound {
420
425
pattern,
@@ -432,6 +437,7 @@ fn print_error(error: &Error, path: &Path) {
432
437
format ! ( "`/{r}/` does not match diagnostics {line}" , )
433
438
}
434
439
} ;
440
+ // This will print a suitable error header.
435
441
create_error (
436
442
msg,
437
443
& [ (
@@ -442,7 +448,7 @@ fn print_error(error: &Error, path: &Path) {
442
448
) ;
443
449
}
444
450
Error :: NoPatternsFound => {
445
- println ! ( "{}" , " no error patterns found in fail test". red ( ) ) ;
451
+ print_error_header ( " no error patterns found in fail test") ;
446
452
}
447
453
Error :: PatternFoundInPassTest { mode, span } => {
448
454
let annot = [ ( "expected because of this annotation" , Some ( * span) ) ] ;
@@ -451,6 +457,7 @@ fn print_error(error: &Error, path: &Path) {
451
457
if let Some ( mode) = mode {
452
458
lines. push ( ( & annot, mode. line_start ) )
453
459
}
460
+ // This will print a suitable error header.
454
461
create_error ( "error pattern found in pass test" , & lines, path) ;
455
462
}
456
463
Error :: OutputDiffers {
@@ -459,7 +466,7 @@ fn print_error(error: &Error, path: &Path) {
459
466
expected,
460
467
bless_command,
461
468
} => {
462
- println ! ( "{}" , " actual output differed from expected". underline ( ) ) ;
469
+ print_error_header ( " actual output differed from expected") ;
463
470
println ! (
464
471
"Execute `{}` to update `{}` to the actual output" ,
465
472
bless_command,
@@ -483,8 +490,9 @@ fn print_error(error: &Error, path: &Path) {
483
490
. iter ( )
484
491
. map ( |msg| ( format ! ( "{:?}: {}" , msg. level, msg. message) , msg. line_col ) )
485
492
. collect :: < Vec < _ > > ( ) ;
493
+ // This will print a suitable error header.
486
494
create_error (
487
- format ! ( "There were {} unmatched diagnostics" , msgs. len( ) ) ,
495
+ format ! ( "there were {} unmatched diagnostics" , msgs. len( ) ) ,
488
496
& [ (
489
497
& msgs
490
498
. iter ( )
@@ -495,10 +503,10 @@ fn print_error(error: &Error, path: &Path) {
495
503
path,
496
504
) ;
497
505
} else {
498
- println ! (
499
- "There were {} unmatched diagnostics that occurred outside the testfile and had no pattern" ,
506
+ print_error_header ( format_args ! (
507
+ "there were {} unmatched diagnostics that occurred outside the testfile and had no pattern" ,
500
508
msgs. len( ) ,
501
- ) ;
509
+ ) ) ;
502
510
for Message {
503
511
level,
504
512
message,
@@ -510,10 +518,12 @@ fn print_error(error: &Error, path: &Path) {
510
518
}
511
519
}
512
520
Error :: InvalidComment { msg, span } => {
521
+ // This will print a suitable error header.
513
522
create_error ( msg, & [ ( & [ ( "" , Some ( * span) ) ] , span. line_start ) ] , path)
514
523
}
515
524
Error :: MultipleRevisionsWithResults { kind, lines } => {
516
525
let title = format ! ( "multiple {kind} found" ) ;
526
+ // This will print a suitable error header.
517
527
create_error (
518
528
title,
519
529
& lines
@@ -524,23 +534,28 @@ fn print_error(error: &Error, path: &Path) {
524
534
)
525
535
}
526
536
Error :: Bug ( msg) => {
527
- println ! ( "A bug in `ui_test` occurred: {msg}" ) ;
537
+ print_error_header ( "a bug in `ui_test` occurred" ) ;
538
+ println ! ( "{msg}" ) ;
528
539
}
529
540
Error :: Aux {
530
541
path : aux_path,
531
542
errors,
532
543
line,
533
544
} => {
534
- println ! ( "Aux build from {}:{line} failed" , path. display( ) ) ;
545
+ print_error_header ( format_args ! (
546
+ "aux build from {}:{line} failed" ,
547
+ path. display( )
548
+ ) ) ;
535
549
for error in errors {
536
550
print_error ( error, aux_path) ;
537
551
}
538
552
}
539
553
Error :: Rustfix ( error) => {
540
- println ! (
541
- "failed to apply suggestions for {} with rustfix: {error} " ,
554
+ print_error_header ( format_args ! (
555
+ "failed to apply suggestions for {} with rustfix" ,
542
556
path. display( )
543
- ) ;
557
+ ) ) ;
558
+ println ! ( "{error}" ) ;
544
559
println ! ( "Add //@no-rustfix to the test file to ignore rustfix suggestions" ) ;
545
560
}
546
561
}
0 commit comments