-
Notifications
You must be signed in to change notification settings - Fork 623
Static Code Checks for Test Files #1257
base: master
Are you sure you want to change the base?
Conversation
@tcm-marcel Should |
I would check in |
I think I should add a path regex for checking whether we have a test file instead of checking membership in the path set returned by |
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.
Hey, I just took a quick look and found a few problems:
- at the moment the script accidentally picks up forward declarations:
04-06-2018 13:18:59 [check_tests:217] INFO : Invalid class name in /home/marcel/dev/peloton/peloton_review/test/concurrency/testing_transaction_util.cpp
04-06-2018 13:18:59 [check_tests:219] INFO : Line 34: class ExecutorContext;
04-06-2018 13:18:59 [check_tests:219] INFO : Line 37: class InsertPlan;
04-06-2018 13:18:59 [check_tests:219] INFO : Line 38: class ProjectInfo;
04-06-2018 13:18:59 [check_tests:221] INFO : Test class names should end with 'Tests' suffix.
- methods are not checked yet:
TEST_F(..)
It looks like all other matches are correct, meaning that the rules are actually violated there. So once we agreed on the result, we will add one more commit that fixes the naming in the files.
@tcm-marcel How do I check the methods? They don't follow a prefix/suffix pattern. Also, to resolve the issue you mentioned above, should I omit the files that end with a |
You can use a regex to find these lines and extract the information. (see example: https://regexr.com/3nnro)
Sounds good. |
Alright, but do we have to check after we extract the identifiers? |
Ah sorry, I got you wrong. The naming conventions say, that every method (test case) should have the suffix |
Yeah, but a lot of test cases across different test files do not. Are we going to use the validator script to fix all these files? |
Correct, that's the idea. Unfortunately we have a lot of code that doesn't meet our conventions, because it is older than these conventions or because people didn't care. The validator shall help to prevent this in the future. |
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 have couple of doubts.
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 comment
The 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 comment
The 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.
@@ -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]+)\)') |
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.
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.
Looks good!
Next step would be to fix all wrong test cases. In generel this should be easy, maybe we have to do some refactoring there.
@@ -224,6 +259,11 @@ def validate_file(file_path): | |||
if not validator(file_path): | |||
file_status = False | |||
|
|||
relative_path = file_path.replace(PELOTON_DIR, '') |
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.
One more thing: Can you use os.path.relpath
here instead of string replace?
As a first iteration, I will simply add the Also, do I need to implement the correction code in the formatter script or simply fix the incorrect files in the Python interpreter and push them? |
@schedutron No, we don't provide automated fixing. We expect people to fix their violations manually ;) |
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 can see one obvious issue: there were few classes ending with Test
rather than Tests
. What happened during the fix is that they're now suffixed with TestTests
. I'll fix these soon.
test/binder/binder_test.cpp
Outdated
@@ -36,7 +36,7 @@ using std::make_tuple; | |||
namespace peloton { | |||
namespace test { | |||
|
|||
class BinderCorrectnessTest : public PelotonTest { | |||
class BinderCorrectnessTestTests : public PelotonTest { |
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.
This class should've been named BinderCorrectnessTests
!
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.
@schedutron Can you apply this change and rebase the PR? How many changes of the test files are still missing?
It's time that we merge it in and finish that part.
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.
Sorry for getting this delayed. I'll apply the changes soon.
test/binder/binder_test.cpp
Outdated
@@ -36,7 +36,7 @@ using std::make_tuple; | |||
namespace peloton { | |||
namespace test { | |||
|
|||
class BinderCorrectnessTest : public PelotonTest { | |||
class BinderCorrectnessTests : public PelotonTest { |
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.
@tcm-marcel At this stage, there are parent classes which still have the Test
suffix instead of the Tests
suffix. They are defined in .h
files, and thus were not changed by the name-fixing script I ran. If I change them, I would also have to change their name in inheritance statements, e.g., here the statement will look like class BinderCorrectnessTests : public PelotonTests {
. Should I do that?
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.
@schedutron Yes.
@tcm-marcel Have a look now :) |
Hey, I fear you screwed up the code when resolving the merge conflicts in 2f28acc. This is also the reason the tests fail. I think the easiest way to solve this is to
*Please remove the changes where you format the headers. It's a good idea, but it should be a separate PR. If you need help, let me know. |
@tcm-marcel I was afraid that could happen. Will fix this soon. Thanks for the tips! |
@tcm-marcel The checks are passing now! |
Hey, sorry for looking at this only now. Let me try if I can fix this quickly. |
What exactly are the changes in, say, |
I can't find it anymore... seems like I looked at a wrong version. I am sorry! Let me take another look. |
Ok sorry, I messed this up a little bit:
I will try to rebase your PR and make it ready to merge. |
@schedutron can you fix the merge conflicts so this can be merged in? |
What is the status of this PR right now? I am putting In Progress tag until merge conflicts are fixed. |
Lets finalize this! |
(Implementing #1192)
I've added a check for test class name. Do I also have to create another
paths
variable viaglob
module, which contains all the test files' paths (which end with*_test.cpp
)?Also, I'll add other checks soon.