Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: PRESUBMIT.py

Issue 2703173002: PRESUBMIT: Add check for UNIT_TEST use in .cc files. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698