Skip to content

Commit

Permalink
PRESUBMIT.py: Make // IN-TEST work for .java files
Browse files Browse the repository at this point in the history
Bug: None
Change-Id: Ibf015f85fbf80c7e8e4060fff361d2e60358a52f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4661685
Commit-Queue: Mohamed Heikal <[email protected]>
Auto-Submit: Andrew Grieve <[email protected]>
Reviewed-by: Mohamed Heikal <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1166720}
  • Loading branch information
agrieve authored and Chromium LUCI CQ committed Jul 6, 2023
1 parent 8bc2dcc commit 40f451d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,7 @@ def CheckNoProductionCodeUsingTestOnlyFunctionsJava(input_api, output_api):
inclusion_re = input_api.re.compile(r'(%s)\s*\(' % name_pattern)
# Ignore definitions. (Comments are ignored separately.)
exclusion_re = input_api.re.compile(r'(%s)[^;]+\{' % name_pattern)
allowlist_re = input_api.re.compile(r'// IN-TEST$')

problems = []
sources = lambda x: input_api.FilterSourceFile(
Expand All @@ -1955,6 +1956,7 @@ def CheckNoProductionCodeUsingTestOnlyFunctionsJava(input_api, output_api):
continue
if (inclusion_re.search(line) and not comment_re.search(line)
and not annotation_re.search(line)
and not allowlist_re.search(line)
and not exclusion_re.search(line)):
problems.append('%s:%d\n %s' %
(local_path, line_number, line.strip()))
Expand Down
2 changes: 2 additions & 0 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,7 @@ def testFalsePositives(self):
MockFile('some/path/foo.mm', ['FooForTesting() {']),
MockFile('some/path/foo.cc', ['::FooForTests();']),
MockFile('some/path/foo.cpp', ['// foo_for_test();']),
MockFile('some/path/foo.cxx', ['foo_for_test(); // IN-TEST']),
]

results = PRESUBMIT.CheckNoProductionCodeUsingTestOnlyFunctions(
Expand Down Expand Up @@ -3143,6 +3144,7 @@ def testFalsePositives(self):
' * Use FooForTest(); to obtain foo in tests.'
' */'
]),
MockFile('dir/java/src/bar6.java', ['FooForTesting(); // IN-TEST']),
]

results = PRESUBMIT.CheckNoProductionCodeUsingTestOnlyFunctionsJava(
Expand Down

0 comments on commit 40f451d

Please sign in to comment.