OLD | NEW |
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 Loading... |
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 | |
414 class InvalidOSMacroNamesTest(unittest.TestCase): | 387 class InvalidOSMacroNamesTest(unittest.TestCase): |
415 def testInvalidOSMacroNames(self): | 388 def testInvalidOSMacroNames(self): |
416 lines = ['#if defined(OS_WINDOWS)', | 389 lines = ['#if defined(OS_WINDOWS)', |
417 ' #elif defined(OS_WINDOW)', | 390 ' #elif defined(OS_WINDOW)', |
418 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', | 391 ' # if defined(OS_MACOSX) || defined(OS_CHROME)', |
419 '# else // defined(OS_MAC)', | 392 '# else // defined(OS_MAC)', |
420 '#endif // defined(OS_MACOS)'] | 393 '#endif // defined(OS_MACOS)'] |
421 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( | 394 errors = PRESUBMIT._CheckForInvalidOSMacrosInFile( |
422 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) | 395 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) |
423 self.assertEqual(len(lines), len(errors)) | 396 self.assertEqual(len(lines), len(errors)) |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 } | 755 } |
783 for master, bots in bots.iteritems(): | 756 for master, bots in bots.iteritems(): |
784 for bot in bots: | 757 for bot in bots: |
785 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), | 758 self.assertEqual(master, PRESUBMIT.GetTryServerMasterForBot(bot), |
786 'bot=%s: expected %s, computed %s' % ( | 759 'bot=%s: expected %s, computed %s' % ( |
787 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) | 760 bot, master, PRESUBMIT.GetTryServerMasterForBot(bot))) |
788 | 761 |
789 | 762 |
790 if __name__ == '__main__': | 763 if __name__ == '__main__': |
791 unittest.main() | 764 unittest.main() |
OLD | NEW |