@@ -788,41 +788,70 @@ impl<'test> TestCx<'test> {
788
788
println ! ( "{}" , "--- reported but not expected (from JSON output) ---" . green( ) ) ;
789
789
for error in & unexpected {
790
790
print ( error) ;
791
+ let mut suggestions = Vec :: new ( ) ;
791
792
for candidate in & not_found {
792
793
if error. msg . contains ( & candidate. msg ) {
793
794
let line_mismatch = candidate. line_num != error. line_num ;
794
795
let kind_mismatch = candidate. kind != error. kind ;
795
796
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
+ ) ) ;
803
807
} 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
+ ) ) ;
805
812
} 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
+ ) ) ;
807
821
}
808
822
} else if candidate. line_num . is_some ( )
809
823
&& candidate. line_num == error. line_num
810
824
{
811
825
let kind_mismatch = candidate. kind != error. kind ;
812
826
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
+ ) ) ;
820
837
} 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}" ) ;
826
855
}
827
856
}
828
857
}
@@ -833,20 +862,31 @@ impl<'test> TestCx<'test> {
833
862
println ! ( "{}" , "--- expected but not reported (from test file) ---" . red( ) ) ;
834
863
for error in & not_found {
835
864
print ( error) ;
865
+ let mut suggestions = Vec :: new ( ) ;
836
866
for candidate in unexpected. iter ( ) . chain ( & unimportant) {
837
867
if candidate. msg . contains ( & error. msg ) {
838
868
let line_mismatch = candidate. line_num != error. line_num ;
839
869
let kind_mismatch = candidate. kind != error. kind ;
840
870
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
+ ) ) ;
848
881
} 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
+ ) ) ;
850
890
} else {
851
891
println ! (
852
892
" {} {}" ,
@@ -859,19 +899,34 @@ impl<'test> TestCx<'test> {
859
899
{
860
900
let kind_mismatch = candidate. kind != error. kind ;
861
901
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
+ ) ) ;
869
912
} 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}" ) ;
875
930
}
876
931
}
877
932
}
0 commit comments