66
66
"src/codegen/util/cc_hash_table.cpp"
67
67
]
68
68
69
+ TEST_CASE_PATT = re .compile (r'TEST_F\(([a-zA-Z]+), ([a-zA-Z]+)\)' )
70
+
69
71
## ==============================================
70
72
## UTILITY FUNCTION DEFINITIONS
71
73
## ==============================================
@@ -202,6 +204,39 @@ def check_includes(file_path):
202
204
return file_status
203
205
204
206
207
+ def check_tests (file_path ):
208
+ """Checks test source files for correct class and method naming."""
209
+ # check class naming
210
+ class_status = True # For reporting class names.
211
+ test_status = True # For reporting test cases.
212
+ line_num = 0
213
+ with open (file_path , "r" ) as file :
214
+ for line in file :
215
+ line_num += 1
216
+ if line .startswith ('class ' ):
217
+ class_name = line .split (' ' )[1 ]
218
+ if not class_name .endswith ('Tests' ):
219
+ if class_status :
220
+ LOG .info ("Invalid class name in %s" , file_path )
221
+ class_status = False
222
+ LOG .info ("Line %s: %s" , line_num , line .strip ())
223
+
224
+ else :
225
+ # Check test case names.
226
+ case_found = TEST_CASE_PATT .match (line )
227
+ if case_found and not case_found .groups ()[1 ].endswith ('Test' ):
228
+ if test_status :
229
+ LOG .info ("Invalid test name in %s" , file_path )
230
+ test_status = False
231
+ LOG .info ("Line %s: %s" , line_num , line .strip ())
232
+
233
+ if not class_status :
234
+ LOG .info ("Test class names should end with 'Tests' suffix." )
235
+ if not test_status :
236
+ LOG .info ("Test case names should end with 'Test' suffix." )
237
+
238
+ return class_status and test_status
239
+
205
240
VALIDATORS = [
206
241
check_common_patterns ,
207
242
check_includes ,
@@ -224,6 +259,11 @@ def validate_file(file_path):
224
259
if not validator (file_path ):
225
260
file_status = False
226
261
262
+ relative_path = os .path .relpath (file_path , start = PELOTON_DIR )
263
+ if relative_path .startswith ('/test/' ) and relative_path .endswith ('.cpp' ):
264
+ if not relative_path .endswith ('_util.cpp' ):
265
+ file_status = check_tests (file_path )
266
+
227
267
return file_status
228
268
229
269
0 commit comments