Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 77c97c1

Browse files
committed
Add test case check
1 parent 6d66e00 commit 77c97c1

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

script/validators/source_validator.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
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
## ==============================================
@@ -205,23 +207,35 @@ def check_includes(file_path):
205207
def check_tests(file_path):
206208
"""Checks test source files for correct class and method naming."""
207209
# check class naming
208-
file_status = True
210+
class_status = True # For reporting class names.
211+
test_status = True # For reporting test cases.
209212
line_num = 0
210213
with open(file_path, "r") as file:
211214
for line in file:
212215
line_num += 1
213216
if line.startswith('class '):
214217
class_name = line.split(' ')[1]
215218
if not class_name.endswith('Tests'):
216-
if file_status:
219+
if class_status:
217220
LOG.info("Invalid class name in %s", file_path)
218-
file_status = False
221+
class_status = False
219222
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:
221234
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
225239

226240
VALIDATORS = [
227241
check_common_patterns,

0 commit comments

Comments
 (0)