This repository was archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 619
Static Code Checks for Test Files #1257
Open
schedutron
wants to merge
4
commits into
cmu-db:master
Choose a base branch
from
schedutron:static
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,8 @@ | |
"src/codegen/util/cc_hash_table.cpp" | ||
] | ||
|
||
TEST_CASE_PATT = re.compile(r'TEST_F\(([a-zA-Z]+), ([a-zA-Z]+)\)') | ||
|
||
## ============================================== | ||
## UTILITY FUNCTION DEFINITIONS | ||
## ============================================== | ||
|
@@ -202,6 +204,39 @@ def check_includes(file_path): | |
return file_status | ||
|
||
|
||
def check_tests(file_path): | ||
"""Checks test source files for correct class and method naming.""" | ||
# check class naming | ||
class_status = True # For reporting class names. | ||
test_status = True # For reporting test cases. | ||
line_num = 0 | ||
with open(file_path, "r") as file: | ||
for line in file: | ||
line_num += 1 | ||
if line.startswith('class '): | ||
class_name = line.split(' ')[1] | ||
if not class_name.endswith('Tests'): | ||
if class_status: | ||
LOG.info("Invalid class name in %s", file_path) | ||
class_status = False | ||
LOG.info("Line %s: %s", line_num, line.strip()) | ||
|
||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be a separate loop for this? That will prevent interleaved output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ok with this, we hope not to have thousands of those errors. |
||
# Check test case names. | ||
case_found = TEST_CASE_PATT.match(line) | ||
if case_found and not case_found.groups()[1].endswith('Test'): | ||
if test_status: | ||
LOG.info("Invalid test name in %s", file_path) | ||
test_status = False | ||
LOG.info("Line %s: %s", line_num, line.strip()) | ||
|
||
if not class_status: | ||
LOG.info("Test class names should end with 'Tests' suffix.") | ||
if not test_status: | ||
LOG.info("Test case names should end with 'Test' suffix.") | ||
|
||
return class_status and test_status | ||
|
||
VALIDATORS = [ | ||
check_common_patterns, | ||
check_includes, | ||
|
@@ -224,6 +259,11 @@ def validate_file(file_path): | |
if not validator(file_path): | ||
file_status = False | ||
|
||
relative_path = os.path.relpath(file_path, start=PELOTON_DIR) | ||
if relative_path.startswith('/test/') and relative_path.endswith('.cpp'): | ||
if not relative_path.endswith('_util.cpp'): | ||
file_status = check_tests(file_path) | ||
|
||
return file_status | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right place to define the regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so.