Commit 2c51e821 authored by jbriance's avatar jbriance Committed by Commit bot

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}
parent bcadd13b
...@@ -1586,8 +1586,9 @@ def _CheckMojoUsesNewWrapperTypes(input_api, output_api): ...@@ -1586,8 +1586,9 @@ def _CheckMojoUsesNewWrapperTypes(input_api, output_api):
def _CheckUselessForwardDeclarations(input_api, output_api): def _CheckUselessForwardDeclarations(input_api, output_api):
"""Checks that added or removed lines in affected header files """Checks that added or removed lines in non third party affected
do not lead to new useless class or struct forward declaration. header files do not lead to new useless class or struct forward
declaration.
""" """
results = [] results = []
class_pattern = input_api.re.compile(r'^class\s+(\w+);$', class_pattern = input_api.re.compile(r'^class\s+(\w+);$',
...@@ -1595,6 +1596,11 @@ def _CheckUselessForwardDeclarations(input_api, output_api): ...@@ -1595,6 +1596,11 @@ def _CheckUselessForwardDeclarations(input_api, output_api):
struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$', struct_pattern = input_api.re.compile(r'^struct\s+(\w+);$',
input_api.re.MULTILINE) input_api.re.MULTILINE)
for f in input_api.AffectedFiles(include_deletes=False): 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'): if not f.LocalPath().endswith('.h'):
continue continue
......
...@@ -1115,11 +1115,14 @@ class HardcodedGoogleHostsTest(unittest.TestCase): ...@@ -1115,11 +1115,14 @@ class HardcodedGoogleHostsTest(unittest.TestCase):
class ForwardDeclarationTest(unittest.TestCase): class ForwardDeclarationTest(unittest.TestCase):
def testCheckHeadersOnly(self): def testCheckHeadersOnlyOutsideThirdParty(self):
mock_input_api = MockInputApi() mock_input_api = MockInputApi()
mock_input_api.files = [ mock_input_api.files = [
MockAffectedFile('somewhere/file.cc', [ MockAffectedFile('somewhere/file.cc', [
'class DummyClass;' 'class DummyClass;'
]),
MockAffectedFile('third_party/header.h', [
'class DummyClass;'
]) ])
] ]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api, warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
...@@ -1130,9 +1133,9 @@ class ForwardDeclarationTest(unittest.TestCase): ...@@ -1130,9 +1133,9 @@ class ForwardDeclarationTest(unittest.TestCase):
mock_input_api = MockInputApi() mock_input_api = MockInputApi()
mock_input_api.files = [ mock_input_api.files = [
MockAffectedFile('somewhere/header.h', [ MockAffectedFile('somewhere/header.h', [
'class SomeClass {' 'class SomeClass {',
' protected:' ' protected:',
' class NotAMatch;' ' class NotAMatch;',
'};' '};'
]) ])
] ]
...@@ -1162,12 +1165,28 @@ class ForwardDeclarationTest(unittest.TestCase): ...@@ -1162,12 +1165,28 @@ class ForwardDeclarationTest(unittest.TestCase):
'struct DummyStruct;', 'struct DummyStruct;',
'class UsefulClass;', 'class UsefulClass;',
'std::unique_ptr<UsefulClass> p;' 'std::unique_ptr<UsefulClass> p;'
]), ])
] ]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api, warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
MockOutputApi()) MockOutputApi())
self.assertEqual(2, len(warnings)) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -120,7 +120,7 @@ class MockFile(object): ...@@ -120,7 +120,7 @@ class MockFile(object):
return self._local_path return self._local_path
def GenerateScmDiff(self): def GenerateScmDiff(self):
return self._scm_diff; return self._scm_diff
def rfind(self, p): def rfind(self, p):
"""os.path.basename is called on MockFile so we need an rfind method.""" """os.path.basename is called on MockFile so we need an rfind method."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment