Add @interface's to @Batch/DoNotBatch ignore list
The PRESUBMIT checks look for @Batch or @DoNotBatch on test files and give warnings if they are not present. These should not include simple @interface's like DisabledTest.java or EnormousTest.java etc. AX-Relnotes: N/A Bug: N/A Change-Id: I3a3278925a6d78f548e4154aca52f12e600f37b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4697253 Commit-Queue: Mark Schillaci <mschillaci@google.com> Reviewed-by: Andrew Grieve <agrieve@chromium.org> Reviewed-by: James Shen <zhiyuans@google.com> Cr-Commit-Position: refs/heads/main@{#1172010}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
841e2bf666
commit
8ef0d871ef
@ -6705,6 +6705,7 @@ def CheckBatchAnnotation(input_api, output_api):
|
||||
robolectric_test = input_api.re.compile(r'[rR]obolectric')
|
||||
test_class_declaration = input_api.re.compile(r'^\s*public\sclass.*Test')
|
||||
uiautomator_test = input_api.re.compile(r'[uU]i[aA]utomator')
|
||||
test_annotation_declaration = input_api.re.compile(r'^\s*public\s@interface\s.*{')
|
||||
|
||||
missing_annotation_errors = []
|
||||
extra_annotation_errors = []
|
||||
@ -6719,6 +6720,7 @@ def CheckBatchAnnotation(input_api, output_api):
|
||||
batch_matched = None
|
||||
do_not_batch_matched = None
|
||||
is_instrumentation_test = True
|
||||
test_annotation_declaration_matched = None
|
||||
for line in f.NewContents():
|
||||
if robolectric_test.search(line) or uiautomator_test.search(line):
|
||||
# Skip Robolectric and UiAutomator tests.
|
||||
@ -6730,8 +6732,11 @@ def CheckBatchAnnotation(input_api, output_api):
|
||||
do_not_batch_matched = do_not_batch_annotation.search(line)
|
||||
test_class_declaration_matched = test_class_declaration.search(
|
||||
line)
|
||||
if test_class_declaration_matched:
|
||||
test_annotation_declaration_matched = test_annotation_declaration.search(line)
|
||||
if test_class_declaration_matched or test_annotation_declaration_matched:
|
||||
break
|
||||
if test_annotation_declaration_matched:
|
||||
continue
|
||||
if (is_instrumentation_test and
|
||||
not batch_matched and
|
||||
not do_not_batch_matched):
|
||||
|
@ -4843,7 +4843,7 @@ class CheckBatchAnnotation(unittest.TestCase):
|
||||
'import org.chromium.base.test.BaseRobolectricTestRunner;',
|
||||
'public class Three {']),
|
||||
MockFile('path/FourTest.java',
|
||||
['@DoNotBatch(reason = "dummy reason 1")',
|
||||
['@DoNotBatch(reason = "placeholder reason 1")',
|
||||
'import org.chromium.base.test.BaseRobolectricTestRunner;',
|
||||
'public class Four {']),
|
||||
]
|
||||
@ -4864,7 +4864,7 @@ class CheckBatchAnnotation(unittest.TestCase):
|
||||
MockFile('path/OneTest.java',
|
||||
['@Batch(Batch.PER_CLASS)', 'public class One {']),
|
||||
MockFile('path/TwoTest.java',
|
||||
['@DoNotBatch(reason = "dummy reasons.")', 'public class Two {'
|
||||
['@DoNotBatch(reason = "placeholder reasons.")', 'public class Two {'
|
||||
]),
|
||||
MockFile('path/ThreeTest.java',
|
||||
['@Batch(Batch.PER_CLASS)',
|
||||
@ -4872,9 +4872,9 @@ class CheckBatchAnnotation(unittest.TestCase):
|
||||
['@Batch(Batch.PER_CLASS)',
|
||||
'public class Three extends BaseTestB {']),
|
||||
MockFile('path/FourTest.java',
|
||||
['@DoNotBatch(reason = "dummy reason 1")',
|
||||
['@DoNotBatch(reason = "placeholder reason 1")',
|
||||
'public class Four extends BaseTestA {'],
|
||||
['@DoNotBatch(reason = "dummy reason 2")',
|
||||
['@DoNotBatch(reason = "placeholder reason 2")',
|
||||
'public class Four extends BaseTestB {']),
|
||||
MockFile('path/FiveTest.java',
|
||||
['import androidx.test.uiautomator.UiDevice;',
|
||||
@ -4897,7 +4897,9 @@ class CheckBatchAnnotation(unittest.TestCase):
|
||||
),
|
||||
MockFile('path/PRESUBMIT.py',
|
||||
['@Batch(Batch.PER_CLASS)',
|
||||
'@DoNotBatch(reason = "dummy reason)']),
|
||||
'@DoNotBatch(reason = "placeholder reason)']),
|
||||
MockFile('path/AnnotationTest.java',
|
||||
['public @interface SomeAnnotation {'],),
|
||||
]
|
||||
errors = PRESUBMIT.CheckBatchAnnotation(mock_input, MockOutputApi())
|
||||
self.assertEqual(0, len(errors))
|
||||
|
Reference in New Issue
Block a user