diff options
author | oysteine <oysteine@chromium.org> | 2015-10-22 13:55:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-22 20:55:58 +0000 |
commit | c430ad4e9110a195902c7b8e886026e8d8353327 (patch) | |
tree | ae6e3201bbe5e5a279d49b063052ddba97ade6ba | |
parent | ea9850a4ac10792b291f2821c4338aa708c1519d (diff) | |
download | chromium_src-c430ad4e9110a195902c7b8e886026e8d8353327.zip chromium_src-c430ad4e9110a195902c7b8e886026e8d8353327.tar.gz chromium_src-c430ad4e9110a195902c7b8e886026e8d8353327.tar.bz2 |
Changed the CheckBaseMacrosInHeaders presubmit to pass over C++ comments
R=dbeam@chromium.org,maruel@chromium.org
BUG=545272
Review URL: https://codereview.chromium.org/1413263002
Cr-Commit-Position: refs/heads/master@{#355639}
-rw-r--r-- | PRESUBMIT.py | 4 | ||||
-rwxr-xr-x | PRESUBMIT_test.py | 11 |
2 files changed, 11 insertions, 4 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 67b5182..e3ee9c4 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -1506,7 +1506,7 @@ def _CheckSingletonInHeaders(input_api, output_api): f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): contents = input_api.ReadFile(f) for line in contents.splitlines(False): - if (not input_api.re.match(r'//', line) and # Strip C++ comment. + if (not line.lstrip().startswith('//') and # Strip C++ comment. pattern.search(line)): files.append(f) break @@ -1532,6 +1532,8 @@ def _CheckBaseMacrosInHeaders(input_api, output_api): if not f.LocalPath().endswith('.h'): continue for line_num, line in f.ChangedContents(): + if line.lstrip().startswith('//'): # Strip C++ comment. + continue if any(d in line for d in disallows): contents = input_api.ReadFile(f) if not (macros in contents or basictypes in contents): diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index f5a21ca..5aed7ee 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -392,15 +392,18 @@ class CheckSingletonInHeadersTest(unittest.TestCase): 'base::Singleton<Type, Traits, DifferentiatingType>::'] diff_foo_h = ['// base::Singleton<Foo> in comment.', 'friend class base::Singleton<Foo>'] + diff_foo2_h = [' //Foo* bar = base::Singleton<Foo>::get();'] diff_bad_h = ['Foo* foo = base::Singleton<Foo>::get();'] mock_input_api = MockInputApi() mock_input_api.files = [MockAffectedFile('base/memory/singleton.h', diff_singleton_h), MockAffectedFile('foo.h', diff_foo_h), + MockAffectedFile('foo2.h', diff_foo2_h), MockAffectedFile('bad.h', diff_bad_h)] warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, MockOutputApi()) self.assertEqual(1, len(warnings)) + self.assertEqual(2, len(warnings[0].items)) self.assertEqual('error', warnings[0].type) self.assertTrue('Found base::Singleton<T>' in warnings[0].message) @@ -414,15 +417,15 @@ class CheckSingletonInHeadersTest(unittest.TestCase): class CheckBaseMacrosInHeadersTest(unittest.TestCase): - def _make_h(self, macro, header): + def _make_h(self, macro, header, line_prefix=''): return (""" #include "base/%s.h" class Thing { private: - DISALLOW_%s(Thing); +%sDISALLOW_%s(Thing); }; -""" % (macro, header)).splitlines() +""" % (macro, line_prefix, header)).splitlines() def testBaseMacrosInHeadersBad(self): mock_input_api = MockInputApi() @@ -444,6 +447,8 @@ class Thing { MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')), + MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', '//')), + MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', ' //')), ] warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, MockOutputApi()) |