@@ -103,7 +103,7 @@ def get_lines(filepath):
103
103
with open (filepath , 'r' , encoding = get_encoding (filepath )) as f :
104
104
lines = f .readlines ()
105
105
except :
106
- print ('WARNING: Could not open file:' , os .path .basename (filepath ))
106
+ print (' WARNING: Could not open file:' , os .path .basename (filepath ))
107
107
finally :
108
108
return lines
109
109
@@ -144,18 +144,27 @@ def try_match(regex, line, mout):
144
144
return True
145
145
return False
146
146
147
+ # Count the number of elements in the list that match satisfy the predicate.
148
+ def count_if (l , predicate ):
149
+ return sum (1 for e in l if predicate (e ))
150
+
151
+ # Count the number of tests in the list that have the given kind.
152
+ def count_if_kind (tests , kind ):
153
+ return count_if (tests , lambda t : t .kind == kind )
154
+
147
155
# () -> int
148
156
def main ():
149
157
root = get_ancestor (os .path .realpath (__file__ ), 4 )
150
158
gfortran = os .path .join (root , 'Fortran' , 'gfortran' )
151
159
subdirs = get_subdirs (gfortran )
152
160
153
161
for subdir in subdirs :
154
- print (subdir )
155
162
files = []
156
163
for e in os .scandir (subdir ):
157
164
if e .is_file () and re_fortran .match (e .name ):
158
165
files .append (e .path )
166
+ if not files :
167
+ continue
159
168
160
169
# Find all the files that are dependencies of some file that is the
161
170
# main file in a test.
@@ -169,7 +178,9 @@ def main():
169
178
for src in qsplit (m [1 ]):
170
179
dependencies .add (src )
171
180
181
+ print (subdir )
172
182
tests = []
183
+ missing_action = []
173
184
for f in files :
174
185
filename = os .path .basename (f )
175
186
if filename in dependencies :
@@ -184,14 +195,26 @@ def main():
184
195
for l in get_lines (f ):
185
196
mout = []
186
197
if try_match (re_preprocess , l , mout ):
198
+ if kind and kind != Test .PREPROCESS :
199
+ print (
200
+ 'ERROR: Overriding action annotation with PREPROCESS'
201
+ )
187
202
kind = Test .PREPROCESS
188
203
elif try_match (re_compile , l , mout ):
204
+ if kind and kind != Test .COMPILE :
205
+ print (
206
+ 'ERROR: Overriding action annotation with COMPILE'
207
+ )
189
208
kind = Test .COMPILE
190
209
# TODO: Handle the optional target.
191
210
elif try_match (re_link , l , mout ):
211
+ if kind and kind != Test .LINK :
212
+ print ('ERROR: Overriding action annotation with LINK' )
192
213
kind = Test .LINK
193
214
# TODO: Assume that this has an optional target.
194
215
elif try_match (re_run , l , mout ):
216
+ if kind and kind != Test .RUN :
217
+ print ('ERROR: Overriding action annotation with RUN' )
195
218
kind = Test .RUN
196
219
# TODO: Handle the optional target.
197
220
elif try_match (re_shouldfail , l , mout ) or \
@@ -206,22 +229,52 @@ def main():
206
229
options .extend (qsplit (m [2 ]))
207
230
# TODO: Handle the optional target.
208
231
232
+ # If the kind is missing, assume that it is a compile test except
233
+ # for torture/execute where it is an execute test.
234
+ anc1 = os .path .basename (get_ancestor (f , 1 ))
235
+ anc2 = os .path .basename (get_ancestor (f , 2 ))
236
+ if not kind :
237
+ if anc2 == 'torture' and anc1 == 'execute' :
238
+ kind = Test .RUN
239
+ else :
240
+ kind = Test .COMPILE
241
+
209
242
fmt = ' WARNING: {} without action annotation: {}'
210
243
if kind :
211
244
test = Test (kind , sources , options , targets , expect_error )
212
245
tests .append (test )
213
246
elif len (sources ) > 1 :
247
+ missing_action .append (filename )
214
248
print (fmt .format ('Additional sources' , filename ))
215
249
elif len (options ) > 1 :
250
+ missing_action .append (filename )
216
251
print (fmt .format ('Compile options' , filename ))
217
252
elif expect_error :
253
+ missing_action .append (filename )
218
254
print (fmt .format ('Expect error' , filename ))
219
255
else :
220
- pass
221
- # print(' WARNING: No action annotation:', filename)
222
- for t in tests :
223
- print (' ' , str (t ))
224
- print (' ' , len (tests ))
256
+ missing_action .append (filename )
257
+ print (' WARNING: No action annotation:' , filename )
258
+
259
+ # Count the fortran files in the tests. Eventually, we want to ensure
260
+ # that all the fortran files are accounted for
261
+ accounted = set ([])
262
+ for test in tests :
263
+ for s in test .sources :
264
+ if re_fortran .match (s ):
265
+ accounted .add (s )
266
+ filenames = set ([os .path .basename (f ) for f in files ])
267
+ unaccounted = filenames - set (accounted ) - set (missing_action )
268
+
269
+ print (' files:' , len (files ))
270
+ if len (unaccounted ):
271
+ print (' unaccounted:' , sorted (unaccounted ))
272
+ print (' tests:' , len (tests ))
273
+ print (' preprocess:' , count_if_kind (tests , Test .PREPROCESS ))
274
+ print (' compile:' , count_if_kind (tests , Test .COMPILE ))
275
+ print (' link:' , count_if_kind (tests , Test .LINK ))
276
+ print (' run:' , count_if_kind (tests , Test .RUN ))
277
+ print (' unknown:' , len (missing_action ))
225
278
226
279
if __name__ == '__main__' :
227
280
exit (main ())
0 commit comments