@@ -878,7 +878,9 @@ pub fn unused_dependencies(
878
878
879
879
#[ cfg( test) ]
880
880
mod tests {
881
+ use itertools:: Itertools ;
881
882
use snapbox:: ToDebug ;
883
+ use std:: collections:: HashSet ;
882
884
883
885
#[ test]
884
886
fn ensure_sorted_lints ( ) {
@@ -913,4 +915,82 @@ mod tests {
913
915
expected. sort ( ) ;
914
916
snapbox:: assert_data_eq!( actual. to_debug( ) , expected. to_debug( ) ) ;
915
917
}
918
+
919
+ #[ test]
920
+ fn ensure_updated_lints ( ) {
921
+ let path = snapbox:: utils:: current_rs!( ) ;
922
+ let expected = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
923
+ let expected = expected
924
+ . lines ( )
925
+ . filter_map ( |l| {
926
+ if l. ends_with ( ": Lint = Lint {" ) {
927
+ Some (
928
+ l. chars ( )
929
+ . skip ( 6 )
930
+ . take_while ( |c| * c != ':' )
931
+ . collect :: < String > ( ) ,
932
+ )
933
+ } else {
934
+ None
935
+ }
936
+ } )
937
+ . collect :: < HashSet < _ > > ( ) ;
938
+ let actual = super :: LINTS
939
+ . iter ( )
940
+ . map ( |l| l. name . to_uppercase ( ) )
941
+ . collect :: < HashSet < _ > > ( ) ;
942
+ let diff = expected. difference ( & actual) . sorted ( ) . collect :: < Vec < _ > > ( ) ;
943
+
944
+ let mut need_added = String :: new ( ) ;
945
+ for name in & diff {
946
+ need_added. push_str ( & format ! ( "{}\n " , name) ) ;
947
+ }
948
+ assert ! (
949
+ diff. is_empty( ) ,
950
+ "\n `LINTS` did not contain all `Lint`s found in {}\n \
951
+ Please add the following to `LINTS`:\n \
952
+ {}",
953
+ path. display( ) ,
954
+ need_added
955
+ ) ;
956
+ }
957
+
958
+ #[ test]
959
+ fn ensure_updated_lint_groups ( ) {
960
+ let path = snapbox:: utils:: current_rs!( ) ;
961
+ let expected = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
962
+ let expected = expected
963
+ . lines ( )
964
+ . filter_map ( |l| {
965
+ if l. ends_with ( ": LintGroup = LintGroup {" ) {
966
+ Some (
967
+ l. chars ( )
968
+ . skip ( 6 )
969
+ . take_while ( |c| * c != ':' )
970
+ . collect :: < String > ( ) ,
971
+ )
972
+ } else {
973
+ None
974
+ }
975
+ } )
976
+ . collect :: < HashSet < _ > > ( ) ;
977
+ let actual = super :: LINT_GROUPS
978
+ . iter ( )
979
+ . map ( |l| l. name . to_uppercase ( ) )
980
+ . collect :: < HashSet < _ > > ( ) ;
981
+ let diff = expected. difference ( & actual) . sorted ( ) . collect :: < Vec < _ > > ( ) ;
982
+
983
+ let mut need_added = String :: new ( ) ;
984
+ for name in & diff {
985
+ need_added. push_str ( & format ! ( "{}\n " , name) ) ;
986
+ }
987
+ assert ! (
988
+ diff. is_empty( ) ,
989
+ "\n `LINT_GROUPS` did not contain all `LintGroup`s found in {}\n \
990
+ Please add the following to `LINT_GROUPS`:\n \
991
+ {}",
992
+ path. display( ) ,
993
+ need_added
994
+ ) ;
995
+ }
916
996
}
0 commit comments