@@ -11,110 +11,119 @@ import sys
11
11
# Tests that check for the behaviour of experimental/upcoming features, so
12
12
# they cannot automatically be checked.
13
13
EXCEPTIONAL_FILES = [
14
- pathlib .Path ("test/Frontend/experimental-features-no-asserts.swift" ),
15
- pathlib .Path ("test/Frontend/upcoming_feature.swift" ),
14
+ pathlib .Path ("test/Frontend/experimental-features-no-asserts.swift" ),
15
+ pathlib .Path ("test/Frontend/upcoming_feature.swift" ),
16
16
]
17
17
18
- FEATURE_USAGE_RE = re .compile (r"-enable-(?:experimental|upcoming)-feature (?:-Xfrontend )?([A-Za-z0-9]*)" )
18
+ FEATURE_USAGE_RE = re .compile (
19
+ r"-enable-(?:experimental|upcoming)-feature (?:-Xfrontend )?([A-Za-z0-9]*)"
20
+ )
19
21
20
22
21
23
def find_test_files_with_features_usage (swift_src_root ):
22
- # Look for every test file in the test directories with `RUN` lines that
23
- # mention `-enable-experimental-feature` or `-enable-upcoming-feature`.
24
- # Be careful of not using REQUIRES or RUN with a colon after them or Lit will
25
- # pick them up.
26
- output = subprocess .check_output ([
27
- "grep" ,
28
- "--extended-regexp" ,
29
- "--recursive" ,
30
- "-e" ,
31
- "RUN[:].*-enable-(experimental|upcoming)-feature" ,
32
- "--files-with-matches" ,
33
- str (swift_src_root / "test" ),
34
- str (swift_src_root / "validation-test" ),
35
- ], text = True )
36
- return output .splitlines ()
24
+ # Look for every test file in the test directories with `RUN` lines that
25
+ # mention `-enable-experimental-feature` or `-enable-upcoming-feature`.
26
+ # Be careful of not using REQUIRES or RUN with a colon after them or Lit will
27
+ # pick them up.
28
+ output = subprocess .check_output ([
29
+ "grep" ,
30
+ "--extended-regexp" ,
31
+ "--recursive" ,
32
+ "-e" ,
33
+ "RUN[:].*-enable-(experimental|upcoming)-feature" ,
34
+ "--files-with-matches" ,
35
+ str (swift_src_root / "test" ),
36
+ str (swift_src_root / "validation-test" ),
37
+ ], text = True )
38
+ return output .splitlines ()
37
39
38
40
39
41
def find_run_lines (test_file ):
40
- output = subprocess .check_output ([
41
- "grep" ,
42
- "--extended-regexp" ,
43
- "--no-filename" ,
44
- "-e" ,
45
- "RUN[:]" ,
46
- str (test_file ),
47
- ], text = True )
48
- return output .splitlines ()
42
+ output = subprocess .check_output ([
43
+ "grep" ,
44
+ "--extended-regexp" ,
45
+ "--no-filename" ,
46
+ "-e" ,
47
+ "RUN[:]" ,
48
+ str (test_file ),
49
+ ], text = True )
50
+ return output .splitlines ()
49
51
50
52
51
53
def check_existing_requires (test_file , feature ):
52
- returncode = subprocess .call ([
53
- "grep" ,
54
- "--extended-regexp" ,
55
- "--quiet" ,
56
- "-e" ,
57
- "REQUIRES[:].*swift_feature_" + feature ,
58
- str (test_file ),
59
- ])
60
- return returncode != 0
54
+ returncode = subprocess .call ([
55
+ "grep" ,
56
+ "--extended-regexp" ,
57
+ "--quiet" ,
58
+ "-e" ,
59
+ "REQUIRES[:].*swift_feature_" + feature ,
60
+ str (test_file ),
61
+ ])
62
+ return returncode != 0
61
63
62
64
63
65
def check_existing_error_message_checks (test_file , feature ):
64
- returncode = subprocess .call ([
65
- "grep" ,
66
- "--extended-regexp" ,
67
- "--quiet" ,
68
- "-e" ,
69
- "requires '-enable-(experimental|upcoming)-feature " + feature + "'" ,
70
- str (test_file ),
71
- ])
72
- return returncode != 0
66
+ returncode = subprocess .call ([
67
+ "grep" ,
68
+ "--extended-regexp" ,
69
+ "--quiet" ,
70
+ "-e" ,
71
+ "requires '-enable-(experimental|upcoming)-feature " + feature + "'" ,
72
+ str (test_file ),
73
+ ])
74
+ return returncode != 0
73
75
74
76
75
77
def check_test_file_feature_usage (test_file ):
76
- run_lines = find_run_lines (test_file )
77
- features = set (
78
- feature
79
- for line in run_lines
80
- for feature in FEATURE_USAGE_RE .findall (line )
81
- )
82
- num_failures = 0
83
- for feature in features :
84
- # No warning if the necessary `REQUIRES` is already there
85
- if not check_existing_requires (test_file , feature ):
86
- continue
87
-
88
- # Some tests check for the errors themselves, so we can skip them as well
89
- if not check_existing_error_message_checks (test_file , feature ):
90
- continue
91
-
92
- # For everything else, print a warning and for an invalid exit code
93
- print ("error: {}: Missing '{}: swift_feature_{}'" .format (str (test_file ), "REQUIRES" , feature ))
94
- num_failures += 1
95
- return num_failures == 0
78
+ run_lines = find_run_lines (test_file )
79
+ features = set (
80
+ feature
81
+ for line in run_lines
82
+ for feature in FEATURE_USAGE_RE .findall (line )
83
+ )
84
+ num_failures = 0
85
+ for feature in features :
86
+ # No warning if the necessary `REQUIRES` is already there
87
+ if not check_existing_requires (test_file , feature ):
88
+ continue
89
+
90
+ # Some tests check for the errors themselves, so we can skip them as well
91
+ if not check_existing_error_message_checks (test_file , feature ):
92
+ continue
93
+
94
+ # For everything else, print a warning and add to the invalid exit code
95
+ print (
96
+ "error: {}: Missing '{}: swift_feature_{}'" .format (
97
+ str (test_file ),
98
+ "REQUIRES" ,
99
+ feature
100
+ )
101
+ )
102
+ num_failures += 1
103
+ return num_failures == 0
96
104
97
105
98
106
def main ():
99
- if len (sys .argv ) < 2 :
100
- print ('Invalid number of arguments.' )
101
- sys .exit (1 )
107
+ if len (sys .argv ) < 2 :
108
+ print ('Invalid number of arguments.' )
109
+ sys .exit (1 )
102
110
103
- swift_src_root = pathlib .Path (sys .argv [1 ])
111
+ swift_src_root = pathlib .Path (sys .argv [1 ])
104
112
105
- num_failures = 0
106
- test_files_with_features_usage = find_test_files_with_features_usage (swift_src_root )
107
- for test_file in test_files_with_features_usage :
108
- test_file = pathlib .Path (test_file )
109
- # First lets check this is not one of the exceptional files
110
- if test_file .relative_to (swift_src_root ) in EXCEPTIONAL_FILES :
111
- continue
113
+ num_failures = 0
114
+ test_files_with_features_usage = find_test_files_with_features_usage (swift_src_root )
115
+ for test_file in test_files_with_features_usage :
116
+ test_file = pathlib .Path (test_file )
117
+ # First lets check this is not one of the exceptional files
118
+ if test_file .relative_to (swift_src_root ) in EXCEPTIONAL_FILES :
119
+ continue
112
120
113
- if not check_test_file_feature_usage (test_file ):
114
- num_failures += 1
121
+ if not check_test_file_feature_usage (test_file ):
122
+ num_failures += 1
123
+
124
+ if num_failures > 0 :
125
+ sys .exit (1 )
115
126
116
- if num_failures > 0 :
117
- sys .exit (1 )
118
127
119
128
if __name__ == '__main__' :
120
- main ()
129
+ main ()
0 commit comments