peloton icon indicating copy to clipboard operation
peloton copied to clipboard

Static Code Checks for Test Files

Open schedutron opened this issue 7 years ago • 23 comments

(Implementing #1192) I've added a check for test class name. Do I also have to create another paths variable via glob module, which contains all the test files' paths (which end with *_test.cpp)?

Also, I'll add other checks soon.

schedutron avatar Apr 04 '18 14:04 schedutron

@tcm-marcel Should check_tests function be only called on staged test files? Also, what are the criteria for the gtest macro methods to be checked? Should each test case name end with the 'Test' suffix?

schedutron avatar Apr 04 '18 14:04 schedutron

I would check in validate_file(file_path) [1] if the file matches /test/*/*.cpp and then run the check in addition to the other checks. This way every test file that the validator is called with gets checked. The pre-commit hook calls the validator with the stages files, to this happens automatically.

[1] https://github.com/schedutron/peloton/blob/dda18900b9c5efafbea1d4ada73b2903ecd4dc9a/script/validators/source_validator.py#L237

tcm-marcel avatar Apr 04 '18 14:04 tcm-marcel

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 glob.glob() for faster execution. Will do so soon. Or maybe a startswith()-endswith() call pair would also be fine - and simpler.

schedutron avatar Apr 04 '18 15:04 schedutron

Coverage Status

Coverage increased (+0.01%) to 77.566% when pulling 3d74f74139f3648778016dded552968107c7a28d on schedutron:static into 5686479c5f33087031e1b68b7832245c7886b712 on cmu-db:master.

coveralls avatar Apr 04 '18 16:04 coveralls

@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 _util suffix?

schedutron avatar Apr 11 '18 14:04 schedutron

How do I check the methods? They don't follow a prefix/suffix pattern.

You can use a regex to find these lines and extract the information. (see example: https://regexr.com/3nnro)

Also, to resolve the issue you mentioned above, should I omit the files that end with a _util suffix?

Sounds good.

tcm-marcel avatar Apr 11 '18 15:04 tcm-marcel

Alright, but do we have to check after we extract the identifiers?

schedutron avatar Apr 11 '18 15:04 schedutron

Ah sorry, I got you wrong. The naming conventions say, that every method (test case) should have the suffix Test.

tcm-marcel avatar Apr 11 '18 15:04 tcm-marcel

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?

schedutron avatar Apr 11 '18 15:04 schedutron

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.

tcm-marcel avatar Apr 11 '18 15:04 tcm-marcel

As a first iteration, I will simply add the Test suffix to the incorrect test class name and the Tests suffix to the incorrect test method names.

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 avatar Apr 27 '18 04:04 schedutron

@schedutron No, we don't provide automated fixing. We expect people to fix their violations manually ;)

tcm-marcel avatar Apr 27 '18 13:04 tcm-marcel

@tcm-marcel Have a look now :)

schedutron avatar May 10 '18 08:05 schedutron

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

  1. make a temporary copy of your branch git checkout -b temp
  2. reset the old branch (the one with the PR) to upstream master git branch -f ... (don't forget to fetch and rebase your master branch before)
  3. cherry pick the commits you want to have (all except the resolve merge conflicts one and the last one*)
  4. force push the new version of this branch, the PR will update accordingly

*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 avatar May 11 '18 14:05 tcm-marcel

@tcm-marcel I was afraid that could happen. Will fix this soon. Thanks for the tips!

schedutron avatar May 13 '18 20:05 schedutron

@tcm-marcel The checks are passing now!

schedutron avatar May 19 '18 13:05 schedutron

Hey, sorry for looking at this only now. ~1) something is still wrong from rebasing, there are several changes in the test files, for example in test/codegen/oa_hash_table_test.cpp~ ~2) I think the two classes PelotonTest and PelotonCodeGenTest should not be changed. I just created a commit to revert this, but I now realized that you will have to touch all files again anyway.~

Let me try if I can fix this quickly.

tcm-marcel avatar May 21 '18 17:05 tcm-marcel

What exactly are the changes in, say, test/codegen/oa_hash_table_test.cpp?

schedutron avatar May 21 '18 18:05 schedutron

I can't find it anymore... seems like I looked at a wrong version. I am sorry! Let me take another look.

tcm-marcel avatar May 21 '18 18:05 tcm-marcel

Ok sorry, I messed this up a little bit:

  1. I was wrong, I must have looked at the wrong diff
  2. I thought about this again and decided that we leave it that way

I will try to rebase your PR and make it ready to merge.

tcm-marcel avatar May 21 '18 22:05 tcm-marcel

@schedutron can you fix the merge conflicts so this can be merged in?

saatviks avatar May 24 '18 00:05 saatviks

What is the status of this PR right now? I am putting In Progress tag until merge conflicts are fixed.

tli2 avatar Jun 05 '18 15:06 tli2

Lets finalize this!

schedutron avatar Aug 22 '18 08:08 schedutron