@@ -4,10 +4,11 @@ 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
+ use crate :: directives:: parse_edition;
11
12
use crate :: executor:: { CollectedTestDesc , ShouldPanic } ;
12
13
13
14
fn make_test_description < R : Read > (
@@ -73,6 +74,7 @@ fn test_parse_normalize_rule() {
73
74
struct ConfigBuilder {
74
75
mode : Option < String > ,
75
76
channel : Option < String > ,
77
+ edition : Option < Edition > ,
76
78
host : Option < String > ,
77
79
target : Option < String > ,
78
80
stage : Option < u32 > ,
@@ -96,6 +98,11 @@ impl ConfigBuilder {
96
98
self
97
99
}
98
100
101
+ fn edition ( & mut self , e : Edition ) -> & mut Self {
102
+ self . edition = Some ( e) ;
103
+ self
104
+ }
105
+
99
106
fn host ( & mut self , s : & str ) -> & mut Self {
100
107
self . host = Some ( s. to_owned ( ) ) ;
101
108
self
@@ -183,6 +190,10 @@ impl ConfigBuilder {
183
190
] ;
184
191
let mut args: Vec < String > = args. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
185
192
193
+ if let Some ( edition) = & self . edition {
194
+ args. push ( format ! ( "--edition={edition}" ) ) ;
195
+ }
196
+
186
197
if let Some ( ref llvm_version) = self . llvm_version {
187
198
args. push ( "--llvm-version" . to_owned ( ) ) ;
188
199
args. push ( llvm_version. clone ( ) ) ;
@@ -941,3 +952,130 @@ fn test_needs_target_std() {
941
952
let config = cfg ( ) . target ( "x86_64-unknown-linux-gnu" ) . build ( ) ;
942
953
assert ! ( !check_ignore( & config, "//@ needs-target-std" ) ) ;
943
954
}
955
+
956
+ fn parse_edition_range ( line : & str ) -> Option < EditionRange > {
957
+ let config = cfg ( ) . build ( ) ;
958
+ let line = super :: DirectiveLine { line_number : 0 , revision : None , raw_directive : line } ;
959
+
960
+ super :: parse_edition_range ( & config, & line, "tmp.rs" . into ( ) )
961
+ }
962
+
963
+ #[ test]
964
+ fn test_parse_edition_range ( ) {
965
+ assert_eq ! ( None , parse_edition_range( "hello-world" ) ) ;
966
+ assert_eq ! ( None , parse_edition_range( "edition" ) ) ;
967
+
968
+ assert_eq ! ( Some ( EditionRange :: Exact ( 2018 . into( ) ) ) , parse_edition_range( "edition: 2018" ) ) ;
969
+ assert_eq ! ( Some ( EditionRange :: Exact ( 2021 . into( ) ) ) , parse_edition_range( "edition:2021" ) ) ;
970
+ assert_eq ! ( Some ( EditionRange :: Exact ( 2024 . into( ) ) ) , parse_edition_range( "edition: 2024 " ) ) ;
971
+ assert_eq ! ( Some ( EditionRange :: Exact ( Edition :: Future ) ) , parse_edition_range( "edition: future" ) ) ;
972
+
973
+ assert_eq ! ( Some ( EditionRange :: RangeFrom ( 2018 . into( ) ) ) , parse_edition_range( "edition: 2018.." ) ) ;
974
+ assert_eq ! ( Some ( EditionRange :: RangeFrom ( 2021 . into( ) ) ) , parse_edition_range( "edition:2021 .." ) ) ;
975
+ assert_eq ! (
976
+ Some ( EditionRange :: RangeFrom ( 2024 . into( ) ) ) ,
977
+ parse_edition_range( "edition: 2024 .. " )
978
+ ) ;
979
+ assert_eq ! (
980
+ Some ( EditionRange :: RangeFrom ( Edition :: Future ) ) ,
981
+ parse_edition_range( "edition: future.. " )
982
+ ) ;
983
+
984
+ assert_eq ! (
985
+ Some ( EditionRange :: Range { lower_bound: 2018 . into( ) , upper_bound: 2024 . into( ) } ) ,
986
+ parse_edition_range( "edition: 2018..2024" )
987
+ ) ;
988
+ assert_eq ! (
989
+ Some ( EditionRange :: Range { lower_bound: 2015 . into( ) , upper_bound: 2021 . into( ) } ) ,
990
+ parse_edition_range( "edition:2015 .. 2021 " )
991
+ ) ;
992
+ assert_eq ! (
993
+ Some ( EditionRange :: Range { lower_bound: 2021 . into( ) , upper_bound: 2027 . into( ) } ) ,
994
+ parse_edition_range( "edition: 2021 .. 2027 " )
995
+ ) ;
996
+ assert_eq ! (
997
+ Some ( EditionRange :: Range { lower_bound: 2021 . into( ) , upper_bound: Edition :: Future } ) ,
998
+ parse_edition_range( "edition: 2021..future" )
999
+ ) ;
1000
+ }
1001
+
1002
+ #[ test]
1003
+ #[ should_panic]
1004
+ fn test_parse_edition_range_empty ( ) {
1005
+ parse_edition_range ( "edition:" ) ;
1006
+ }
1007
+
1008
+ #[ test]
1009
+ #[ should_panic]
1010
+ fn test_parse_edition_range_invalid_edition ( ) {
1011
+ parse_edition_range ( "edition: hello" ) ;
1012
+ }
1013
+
1014
+ #[ test]
1015
+ #[ should_panic]
1016
+ fn test_parse_edition_range_double_dots ( ) {
1017
+ parse_edition_range ( "edition: .." ) ;
1018
+ }
1019
+
1020
+ #[ test]
1021
+ #[ should_panic]
1022
+ fn test_parse_edition_range_inverted_range ( ) {
1023
+ parse_edition_range ( "edition: 2021..2015" ) ;
1024
+ }
1025
+
1026
+ #[ test]
1027
+ #[ should_panic]
1028
+ fn test_parse_edition_range_inverted_range_future ( ) {
1029
+ parse_edition_range ( "edition: future..2015" ) ;
1030
+ }
1031
+
1032
+ #[ test]
1033
+ #[ should_panic]
1034
+ fn test_parse_edition_range_empty_range ( ) {
1035
+ parse_edition_range ( "edition: 2021..2021" ) ;
1036
+ }
1037
+
1038
+ #[ track_caller]
1039
+ fn assert_edition_to_test (
1040
+ expected : impl Into < Edition > ,
1041
+ range : EditionRange ,
1042
+ default : Option < Edition > ,
1043
+ ) {
1044
+ let mut cfg = cfg ( ) ;
1045
+ if let Some ( default) = default {
1046
+ cfg. edition ( default) ;
1047
+ }
1048
+ assert_eq ! ( expected. into( ) , range. edition_to_test( cfg. build( ) . edition) ) ;
1049
+ }
1050
+
1051
+ #[ test]
1052
+ fn test_edition_range_edition_to_test ( ) {
1053
+ let e2015 = parse_edition ( "2015" ) ;
1054
+ let e2018 = parse_edition ( "2018" ) ;
1055
+ let e2021 = parse_edition ( "2021" ) ;
1056
+ let e2024 = parse_edition ( "2024" ) ;
1057
+ let efuture = parse_edition ( "future" ) ;
1058
+
1059
+ let exact = EditionRange :: Exact ( 2021 . into ( ) ) ;
1060
+ assert_edition_to_test ( 2021 , exact, None ) ;
1061
+ assert_edition_to_test ( 2021 , exact, Some ( e2018) ) ;
1062
+ assert_edition_to_test ( 2021 , exact, Some ( efuture) ) ;
1063
+
1064
+ assert_edition_to_test ( Edition :: Future , EditionRange :: Exact ( Edition :: Future ) , None ) ;
1065
+
1066
+ let greater_equal_than = EditionRange :: RangeFrom ( 2021 . into ( ) ) ;
1067
+ assert_edition_to_test ( 2021 , greater_equal_than, None ) ;
1068
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( e2015) ) ;
1069
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( e2018) ) ;
1070
+ assert_edition_to_test ( 2021 , greater_equal_than, Some ( e2021) ) ;
1071
+ assert_edition_to_test ( 2024 , greater_equal_than, Some ( e2024) ) ;
1072
+ assert_edition_to_test ( Edition :: Future , greater_equal_than, Some ( efuture) ) ;
1073
+
1074
+ let range = EditionRange :: Range { lower_bound : 2018 . into ( ) , upper_bound : 2024 . into ( ) } ;
1075
+ assert_edition_to_test ( 2018 , range, None ) ;
1076
+ assert_edition_to_test ( 2018 , range, Some ( e2015) ) ;
1077
+ assert_edition_to_test ( 2018 , range, Some ( e2018) ) ;
1078
+ assert_edition_to_test ( 2021 , range, Some ( e2021) ) ;
1079
+ assert_edition_to_test ( 2018 , range, Some ( e2024) ) ;
1080
+ assert_edition_to_test ( 2018 , range, Some ( efuture) ) ;
1081
+ }
0 commit comments