@@ -4,10 +4,11 @@ use camino::Utf8Path;
44use semver:: Version ;
55
66use super :: {
7- DirectivesCache , EarlyProps , extract_llvm_version , extract_version_range , iter_directives ,
8- parse_normalize_rule,
7+ DirectivesCache , EarlyProps , Edition , EditionRange , extract_llvm_version ,
8+ extract_version_range , iter_directives , parse_normalize_rule,
99} ;
1010use crate :: common:: { Config , Debugger , TestMode } ;
11+ use crate :: directives:: parse_edition;
1112use crate :: executor:: { CollectedTestDesc , ShouldPanic } ;
1213
1314fn make_test_description < R : Read > (
@@ -71,6 +72,7 @@ fn test_parse_normalize_rule() {
7172struct ConfigBuilder {
7273 mode : Option < String > ,
7374 channel : Option < String > ,
75+ edition : Option < Edition > ,
7476 host : Option < String > ,
7577 target : Option < String > ,
7678 stage : Option < u32 > ,
@@ -94,6 +96,11 @@ impl ConfigBuilder {
9496 self
9597 }
9698
99+ fn edition ( & mut self , e : Edition ) -> & mut Self {
100+ self . edition = Some ( e) ;
101+ self
102+ }
103+
97104 fn host ( & mut self , s : & str ) -> & mut Self {
98105 self . host = Some ( s. to_owned ( ) ) ;
99106 self
@@ -181,6 +188,10 @@ impl ConfigBuilder {
181188 ] ;
182189 let mut args: Vec < String > = args. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
183190
191+ if let Some ( edition) = & self . edition {
192+ args. push ( format ! ( "--edition={edition}" ) ) ;
193+ }
194+
184195 if let Some ( ref llvm_version) = self . llvm_version {
185196 args. push ( "--llvm-version" . to_owned ( ) ) ;
186197 args. push ( llvm_version. clone ( ) ) ;
@@ -939,3 +950,128 @@ fn test_needs_target_std() {
939950 let config = cfg ( ) . target ( "x86_64-unknown-linux-gnu" ) . build ( ) ;
940951 assert ! ( !check_ignore( & config, "//@ needs-target-std" ) ) ;
941952}
953+
954+ fn parse_edition_range ( line : & str ) -> Option < EditionRange > {
955+ let config = cfg ( ) . build ( ) ;
956+ super :: parse_edition_range ( & config, line, "tmp.rs" . into ( ) , 0 )
957+ }
958+
959+ #[ test]
960+ fn test_parse_edition_range ( ) {
961+ assert_eq ! ( None , parse_edition_range( "hello-world" ) ) ;
962+ assert_eq ! ( None , parse_edition_range( "edition" ) ) ;
963+
964+ assert_eq ! ( Some ( EditionRange :: Exact ( 2018 . into( ) ) ) , parse_edition_range( "edition: 2018" ) ) ;
965+ assert_eq ! ( Some ( EditionRange :: Exact ( 2021 . into( ) ) ) , parse_edition_range( "edition:2021" ) ) ;
966+ assert_eq ! ( Some ( EditionRange :: Exact ( 2024 . into( ) ) ) , parse_edition_range( "edition: 2024 " ) ) ;
967+ assert_eq ! ( Some ( EditionRange :: Exact ( Edition :: Future ) ) , parse_edition_range( "edition: future" ) ) ;
968+
969+ assert_eq ! ( Some ( EditionRange :: RangeFrom ( 2018 . into( ) ) ) , parse_edition_range( "edition: 2018.." ) ) ;
970+ assert_eq ! ( Some ( EditionRange :: RangeFrom ( 2021 . into( ) ) ) , parse_edition_range( "edition:2021 .." ) ) ;
971+ assert_eq ! (
972+ Some ( EditionRange :: RangeFrom ( 2024 . into( ) ) ) ,
973+ parse_edition_range( "edition: 2024 .. " )
974+ ) ;
975+ assert_eq ! (
976+ Some ( EditionRange :: RangeFrom ( Edition :: Future ) ) ,
977+ parse_edition_range( "edition: future.. " )
978+ ) ;
979+
980+ assert_eq ! (
981+ Some ( EditionRange :: Range { lower_bound: 2018 . into( ) , upper_bound: 2024 . into( ) } ) ,
982+ parse_edition_range( "edition: 2018..2024" )
983+ ) ;
984+ assert_eq ! (
985+ Some ( EditionRange :: Range { lower_bound: 2015 . into( ) , upper_bound: 2021 . into( ) } ) ,
986+ parse_edition_range( "edition:2015 .. 2021 " )
987+ ) ;
988+ assert_eq ! (
989+ Some ( EditionRange :: Range { lower_bound: 2021 . into( ) , upper_bound: 2027 . into( ) } ) ,
990+ parse_edition_range( "edition: 2021 .. 2027 " )
991+ ) ;
992+ assert_eq ! (
993+ Some ( EditionRange :: Range { lower_bound: 2021 . into( ) , upper_bound: Edition :: Future } ) ,
994+ parse_edition_range( "edition: 2021..future" )
995+ ) ;
996+ }
997+
998+ #[ test]
999+ #[ should_panic]
1000+ fn test_parse_edition_range_empty ( ) {
1001+ parse_edition_range ( "edition:" ) ;
1002+ }
1003+
1004+ #[ test]
1005+ #[ should_panic]
1006+ fn test_parse_edition_range_invalid_edition ( ) {
1007+ parse_edition_range ( "edition: hello" ) ;
1008+ }
1009+
1010+ #[ test]
1011+ #[ should_panic]
1012+ fn test_parse_edition_range_double_dots ( ) {
1013+ parse_edition_range ( "edition: .." ) ;
1014+ }
1015+
1016+ #[ test]
1017+ #[ should_panic]
1018+ fn test_parse_edition_range_inverted_range ( ) {
1019+ parse_edition_range ( "edition: 2021..2015" ) ;
1020+ }
1021+
1022+ #[ test]
1023+ #[ should_panic]
1024+ fn test_parse_edition_range_inverted_range_future ( ) {
1025+ parse_edition_range ( "edition: future..2015" ) ;
1026+ }
1027+
1028+ #[ test]
1029+ #[ should_panic]
1030+ fn test_parse_edition_range_empty_range ( ) {
1031+ parse_edition_range ( "edition: 2021..2021" ) ;
1032+ }
1033+
1034+ #[ track_caller]
1035+ fn assert_edition_to_test (
1036+ expected : impl Into < Edition > ,
1037+ range : EditionRange ,
1038+ default : Option < Edition > ,
1039+ ) {
1040+ let mut cfg = cfg ( ) ;
1041+ if let Some ( default) = default {
1042+ cfg. edition ( default) ;
1043+ }
1044+ assert_eq ! ( expected. into( ) , range. edition_to_test( cfg. build( ) . edition) ) ;
1045+ }
1046+
1047+ #[ test]
1048+ fn test_edition_range_edition_to_test ( ) {
1049+ let e2015 = parse_edition ( "2015" ) ;
1050+ let e2018 = parse_edition ( "2018" ) ;
1051+ let e2021 = parse_edition ( "2021" ) ;
1052+ let e2024 = parse_edition ( "2024" ) ;
1053+ let efuture = parse_edition ( "future" ) ;
1054+
1055+ let exact = EditionRange :: Exact ( 2021 . into ( ) ) ;
1056+ assert_edition_to_test ( 2021 , exact, None ) ;
1057+ assert_edition_to_test ( 2021 , exact, Some ( e2018) ) ;
1058+ assert_edition_to_test ( 2021 , exact, Some ( efuture) ) ;
1059+
1060+ assert_edition_to_test ( Edition :: Future , EditionRange :: Exact ( Edition :: Future ) , None ) ;
1061+
1062+ let greater_equal_than = EditionRange :: RangeFrom ( 2021 . into ( ) ) ;
1063+ assert_edition_to_test ( 2021 , greater_equal_than, None ) ;
1064+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( e2015) ) ;
1065+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( e2018) ) ;
1066+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( e2021) ) ;
1067+ assert_edition_to_test ( 2024 , greater_equal_than, Some ( e2024) ) ;
1068+ assert_edition_to_test ( Edition :: Future , greater_equal_than, Some ( efuture) ) ;
1069+
1070+ let range = EditionRange :: Range { lower_bound : 2018 . into ( ) , upper_bound : 2024 . into ( ) } ;
1071+ assert_edition_to_test ( 2018 , range, None ) ;
1072+ assert_edition_to_test ( 2018 , range, Some ( e2015) ) ;
1073+ assert_edition_to_test ( 2018 , range, Some ( e2018) ) ;
1074+ assert_edition_to_test ( 2021 , range, Some ( e2021) ) ;
1075+ assert_edition_to_test ( 2018 , range, Some ( e2024) ) ;
1076+ assert_edition_to_test ( 2018 , range, Some ( efuture) ) ;
1077+ }
0 commit comments