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

Side by Side Diff: PRESUBMIT_test.py

Issue 929043002: Add a presubmit check that warns about declaring Singleton<T> in header files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added presubmit test Created 5 years, 10 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') | PRESUBMIT_test_mocks.py » ('j') | 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 def testOnlyOwnersFiles(self): 378 def testOnlyOwnersFiles(self):
379 mock_change = MockChange([ 379 mock_change = MockChange([
380 'some/path/OWNERS', 380 'some/path/OWNERS',
381 'A\Windows\Path\OWNERS', 381 'A\Windows\Path\OWNERS',
382 ]) 382 ])
383 results = PRESUBMIT.GetPreferredTryMasters(None, mock_change) 383 results = PRESUBMIT.GetPreferredTryMasters(None, mock_change)
384 self.assertEqual({}, results) 384 self.assertEqual({}, results)
385 385
386 386
387 class CheckSingletonInHeadersTest(unittest.TestCase):
388 def testSingletonInArbitraryHeader(self):
389 diff_singleton_h = ['base::subtle::AtomicWord '
390 'Singleton<Type, Traits, DifferentiatingType>::']
391 diff_foo_h = ['// Singleton<Foo> in comment.',
392 'friend class Singleton<Foo>']
393 diff_bad_h = ['Foo* foo = Singleton<Foo>::get();']
394 mock_input_api = MockInputApi()
395 mock_input_api.files = [MockFile('base/memory/singleton.h',
396 diff_singleton_h),
397 MockFile('foo.h', diff_foo_h),
398 MockFile('bad.h', diff_bad_h)]
399 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
400 MockOutputApi())
401 self.assertEqual(1, len(warnings))
402 self.assertEqual('error', warnings[0].type)
403 self.assertTrue('Found Singleton<T>' in warnings[0].message)
404
405 def testSingletonInCC(self):
406 diff_cc = ['Foo* foo = Singleton<Foo>::get();']
407 mock_input_api = MockInputApi()
408 mock_input_api.files = [MockFile('some/path/foo.cc', diff_cc)]
409 warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
410 MockOutputApi())
411 self.assertEqual(0, len(warnings))
412
413
387 class InvalidOSMacroNamesTest(unittest.TestCase): 414 class InvalidOSMacroNamesTest(unittest.TestCase):
388 def testInvalidOSMacroNames(self): 415 def testInvalidOSMacroNames(self):
389 lines = ['#if defined(OS_WINDOWS)', 416 lines = ['#if defined(OS_WINDOWS)',
390 ' #elif defined(OS_WINDOW)', 417 ' #elif defined(OS_WINDOW)',
391 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', 418 ' # if defined(OS_MACOSX) || defined(OS_CHROME)',
392 '# else // defined(OS_MAC)', 419 '# else // defined(OS_MAC)',
393 '#endif // defined(OS_MACOS)'] 420 '#endif // defined(OS_MACOS)']
394 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( 421 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile(
395 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 422 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
396 self.assertEqual(len(lines), len(errors)) 423 self.assertEqual(len(lines), len(errors))
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 } 782 }
756 for master, bots in bots.iteritems(): 783 for master, bots in bots.iteritems():
757 for bot in bots: 784 for bot in bots:
758 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), 785 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot),
759 'bot=%s: expected %s, computed %s' % ( 786 'bot=%s: expected %s, computed %s' % (
760 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) 787 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot)))
761 788
762 789
763 if __name__ == '__main__': 790 if __name__ == '__main__':
764 unittest.main() 791 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | PRESUBMIT_test_mocks.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698