@@ -14,8 +14,8 @@ use toml_edit::ImDocument;
14
14
15
15
const LINT_GROUPS : & [ LintGroup ] = & [ TEST_DUMMY_UNSTABLE ] ;
16
16
pub const LINTS : & [ Lint ] = & [
17
- IM_A_TEAPOT ,
18
17
IMPLICIT_FEATURES ,
18
+ IM_A_TEAPOT ,
19
19
UNKNOWN_LINTS ,
20
20
UNUSED_OPTIONAL_DEPENDENCY ,
21
21
] ;
@@ -875,3 +875,122 @@ pub fn unused_dependencies(
875
875
}
876
876
Ok ( ( ) )
877
877
}
878
+
879
+ #[ cfg( test) ]
880
+ mod tests {
881
+ use itertools:: Itertools ;
882
+ use snapbox:: ToDebug ;
883
+ use std:: collections:: HashSet ;
884
+
885
+ #[ test]
886
+ fn ensure_sorted_lints ( ) {
887
+ // This will be printed out if the fields are not sorted.
888
+ let location = std:: panic:: Location :: caller ( ) ;
889
+ println ! ( "\n To fix this test, sort `LINTS` in {}\n " , location. file( ) , ) ;
890
+
891
+ let actual = super :: LINTS
892
+ . iter ( )
893
+ . map ( |l| l. name . to_uppercase ( ) )
894
+ . collect :: < Vec < _ > > ( ) ;
895
+
896
+ let mut expected = actual. clone ( ) ;
897
+ expected. sort ( ) ;
898
+ snapbox:: assert_data_eq!( actual. to_debug( ) , expected. to_debug( ) ) ;
899
+ }
900
+
901
+ #[ test]
902
+ fn ensure_sorted_lint_groups ( ) {
903
+ // This will be printed out if the fields are not sorted.
904
+ let location = std:: panic:: Location :: caller ( ) ;
905
+ println ! (
906
+ "\n To fix this test, sort `LINT_GROUPS` in {}\n " ,
907
+ location. file( ) ,
908
+ ) ;
909
+ let actual = super :: LINT_GROUPS
910
+ . iter ( )
911
+ . map ( |l| l. name . to_uppercase ( ) )
912
+ . collect :: < Vec < _ > > ( ) ;
913
+
914
+ let mut expected = actual. clone ( ) ;
915
+ expected. sort ( ) ;
916
+ snapbox:: assert_data_eq!( actual. to_debug( ) , expected. to_debug( ) ) ;
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
+ }
996
+ }
0 commit comments