Presubmit: Skip third_party for fwd decl warning
Skip presubmit warning when the introduced useless forward declaration is made in third_party (with the exception of blink). Take the opportunity to fix one test and style. BUG=662195 TEST=PRESUBMIT_test.py ForwardDeclarationTest Review-Url: https://codereview.chromium.org/2568473002 Cr-Commit-Position: refs/heads/master@{#437833}
This commit is contained in:
10
PRESUBMIT.py
10
PRESUBMIT.py
@ -1586,8 +1586,9 @@ def _CheckMojoUsesNewWrapperTypes(input_api, output_api):
|
||||
|
||||
|
||||
def _CheckUselessForwardDeclarations(input_api, output_api):
|
||||
"""Checks that added or removed lines in affected header files
|
||||
do not lead to new useless class or struct forward declaration.
|
||||
"""Checks that added or removed lines in non third party affected
|
||||
header files do not lead to new useless class or struct forward
|
||||
declaration.
|
||||
"""
|
||||
results = []
|
||||
class_pattern = input_api.re.compile(r'^class\s+(\w+);$',
|
||||
@ -1595,6 +1596,11 @@ def _CheckUselessForwardDeclarations(input_api, output_api):
|
||||
struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$',
|
||||
input_api.re.MULTILINE)
|
||||
for f in input_api.AffectedFiles(include_deletes=False):
|
||||
if (f.LocalPath().startswith('third_party') and
|
||||
not f.LocalPath().startswith('third_party/WebKit') and
|
||||
not f.LocalPath().startswith('third_party\\WebKit')):
|
||||
continue
|
||||
|
||||
if not f.LocalPath().endswith('.h'):
|
||||
continue
|
||||
|
||||
|
@ -1115,11 +1115,14 @@ class HardcodedGoogleHostsTest(unittest.TestCase):
|
||||
|
||||
|
||||
class ForwardDeclarationTest(unittest.TestCase):
|
||||
def testCheckHeadersOnly(self):
|
||||
def testCheckHeadersOnlyOutsideThirdParty(self):
|
||||
mock_input_api = MockInputApi()
|
||||
mock_input_api.files = [
|
||||
MockAffectedFile('somewhere/file.cc', [
|
||||
'class DummyClass;'
|
||||
]),
|
||||
MockAffectedFile('third_party/header.h', [
|
||||
'class DummyClass;'
|
||||
])
|
||||
]
|
||||
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
|
||||
@ -1130,9 +1133,9 @@ class ForwardDeclarationTest(unittest.TestCase):
|
||||
mock_input_api = MockInputApi()
|
||||
mock_input_api.files = [
|
||||
MockAffectedFile('somewhere/header.h', [
|
||||
'class SomeClass {'
|
||||
' protected:'
|
||||
' class NotAMatch;'
|
||||
'class SomeClass {',
|
||||
' protected:',
|
||||
' class NotAMatch;',
|
||||
'};'
|
||||
])
|
||||
]
|
||||
@ -1162,12 +1165,28 @@ class ForwardDeclarationTest(unittest.TestCase):
|
||||
'struct DummyStruct;',
|
||||
'class UsefulClass;',
|
||||
'std::unique_ptr<UsefulClass> p;'
|
||||
]),
|
||||
])
|
||||
]
|
||||
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
|
||||
MockOutputApi())
|
||||
self.assertEqual(2, len(warnings))
|
||||
|
||||
def testBlinkHeaders(self):
|
||||
mock_input_api = MockInputApi()
|
||||
mock_input_api.files = [
|
||||
MockAffectedFile('third_party/WebKit/header.h', [
|
||||
'class DummyClass;',
|
||||
'struct DummyStruct;',
|
||||
]),
|
||||
MockAffectedFile('third_party\\WebKit\\header.h', [
|
||||
'class DummyClass;',
|
||||
'struct DummyStruct;',
|
||||
])
|
||||
]
|
||||
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
|
||||
MockOutputApi())
|
||||
self.assertEqual(4, len(warnings))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -120,7 +120,7 @@ class MockFile(object):
|
||||
return self._local_path
|
||||
|
||||
def GenerateScmDiff(self):
|
||||
return self._scm_diff;
|
||||
return self._scm_diff
|
||||
|
||||
def rfind(self, p):
|
||||
"""os.path.basename is called on MockFile so we need an rfind method."""
|
||||
|
Reference in New Issue
Block a user