6666 "src/codegen/util/cc_hash_table.cpp"
6767]
6868
69+ TEST_CASE_PATT = re .compile (r'TEST_F\(([a-zA-Z]+), ([a-zA-Z]+)\)' )
70+
6971## ==============================================
7072## UTILITY FUNCTION DEFINITIONS
7173## ==============================================
@@ -202,6 +204,39 @@ def check_includes(file_path):
202204 return file_status
203205
204206
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+
205240VALIDATORS = [
206241 check_common_patterns ,
207242 check_includes ,
@@ -224,6 +259,11 @@ def validate_file(file_path):
224259 if not validator (file_path ):
225260 file_status = False
226261
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+
227267 return file_status
228268
229269
0 commit comments