|
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 | ## ============================================== |
@@ -205,23 +207,35 @@ def check_includes(file_path): |
205 | 207 | def check_tests(file_path): |
206 | 208 | """Checks test source files for correct class and method naming.""" |
207 | 209 | # check class naming |
208 | | - file_status = True |
| 210 | + class_status = True # For reporting class names. |
| 211 | + test_status = True # For reporting test cases. |
209 | 212 | line_num = 0 |
210 | 213 | with open(file_path, "r") as file: |
211 | 214 | for line in file: |
212 | 215 | line_num += 1 |
213 | 216 | if line.startswith('class '): |
214 | 217 | class_name = line.split(' ')[1] |
215 | 218 | if not class_name.endswith('Tests'): |
216 | | - if file_status: |
| 219 | + if class_status: |
217 | 220 | LOG.info("Invalid class name in %s", file_path) |
218 | | - file_status = False |
| 221 | + class_status = False |
219 | 222 | LOG.info("Line %s: %s", line_num, line.strip()) |
220 | | - if not file_status: |
| 223 | + |
| 224 | + else: |
| 225 | + # Check test case names. |
| 226 | + case_found = TEST_CASE_PATT.search(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: |
221 | 234 | LOG.info("Test class names should end with 'Tests' suffix.") |
222 | | - return file_status |
223 | | - |
224 | | - # check method naming |
| 235 | + if not test_status: |
| 236 | + LOG.info("Test case names should end with 'Test' suffix.") |
| 237 | + |
| 238 | + return class_status and test_status |
225 | 239 |
|
226 | 240 | VALIDATORS = [ |
227 | 241 | check_common_patterns, |
|
0 commit comments