@@ -4,8 +4,8 @@ use camino::Utf8Path;
4
4
use semver:: Version ;
5
5
6
6
use 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,
9
9
} ;
10
10
use crate :: common:: { Config , Debugger , TestMode } ;
11
11
use crate :: executor:: { CollectedTestDesc , ShouldPanic } ;
@@ -71,6 +71,7 @@ fn test_parse_normalize_rule() {
71
71
struct ConfigBuilder {
72
72
mode : Option < String > ,
73
73
channel : Option < String > ,
74
+ edition : Option < String > ,
74
75
host : Option < String > ,
75
76
target : Option < String > ,
76
77
stage : Option < u32 > ,
@@ -94,6 +95,11 @@ impl ConfigBuilder {
94
95
self
95
96
}
96
97
98
+ fn edition ( & mut self , s : & str ) -> & mut Self {
99
+ self . edition = Some ( s. to_owned ( ) ) ;
100
+ self
101
+ }
102
+
97
103
fn host ( & mut self , s : & str ) -> & mut Self {
98
104
self . host = Some ( s. to_owned ( ) ) ;
99
105
self
@@ -181,6 +187,10 @@ impl ConfigBuilder {
181
187
] ;
182
188
let mut args: Vec < String > = args. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
183
189
190
+ if let Some ( edition) = & self . edition {
191
+ args. push ( format ! ( "--edition={edition}" ) ) ;
192
+ }
193
+
184
194
if let Some ( ref llvm_version) = self . llvm_version {
185
195
args. push ( "--llvm-version" . to_owned ( ) ) ;
186
196
args. push ( llvm_version. clone ( ) ) ;
@@ -939,3 +949,160 @@ fn test_needs_target_std() {
939
949
let config = cfg ( ) . target ( "x86_64-unknown-linux-gnu" ) . build ( ) ;
940
950
assert ! ( !check_ignore( & config, "//@ needs-target-std" ) ) ;
941
951
}
952
+
953
+ fn y ( year : u32 ) -> Edition {
954
+ Edition :: Year ( year)
955
+ }
956
+
957
+ fn parse_edition_range ( line : & str ) -> Option < EditionRange > {
958
+ let config = cfg ( ) . build ( ) ;
959
+ super :: parse_edition_range ( & config, line)
960
+ }
961
+
962
+ #[ test]
963
+ fn test_parse_edition_range ( ) {
964
+ assert_eq ! ( None , parse_edition_range( "hello-world" ) ) ;
965
+ assert_eq ! ( None , parse_edition_range( "edition" ) ) ;
966
+
967
+ assert_eq ! ( Some ( EditionRange :: Exact ( y( 2018 ) ) ) , parse_edition_range( "edition: 2018" ) ) ;
968
+ assert_eq ! ( Some ( EditionRange :: Exact ( y( 2021 ) ) ) , parse_edition_range( "edition:2021" ) ) ;
969
+ assert_eq ! ( Some ( EditionRange :: Exact ( y( 2024 ) ) ) , parse_edition_range( "edition: 2024 " ) ) ;
970
+ assert_eq ! ( Some ( EditionRange :: Exact ( Edition :: Future ) ) , parse_edition_range( "edition: future" ) ) ;
971
+
972
+ assert_eq ! ( Some ( EditionRange :: LowerThan ( y( 2018 ) ) ) , parse_edition_range( "edition: ..2018" ) ) ;
973
+ assert_eq ! ( Some ( EditionRange :: LowerThan ( y( 2021 ) ) ) , parse_edition_range( "edition:.. 2021" ) ) ;
974
+ assert_eq ! ( Some ( EditionRange :: LowerThan ( y( 2024 ) ) ) , parse_edition_range( "edition: .. 2024 " ) ) ;
975
+ assert_eq ! (
976
+ Some ( EditionRange :: LowerThan ( Edition :: Future ) ) ,
977
+ parse_edition_range( "edition: ..future" )
978
+ ) ;
979
+
980
+ assert_eq ! (
981
+ Some ( EditionRange :: GreaterEqualThan ( y( 2018 ) ) ) ,
982
+ parse_edition_range( "edition: 2018.." )
983
+ ) ;
984
+ assert_eq ! (
985
+ Some ( EditionRange :: GreaterEqualThan ( y( 2021 ) ) ) ,
986
+ parse_edition_range( "edition:2021 .." )
987
+ ) ;
988
+ assert_eq ! (
989
+ Some ( EditionRange :: GreaterEqualThan ( y( 2024 ) ) ) ,
990
+ parse_edition_range( "edition: 2024 .. " )
991
+ ) ;
992
+ assert_eq ! (
993
+ Some ( EditionRange :: GreaterEqualThan ( Edition :: Future ) ) ,
994
+ parse_edition_range( "edition: future.. " )
995
+ ) ;
996
+
997
+ assert_eq ! (
998
+ Some ( EditionRange :: Range { greater_equal_than: y( 2018 ) , lower_than: y( 2024 ) } ) ,
999
+ parse_edition_range( "edition: 2018..2024" )
1000
+ ) ;
1001
+ assert_eq ! (
1002
+ Some ( EditionRange :: Range { greater_equal_than: y( 2015 ) , lower_than: y( 2021 ) } ) ,
1003
+ parse_edition_range( "edition:2015 .. 2021 " )
1004
+ ) ;
1005
+ assert_eq ! (
1006
+ Some ( EditionRange :: Range { greater_equal_than: y( 2021 ) , lower_than: y( 2027 ) } ) ,
1007
+ parse_edition_range( "edition: 2021 .. 2027 " )
1008
+ ) ;
1009
+ assert_eq ! (
1010
+ Some ( EditionRange :: Range { greater_equal_than: y( 2021 ) , lower_than: Edition :: Future } ) ,
1011
+ parse_edition_range( "edition: 2021..future" )
1012
+ ) ;
1013
+ }
1014
+
1015
+ #[ test]
1016
+ #[ should_panic = "empty value for //@ edition" ]
1017
+ fn test_parse_edition_range_empty ( ) {
1018
+ parse_edition_range ( "edition:" ) ;
1019
+ }
1020
+
1021
+ #[ test]
1022
+ #[ should_panic = "'hello' doesn't look like an edition" ]
1023
+ fn test_parse_edition_range_invalid_edition ( ) {
1024
+ parse_edition_range ( "edition: hello" ) ;
1025
+ }
1026
+
1027
+ #[ test]
1028
+ #[ should_panic = "'..' is not a supported range in //@ edition" ]
1029
+ fn test_parse_edition_range_double_dots ( ) {
1030
+ parse_edition_range ( "edition: .." ) ;
1031
+ }
1032
+
1033
+ #[ test]
1034
+ #[ should_panic = "the left side of `//@ edition` cannot be higher than the right side" ]
1035
+ fn test_parse_edition_range_inverted_range ( ) {
1036
+ parse_edition_range ( "edition: 2021..2015" ) ;
1037
+ }
1038
+
1039
+ #[ test]
1040
+ #[ should_panic = "the left side of `//@ edition` cannot be higher than the right side" ]
1041
+ fn test_parse_edition_range_inverted_range_future ( ) {
1042
+ parse_edition_range ( "edition: future..2015" ) ;
1043
+ }
1044
+
1045
+ #[ test]
1046
+ #[ should_panic = "the left side of `//@ edition` cannot be equal to the right side" ]
1047
+ fn test_parse_edition_range_empty_range ( ) {
1048
+ parse_edition_range ( "edition: 2021..2021" ) ;
1049
+ }
1050
+
1051
+ #[ track_caller]
1052
+ fn assert_edition_to_test (
1053
+ expected : impl Into < Edition > ,
1054
+ range : EditionRange ,
1055
+ default : Option < & str > ,
1056
+ ) {
1057
+ let mut cfg = cfg ( ) ;
1058
+ if let Some ( default) = default {
1059
+ cfg. edition ( default) ;
1060
+ }
1061
+ assert_eq ! ( expected. into( ) , range. edition_to_test( & cfg. build( ) ) ) ;
1062
+ }
1063
+
1064
+ #[ test]
1065
+ fn test_edition_range_edition_to_test ( ) {
1066
+ let exact = EditionRange :: Exact ( y ( 2021 ) ) ;
1067
+ assert_edition_to_test ( 2021 , exact, None ) ;
1068
+ assert_edition_to_test ( 2021 , exact, Some ( "2018" ) ) ;
1069
+ assert_edition_to_test ( 2021 , exact, Some ( "future" ) ) ;
1070
+
1071
+ assert_edition_to_test ( Edition :: Future , EditionRange :: Exact ( Edition :: Future ) , None ) ;
1072
+
1073
+ let greater_equal_than = EditionRange :: GreaterEqualThan ( y ( 2021 ) ) ;
1074
+ assert_edition_to_test ( 2021 , greater_equal_than, None ) ;
1075
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( "2015" ) ) ;
1076
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( "2018" ) ) ;
1077
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( "2021" ) ) ;
1078
+ assert_edition_to_test ( 2024 , greater_equal_than, Some ( "2024" ) ) ;
1079
+ assert_edition_to_test ( Edition :: Future , greater_equal_than, Some ( "future" ) ) ;
1080
+
1081
+ let lower_than = EditionRange :: LowerThan ( y ( 2021 ) ) ;
1082
+ assert_edition_to_test ( 2015 , lower_than, None ) ;
1083
+ assert_edition_to_test ( 2015 , lower_than, Some ( "2015" ) ) ;
1084
+ assert_edition_to_test ( 2018 , lower_than, Some ( "2018" ) ) ;
1085
+ assert_edition_to_test ( 2015 , lower_than, Some ( "2021" ) ) ;
1086
+ assert_edition_to_test ( 2015 , lower_than, Some ( "2024" ) ) ;
1087
+ assert_edition_to_test ( 2015 , lower_than, Some ( "future" ) ) ;
1088
+
1089
+ let range = EditionRange :: Range { greater_equal_than : y ( 2018 ) , lower_than : y ( 2024 ) } ;
1090
+ assert_edition_to_test ( 2018 , range, None ) ;
1091
+ assert_edition_to_test ( 2018 , range, Some ( "2015" ) ) ;
1092
+ assert_edition_to_test ( 2018 , range, Some ( "2018" ) ) ;
1093
+ assert_edition_to_test ( 2021 , range, Some ( "2021" ) ) ;
1094
+ assert_edition_to_test ( 2018 , range, Some ( "2024" ) ) ;
1095
+ assert_edition_to_test ( 2018 , range, Some ( "future" ) ) ;
1096
+ }
1097
+
1098
+ #[ test]
1099
+ #[ should_panic = "'not an edition' doesn't look like an edition" ]
1100
+ fn test_edition_range_edition_to_test_bad_cli ( ) {
1101
+ assert_edition_to_test ( 2021 , EditionRange :: Exact ( y ( 2021 ) ) , Some ( "not an edition" ) ) ;
1102
+ }
1103
+
1104
+ #[ test]
1105
+ #[ should_panic = "editions lower than 2015 are not supported" ]
1106
+ fn test_edition_range_too_low ( ) {
1107
+ assert_edition_to_test ( 2015 , EditionRange :: LowerThan ( y ( 2012 ) ) , None ) ;
1108
+ }
0 commit comments