@@ -603,7 +603,10 @@ impl<'test> TestCx<'test> {
603603 ) ;
604604 } else {
605605 for pattern in missing_patterns {
606- self . error ( & format ! ( "error pattern '{}' not found!" , pattern) ) ;
606+ println ! (
607+ "\n {prefix}: error pattern '{pattern}' not found!" ,
608+ prefix = self . error_prefix( )
609+ ) ;
607610 }
608611 self . fatal_proc_rec ( "multiple error patterns not found" , proc_res) ;
609612 }
@@ -821,10 +824,11 @@ impl<'test> TestCx<'test> {
821824 // - only known line - meh, but suggested
822825 // - others are not worth suggesting
823826 if !unexpected. is_empty ( ) {
824- self . error ( & format ! (
825- "{} diagnostics reported in JSON output but not expected in test file" ,
826- unexpected. len( ) ,
827- ) ) ;
827+ println ! (
828+ "\n {prefix}: {n} diagnostics reported in JSON output but not expected in test file" ,
829+ prefix = self . error_prefix( ) ,
830+ n = unexpected. len( ) ,
831+ ) ;
828832 for error in & unexpected {
829833 print_error ( error) ;
830834 let mut suggestions = Vec :: new ( ) ;
@@ -854,10 +858,11 @@ impl<'test> TestCx<'test> {
854858 }
855859 }
856860 if !not_found. is_empty ( ) {
857- self . error ( & format ! (
858- "{} diagnostics expected in test file but not reported in JSON output" ,
859- not_found. len( )
860- ) ) ;
861+ println ! (
862+ "\n {prefix}: {n} diagnostics expected in test file but not reported in JSON output" ,
863+ prefix = self . error_prefix( ) ,
864+ n = not_found. len( ) ,
865+ ) ;
861866 for error in & not_found {
862867 print_error ( error) ;
863868 let mut suggestions = Vec :: new ( ) ;
@@ -1992,16 +1997,19 @@ impl<'test> TestCx<'test> {
19921997 output_base_name ( self . config , self . testpaths , self . safe_revision ( ) )
19931998 }
19941999
1995- fn error ( & self , err : & str ) {
2000+ /// Prefix to print before error messages. Normally just `error`, but also
2001+ /// includes the revision name for tests that use revisions.
2002+ #[ must_use]
2003+ fn error_prefix ( & self ) -> String {
19962004 match self . revision {
1997- Some ( rev) => println ! ( "\n error in revision `{}`: {}" , rev , err ) ,
1998- None => println ! ( "\n error: {}" , err ) ,
2005+ Some ( rev) => format ! ( "error in revision `{rev}`" ) ,
2006+ None => format ! ( "error" ) ,
19992007 }
20002008 }
20012009
20022010 #[ track_caller]
20032011 fn fatal ( & self , err : & str ) -> ! {
2004- self . error ( err ) ;
2012+ println ! ( " \n {prefix}: {err}" , prefix = self . error_prefix ( ) ) ;
20052013 error ! ( "fatal error, panic: {:?}" , err) ;
20062014 panic ! ( "fatal error" ) ;
20072015 }
@@ -2019,7 +2027,7 @@ impl<'test> TestCx<'test> {
20192027 proc_res : & ProcRes ,
20202028 callback_before_unwind : impl FnOnce ( ) ,
20212029 ) -> ! {
2022- self . error ( err ) ;
2030+ println ! ( " \n {prefix}: {err}" , prefix = self . error_prefix ( ) ) ;
20232031
20242032 // Some callers want to print additional notes after the main error message.
20252033 if let Some ( note) = extra_note {
0 commit comments