summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PRESUBMIT.py4
-rwxr-xr-xPRESUBMIT_test.py11
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())