Skip to content

Commit 8ef0d87

Browse files
mschillaciChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
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 <[email protected]> Reviewed-by: Andrew Grieve <[email protected]> Reviewed-by: James Shen <[email protected]> Cr-Commit-Position: refs/heads/main@{#1172010}
1 parent 841e2bf commit 8ef0d87

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

PRESUBMIT.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -6705,6 +6705,7 @@ def CheckBatchAnnotation(input_api, output_api):
67056705
robolectric_test = input_api.re.compile(r'[rR]obolectric')
67066706
test_class_declaration = input_api.re.compile(r'^\s*public\sclass.*Test')
67076707
uiautomator_test = input_api.re.compile(r'[uU]i[aA]utomator')
6708+
test_annotation_declaration = input_api.re.compile(r'^\s*public\s@interface\s.*{')
67086709

67096710
missing_annotation_errors = []
67106711
extra_annotation_errors = []
@@ -6719,6 +6720,7 @@ def _FilterFile(affected_file):
67196720
batch_matched = None
67206721
do_not_batch_matched = None
67216722
is_instrumentation_test = True
6723+
test_annotation_declaration_matched = None
67226724
for line in f.NewContents():
67236725
if robolectric_test.search(line) or uiautomator_test.search(line):
67246726
# Skip Robolectric and UiAutomator tests.
@@ -6730,8 +6732,11 @@ def _FilterFile(affected_file):
67306732
do_not_batch_matched = do_not_batch_annotation.search(line)
67316733
test_class_declaration_matched = test_class_declaration.search(
67326734
line)
6733-
if test_class_declaration_matched:
6735+
test_annotation_declaration_matched = test_annotation_declaration.search(line)
6736+
if test_class_declaration_matched or test_annotation_declaration_matched:
67346737
break
6738+
if test_annotation_declaration_matched:
6739+
continue
67356740
if (is_instrumentation_test and
67366741
not batch_matched and
67376742
not do_not_batch_matched):

PRESUBMIT_test.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -4843,7 +4843,7 @@ def testTruePositives(self):
48434843
'import org.chromium.base.test.BaseRobolectricTestRunner;',
48444844
'public class Three {']),
48454845
MockFile('path/FourTest.java',
4846-
['@DoNotBatch(reason = "dummy reason 1")',
4846+
['@DoNotBatch(reason = "placeholder reason 1")',
48474847
'import org.chromium.base.test.BaseRobolectricTestRunner;',
48484848
'public class Four {']),
48494849
]
@@ -4864,17 +4864,17 @@ def testAnnotationsPresent(self):
48644864
MockFile('path/OneTest.java',
48654865
['@Batch(Batch.PER_CLASS)', 'public class One {']),
48664866
MockFile('path/TwoTest.java',
4867-
['@DoNotBatch(reason = "dummy reasons.")', 'public class Two {'
4867+
['@DoNotBatch(reason = "placeholder reasons.")', 'public class Two {'
48684868
]),
48694869
MockFile('path/ThreeTest.java',
48704870
['@Batch(Batch.PER_CLASS)',
48714871
'public class Three extends BaseTestA {'],
48724872
['@Batch(Batch.PER_CLASS)',
48734873
'public class Three extends BaseTestB {']),
48744874
MockFile('path/FourTest.java',
4875-
['@DoNotBatch(reason = "dummy reason 1")',
4875+
['@DoNotBatch(reason = "placeholder reason 1")',
48764876
'public class Four extends BaseTestA {'],
4877-
['@DoNotBatch(reason = "dummy reason 2")',
4877+
['@DoNotBatch(reason = "placeholder reason 2")',
48784878
'public class Four extends BaseTestB {']),
48794879
MockFile('path/FiveTest.java',
48804880
['import androidx.test.uiautomator.UiDevice;',
@@ -4897,7 +4897,9 @@ def testAnnotationsPresent(self):
48974897
),
48984898
MockFile('path/PRESUBMIT.py',
48994899
['@Batch(Batch.PER_CLASS)',
4900-
'@DoNotBatch(reason = "dummy reason)']),
4900+
'@DoNotBatch(reason = "placeholder reason)']),
4901+
MockFile('path/AnnotationTest.java',
4902+
['public @interface SomeAnnotation {'],),
49014903
]
49024904
errors = PRESUBMIT.CheckBatchAnnotation(mock_input, MockOutputApi())
49034905
self.assertEqual(0, len(errors))

0 commit comments

Comments
 (0)