@@ -753,29 +753,31 @@ impl<'test> TestCx<'test> {
753
753
}
754
754
755
755
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 `/`.
757
764
let file_name = self
758
765
. testpaths
759
766
. file
760
767
. strip_prefix ( self . config . src_root . as_str ( ) )
761
768
. unwrap_or ( & self . testpaths . file )
762
769
. to_string ( )
763
770
. 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 | {
771
772
let line_num = e. line_num . map_or ( "?" . to_string ( ) , |line_num| line_num. to_string ( ) ) ;
772
773
// `file:?:NUM` may be confusing to editors and unclickable.
773
774
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}" ) ,
775
776
_ => "" . to_string ( ) ,
776
777
} ;
777
- println ! ( "{file_name}:{line_num}: {opt_col_num} {}: {}" , e . kind , e . msg . cyan ( ) )
778
+ format ! ( "{file_name}:{line_num}{opt_col_num}" )
778
779
} ;
780
+ let print = |e : & Error | println ! ( "{}: {}: {}" , line_str( e) , e. kind, e. msg. cyan( ) ) ;
779
781
// Fuzzy matching quality:
780
782
// - message and line / message and kind - great, suggested
781
783
// - only message - good, suggested
@@ -788,19 +790,40 @@ impl<'test> TestCx<'test> {
788
790
print ( error) ;
789
791
for candidate in & not_found {
790
792
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) ;
793
805
} else {
794
- "expected with a different kind"
806
+ println ! ( " {} {}" , "expected on line" . red ( ) , line_str ( candidate ) ) ;
795
807
}
796
- . red ( ) ;
797
- print ! ( " {prefix}: " ) ;
798
- print ( candidate) ;
799
808
} else if candidate. line_num . is_some ( )
800
809
&& candidate. line_num == error. line_num
801
810
{
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
+ }
804
827
}
805
828
}
806
829
}
@@ -812,19 +835,44 @@ impl<'test> TestCx<'test> {
812
835
print ( error) ;
813
836
for candidate in unexpected. iter ( ) . chain ( & unimportant) {
814
837
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) ;
817
850
} else {
818
- "reported with a different kind"
851
+ println ! (
852
+ " {} {}" ,
853
+ "reported on line" . green( ) ,
854
+ line_str( candidate)
855
+ ) ;
819
856
}
820
- . green ( ) ;
821
- print ! ( " {prefix}: " ) ;
822
- print ( candidate) ;
823
857
} else if candidate. line_num . is_some ( )
824
858
&& candidate. line_num == error. line_num
825
859
{
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
+ }
828
876
}
829
877
}
830
878
}
0 commit comments