@@ -603,7 +603,10 @@ impl<'test> TestCx<'test> {
603
603
) ;
604
604
} else {
605
605
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
+ ) ;
607
610
}
608
611
self . fatal_proc_rec ( "multiple error patterns not found" , proc_res) ;
609
612
}
@@ -821,10 +824,11 @@ impl<'test> TestCx<'test> {
821
824
// - only known line - meh, but suggested
822
825
// - others are not worth suggesting
823
826
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
+ ) ;
828
832
for error in & unexpected {
829
833
print_error ( error) ;
830
834
let mut suggestions = Vec :: new ( ) ;
@@ -854,10 +858,11 @@ impl<'test> TestCx<'test> {
854
858
}
855
859
}
856
860
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
+ ) ;
861
866
for error in & not_found {
862
867
print_error ( error) ;
863
868
let mut suggestions = Vec :: new ( ) ;
@@ -1992,16 +1997,19 @@ impl<'test> TestCx<'test> {
1992
1997
output_base_name ( self . config , self . testpaths , self . safe_revision ( ) )
1993
1998
}
1994
1999
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 {
1996
2004
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" ) ,
1999
2007
}
2000
2008
}
2001
2009
2002
2010
#[ track_caller]
2003
2011
fn fatal ( & self , err : & str ) -> ! {
2004
- self . error ( err ) ;
2012
+ println ! ( " \n {prefix}: {err}" , prefix = self . error_prefix ( ) ) ;
2005
2013
error ! ( "fatal error, panic: {:?}" , err) ;
2006
2014
panic ! ( "fatal error" ) ;
2007
2015
}
@@ -2019,7 +2027,7 @@ impl<'test> TestCx<'test> {
2019
2027
proc_res : & ProcRes ,
2020
2028
callback_before_unwind : impl FnOnce ( ) ,
2021
2029
) -> ! {
2022
- self . error ( err ) ;
2030
+ println ! ( " \n {prefix}: {err}" , prefix = self . error_prefix ( ) ) ;
2023
2031
2024
2032
// Some callers want to print additional notes after the main error message.
2025
2033
if let Some ( note) = extra_note {
0 commit comments