@@ -753,29 +753,31 @@ impl<'test> TestCx<'test> {
753753 }
754754
755755 if !unexpected. is_empty ( ) || !not_found. is_empty ( ) {
756- // Show relative path for brevity, and normalize path separators to `/`.
756+ self . error ( & format ! (
757+ "{} unexpected diagnostics reported, {} expected diagnostics not reported" ,
758+ unexpected. len( ) ,
759+ not_found. len( )
760+ ) ) ;
761+
762+ // Emit locations in a format that is short (relative paths) but "clickable" in editors.
763+ // Also normalize path separators to `/`.
757764 let file_name = self
758765 . testpaths
759766 . file
760767 . strip_prefix ( self . config . src_root . as_str ( ) )
761768 . unwrap_or ( & self . testpaths . file )
762769 . to_string ( )
763770 . replace ( r"\" , "/" ) ;
764-
765- self . error ( & format ! (
766- "{} unexpected diagnostics reported, {} expected diagnostics not reported" ,
767- unexpected. len( ) ,
768- not_found. len( )
769- ) ) ;
770- let print = |e : & Error | {
771+ let line_str = |e : & Error | {
771772 let line_num = e. line_num . map_or ( "?" . to_string ( ) , |line_num| line_num. to_string ( ) ) ;
772773 // `file:?:NUM` may be confusing to editors and unclickable.
773774 let opt_col_num = match e. column_num {
774- Some ( col_num) if line_num != "?" => format ! ( "{col_num}: " ) ,
775+ Some ( col_num) if line_num != "?" => format ! ( ": {col_num}" ) ,
775776 _ => "" . to_string ( ) ,
776777 } ;
777- println ! ( "{file_name}:{line_num}: {opt_col_num} {}: {}" , e . kind , e . msg . cyan ( ) )
778+ format ! ( "{file_name}:{line_num}{opt_col_num}" )
778779 } ;
780+ let print = |e : & Error | println ! ( "{}: {}: {}" , line_str( e) , e. kind, e. msg. cyan( ) ) ;
779781 // Fuzzy matching quality:
780782 // - message and line / message and kind - great, suggested
781783 // - only message - good, suggested
@@ -788,19 +790,40 @@ impl<'test> TestCx<'test> {
788790 print ( error) ;
789791 for candidate in & not_found {
790792 if error. msg . contains ( & candidate. msg ) {
791- let prefix = if candidate. line_num != error. line_num {
792- "expected on a different line"
793+ let line_mismatch = candidate. line_num != error. line_num ;
794+ let kind_mismatch = candidate. kind != error. kind ;
795+ if kind_mismatch && line_mismatch {
796+ println ! (
797+ " {} {} {} {}" ,
798+ "expected with kind" . red( ) ,
799+ candidate. kind,
800+ "on line" . red( ) ,
801+ line_str( candidate)
802+ ) ;
803+ } else if kind_mismatch {
804+ println ! ( " {} {}" , "expected with kind" . red( ) , candidate. kind) ;
793805 } else {
794- "expected with a different kind"
806+ println ! ( " {} {}" , "expected on line" . red ( ) , line_str ( candidate ) ) ;
795807 }
796- . red ( ) ;
797- print ! ( " {prefix}: " ) ;
798- print ( candidate) ;
799808 } else if candidate. line_num . is_some ( )
800809 && candidate. line_num == error. line_num
801810 {
802- print ! ( " {}: " , "expected with a different message" . red( ) ) ;
803- print ( candidate) ;
811+ let kind_mismatch = candidate. kind != error. kind ;
812+ if kind_mismatch {
813+ println ! (
814+ " {} {} {} {}" ,
815+ "expected with kind" . red( ) ,
816+ candidate. kind,
817+ "with message" . red( ) ,
818+ candidate. msg. cyan( )
819+ ) ;
820+ } else {
821+ println ! (
822+ " {} {}" ,
823+ "expected with message" . red( ) ,
824+ candidate. msg. cyan( )
825+ ) ;
826+ }
804827 }
805828 }
806829 }
@@ -812,19 +835,44 @@ impl<'test> TestCx<'test> {
812835 print ( error) ;
813836 for candidate in unexpected. iter ( ) . chain ( & unimportant) {
814837 if candidate. msg . contains ( & error. msg ) {
815- let prefix = if candidate. line_num != error. line_num {
816- "reported on a different line"
838+ let line_mismatch = candidate. line_num != error. line_num ;
839+ let kind_mismatch = candidate. kind != error. kind ;
840+ if kind_mismatch && line_mismatch {
841+ println ! (
842+ " {} {} {} {}" ,
843+ "reported with kind" . green( ) ,
844+ candidate. kind,
845+ "on line" . green( ) ,
846+ line_str( candidate)
847+ ) ;
848+ } else if kind_mismatch {
849+ println ! ( " {} {}" , "reported with kind" . green( ) , candidate. kind) ;
817850 } else {
818- "reported with a different kind"
851+ println ! (
852+ " {} {}" ,
853+ "reported on line" . green( ) ,
854+ line_str( candidate)
855+ ) ;
819856 }
820- . green ( ) ;
821- print ! ( " {prefix}: " ) ;
822- print ( candidate) ;
823857 } else if candidate. line_num . is_some ( )
824858 && candidate. line_num == error. line_num
825859 {
826- print ! ( " {}: " , "reported with a different message" . green( ) ) ;
827- print ( candidate) ;
860+ let kind_mismatch = candidate. kind != error. kind ;
861+ if kind_mismatch {
862+ println ! (
863+ " {} {} {} {}" ,
864+ "reported with kind" . green( ) ,
865+ candidate. kind,
866+ "with message" . green( ) ,
867+ candidate. msg. cyan( )
868+ ) ;
869+ } else {
870+ println ! (
871+ " {} {}" ,
872+ "reported with message" . green( ) ,
873+ candidate. msg. cyan( )
874+ ) ;
875+ }
828876 }
829877 }
830878 }
0 commit comments