@@ -788,41 +788,70 @@ impl<'test> TestCx<'test> {
788788 println ! ( "{}" , "--- reported but not expected (from JSON output) ---" . green( ) ) ;
789789 for error in & unexpected {
790790 print ( error) ;
791+ let mut suggestions = Vec :: new ( ) ;
791792 for candidate in & not_found {
792793 if error. msg . contains ( & candidate. msg ) {
793794 let line_mismatch = candidate. line_num != error. line_num ;
794795 let kind_mismatch = candidate. kind != error. kind ;
795796 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- ) ;
797+ suggestions. push ( (
798+ format ! (
799+ " {} {} {} {}" ,
800+ "expected with kind" . red( ) ,
801+ candidate. kind,
802+ "on line" . red( ) ,
803+ line_str( candidate)
804+ ) ,
805+ 0 ,
806+ ) ) ;
803807 } else if kind_mismatch {
804- println ! ( " {} {}" , "expected with kind" . red( ) , candidate. kind) ;
808+ suggestions. push ( (
809+ format ! ( " {} {}" , "expected with kind" . red( ) , candidate. kind) ,
810+ 0 ,
811+ ) ) ;
805812 } else {
806- println ! ( " {} {}" , "expected on line" . red( ) , line_str( candidate) ) ;
813+ suggestions. push ( (
814+ format ! (
815+ " {} {}" ,
816+ "expected on line" . red( ) ,
817+ line_str( candidate)
818+ ) ,
819+ 0 ,
820+ ) ) ;
807821 }
808822 } else if candidate. line_num . is_some ( )
809823 && candidate. line_num == error. line_num
810824 {
811825 let kind_mismatch = candidate. kind != error. kind ;
812826 if kind_mismatch {
813- println ! (
814- " {} {} {} {}" ,
815- "expected with kind" . red( ) ,
816- candidate. kind,
817- "with message" . red( ) ,
818- candidate. msg. cyan( )
819- ) ;
827+ suggestions. push ( (
828+ format ! (
829+ " {} {} {} {}" ,
830+ "expected with kind" . red( ) ,
831+ candidate. kind,
832+ "with message" . red( ) ,
833+ candidate. msg. cyan( )
834+ ) ,
835+ 1 ,
836+ ) ) ;
820837 } else {
821- println ! (
822- " {} {}" ,
823- "expected with message" . red( ) ,
824- candidate. msg. cyan( )
825- ) ;
838+ suggestions. push ( (
839+ format ! (
840+ " {} {}" ,
841+ "expected with message" . red( ) ,
842+ candidate. msg. cyan( )
843+ ) ,
844+ 1 ,
845+ ) ) ;
846+ }
847+ }
848+ }
849+
850+ suggestions. sort_by_key ( |( _, rank) | * rank) ;
851+ if let Some ( & ( _, top_rank) ) = suggestions. first ( ) {
852+ for ( suggestion, rank) in suggestions {
853+ if rank == top_rank {
854+ println ! ( "{suggestion}" ) ;
826855 }
827856 }
828857 }
@@ -833,20 +862,31 @@ impl<'test> TestCx<'test> {
833862 println ! ( "{}" , "--- expected but not reported (from test file) ---" . red( ) ) ;
834863 for error in & not_found {
835864 print ( error) ;
865+ let mut suggestions = Vec :: new ( ) ;
836866 for candidate in unexpected. iter ( ) . chain ( & unimportant) {
837867 if candidate. msg . contains ( & error. msg ) {
838868 let line_mismatch = candidate. line_num != error. line_num ;
839869 let kind_mismatch = candidate. kind != error. kind ;
840870 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- ) ;
871+ suggestions. push ( (
872+ format ! (
873+ " {} {} {} {}" ,
874+ "reported with kind" . green( ) ,
875+ candidate. kind,
876+ "on line" . green( ) ,
877+ line_str( candidate)
878+ ) ,
879+ 0 ,
880+ ) ) ;
848881 } else if kind_mismatch {
849- println ! ( " {} {}" , "reported with kind" . green( ) , candidate. kind) ;
882+ suggestions. push ( (
883+ format ! (
884+ " {} {}" ,
885+ "reported with kind" . green( ) ,
886+ candidate. kind
887+ ) ,
888+ 0 ,
889+ ) ) ;
850890 } else {
851891 println ! (
852892 " {} {}" ,
@@ -859,19 +899,34 @@ impl<'test> TestCx<'test> {
859899 {
860900 let kind_mismatch = candidate. kind != error. kind ;
861901 if kind_mismatch {
862- println ! (
863- " {} {} {} {}" ,
864- "reported with kind" . green( ) ,
865- candidate. kind,
866- "with message" . green( ) ,
867- candidate. msg. cyan( )
868- ) ;
902+ suggestions. push ( (
903+ format ! (
904+ " {} {} {} {}" ,
905+ "reported with kind" . green( ) ,
906+ candidate. kind,
907+ "with message" . green( ) ,
908+ candidate. msg. cyan( )
909+ ) ,
910+ 1 ,
911+ ) ) ;
869912 } else {
870- println ! (
871- " {} {}" ,
872- "reported with message" . green( ) ,
873- candidate. msg. cyan( )
874- ) ;
913+ suggestions. push ( (
914+ format ! (
915+ " {} {}" ,
916+ "reported with message" . green( ) ,
917+ candidate. msg. cyan( )
918+ ) ,
919+ 1 ,
920+ ) ) ;
921+ }
922+ }
923+ }
924+
925+ suggestions. sort_by_key ( |( _, rank) | * rank) ;
926+ if let Some ( & ( _, top_rank) ) = suggestions. first ( ) {
927+ for ( suggestion, rank) in suggestions {
928+ if rank == top_rank {
929+ println ! ( "{suggestion}" ) ;
875930 }
876931 }
877932 }
0 commit comments