Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index 3405ef9116fcd9e654af577ba49538e08ca945d3..119060c61b183839fa7f5ccbf829b71b24325e71 100755 |
| --- a/PRESUBMIT.py |
| +++ b/PRESUBMIT.py |
| @@ -169,6 +169,23 @@ def _CheckNoIOStreamInHeaders(input_api, output_api): |
| return [] |
| +def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api): |
| + """Checks to make sure no source files use UNIT_TEST.""" |
|
kwiberg-webrtc
2017/02/20 08:44:46
Either this doc string or the error message below
|
| + problems = [] |
| + for f in input_api.AffectedFiles(): |
| + if not f.LocalPath().endswith(('.cc', '.mm')): |
|
kwiberg-webrtc
2017/02/20 08:44:46
It would seem safer to have a whitelist of file ty
|
| + continue |
| + |
| + for line_num, line in f.ChangedContents(): |
| + if 'UNIT_TEST ' in line or line.endswith('UNIT_TEST'): |
|
kwiberg-webrtc
2017/02/20 08:44:46
Use re to search the line for "\bUNIT_TEST\b"? Tha
|
| + problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| + |
| + if not problems: |
| + return [] |
| + return [output_api.PresubmitPromptWarning('UNIT_TEST is only for headers.\n' + |
| + '\n'.join(problems))] |
| + |
| + |
| def _CheckNoFRIEND_TEST(input_api, output_api): |
| """Make sure that gtest's FRIEND_TEST() macro is not used, the |
| FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be |
| @@ -514,6 +531,7 @@ def _CommonChecks(input_api, output_api): |
| input_api, output_api)) |
| results.extend(_CheckNativeApiHeaderChanges(input_api, output_api)) |
| results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
| + results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
| results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
| results.extend(_CheckGnChanges(input_api, output_api)) |
| results.extend(_CheckUnwantedDependencies(input_api, output_api)) |