Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: PRESUBMIT_test.py

Issue 1413263002: Changed the CheckBaseMacrosInHeaders presubmit to pass over C++ comments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import glob 6 import glob
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 import subprocess 10 import subprocess
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi()) 385 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
386 self.assertEqual(0, len(results)) 386 self.assertEqual(0, len(results))
387 387
388 388
389 class CheckSingletonInHeadersTest(unittest.TestCase): 389 class CheckSingletonInHeadersTest(unittest.TestCase):
390 def testSingletonInArbitraryHeader(self): 390 def testSingletonInArbitraryHeader(self):
391 diff_singleton_h = ['base::subtle::AtomicWord ' 391 diff_singleton_h = ['base::subtle::AtomicWord '
392 'base::Singleton<Type, Traits, DifferentiatingType>::'] 392 'base::Singleton<Type, Traits, DifferentiatingType>::']
393 diff_foo_h = ['// base::Singleton<Foo> in comment.', 393 diff_foo_h = ['// base::Singleton<Foo> in comment.',
394 'friend class base::Singleton<Foo>'] 394 'friend class base::Singleton<Foo>']
395 diff_foo2_h = [' //Foo* bar = base::Singleton<Foo>::get();']
395 diff_bad_h = ['Foo* foo = base::Singleton<Foo>::get();'] 396 diff_bad_h = ['Foo* foo = base::Singleton<Foo>::get();']
396 mock_input_api = MockInputApi() 397 mock_input_api = MockInputApi()
397 mock_input_api.files = [MockAffectedFile('base/memory/singleton.h', 398 mock_input_api.files = [MockAffectedFile('base/memory/singleton.h',
398 diff_singleton_h), 399 diff_singleton_h),
399 MockAffectedFile('foo.h', diff_foo_h), 400 MockAffectedFile('foo.h', diff_foo_h),
401 MockAffectedFile('foo2.h', diff_foo2_h),
400 MockAffectedFile('bad.h', diff_bad_h)] 402 MockAffectedFile('bad.h', diff_bad_h)]
401 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, 403 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
402 MockOutputApi()) 404 MockOutputApi())
403 self.assertEqual(1, len(warnings)) 405 self.assertEqual(1, len(warnings))
406 self.assertEqual(2, len(warnings[0].items))
404 self.assertEqual('error', warnings[0].type) 407 self.assertEqual('error', warnings[0].type)
405 self.assertTrue('Found base::Singleton<T>' in warnings[0].message) 408 self.assertTrue('Found base::Singleton<T>' in warnings[0].message)
406 409
407 def testSingletonInCC(self): 410 def testSingletonInCC(self):
408 diff_cc = ['Foo* foo = base::Singleton<Foo>::get();'] 411 diff_cc = ['Foo* foo = base::Singleton<Foo>::get();']
409 mock_input_api = MockInputApi() 412 mock_input_api = MockInputApi()
410 mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)] 413 mock_input_api.files = [MockAffectedFile('some/path/foo.cc', diff_cc)]
411 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api, 414 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
412 MockOutputApi()) 415 MockOutputApi())
413 self.assertEqual(0, len(warnings)) 416 self.assertEqual(0, len(warnings))
414 417
415 418
416 class CheckBaseMacrosInHeadersTest(unittest.TestCase): 419 class CheckBaseMacrosInHeadersTest(unittest.TestCase):
417 def _make_h(self, macro, header): 420 def _make_h(self, macro, header, line_prefix=''):
418 return (""" 421 return ("""
419 #include "base/%s.h" 422 #include "base/%s.h"
420 423
421 class Thing { 424 class Thing {
422 private: 425 private:
423 DISALLOW_%s(Thing); 426 %sDISALLOW_%s(Thing);
424 }; 427 };
425 """ % (macro, header)).splitlines() 428 """ % (macro, line_prefix, header)).splitlines()
426 429
427 def testBaseMacrosInHeadersBad(self): 430 def testBaseMacrosInHeadersBad(self):
428 mock_input_api = MockInputApi() 431 mock_input_api = MockInputApi()
429 mock_input_api.files = [ 432 mock_input_api.files = [
430 MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')), 433 MockAffectedFile('foo.h', self._make_h('not_macros', 'ASSIGN')),
431 MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')), 434 MockAffectedFile('bar.h', self._make_h('not_macros', 'COPY')),
432 MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')), 435 MockAffectedFile('baz.h', self._make_h('not_macros', 'COPY_AND_ASSIGN')),
433 MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')), 436 MockAffectedFile('qux.h', self._make_h('not_macros', 'EVIL')),
434 ] 437 ]
435 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, 438 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api,
436 MockOutputApi()) 439 MockOutputApi())
437 self.assertEqual(1, len(warnings)) 440 self.assertEqual(1, len(warnings))
438 self.assertEqual(4, len(warnings[0].items)) 441 self.assertEqual(4, len(warnings[0].items))
439 442
440 def testBaseMacrosInHeadersGood(self): 443 def testBaseMacrosInHeadersGood(self):
441 mock_input_api = MockInputApi() 444 mock_input_api = MockInputApi()
442 mock_input_api.files = [ 445 mock_input_api.files = [
443 MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')), 446 MockAffectedFile('foo.h', self._make_h('macros', 'ASSIGN')),
444 MockAffectedFile('bar.h', self._make_h('macros', 'COPY')), 447 MockAffectedFile('bar.h', self._make_h('macros', 'COPY')),
445 MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')), 448 MockAffectedFile('baz.h', self._make_h('macros', 'COPY_AND_ASSIGN')),
446 MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')), 449 MockAffectedFile('qux.h', self._make_h('macros', 'EVIL')),
450 MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', '//')),
451 MockAffectedFile('foz.h', self._make_h('not_macros', 'ASSIGN', ' //')),
447 ] 452 ]
448 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api, 453 warnings = PRESUBMIT._CheckBaseMacrosInHeaders(mock_input_api,
449 MockOutputApi()) 454 MockOutputApi())
450 self.assertEqual(0, len(warnings)) 455 self.assertEqual(0, len(warnings))
451 456
452 457
453 class InvalidOSMacroNamesTest(unittest.TestCase): 458 class InvalidOSMacroNamesTest(unittest.TestCase):
454 def testInvalidOSMacroNames(self): 459 def testInvalidOSMacroNames(self):
455 lines = ['#if defined(OS_WINDOWS)', 460 lines = ['#if defined(OS_WINDOWS)',
456 ' #elif defined(OS_WINDOW)', 461 ' #elif defined(OS_WINDOW)',
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 # Tag must not contain 982 # Tag must not contain
978 nb = len(msgs[4].items) 983 nb = len(msgs[4].items)
979 self.assertEqual(2, nb, 984 self.assertEqual(2, nb,
980 'Expected %d items, found %d: %s' % (2, nb, msgs[4].items)) 985 'Expected %d items, found %d: %s' % (2, nb, msgs[4].items))
981 self.assertTrue('HasDottedTag.java' in msgs[4].items) 986 self.assertTrue('HasDottedTag.java' in msgs[4].items)
982 self.assertTrue('HasOldTag.java' in msgs[4].items) 987 self.assertTrue('HasOldTag.java' in msgs[4].items)
983 988
984 989
985 if __name__ == '__main__': 990 if __name__ == '__main__':
986 unittest.main() 991 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698