summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT_test.py
diff options
context:
space:
mode:
authorglider <glider@chromium.org>2015-02-17 01:26:17 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-17 09:27:05 +0000
commit9b73d0393037452d13358f4e2766cb62adbdede8 (patch)
treece0fd484336ea2c3535081abed9c6647a179e903 /PRESUBMIT_test.py
parente8687ac4a2cc7836251226cf17d05f3682795e49 (diff)
downloadchromium_src-9b73d0393037452d13358f4e2766cb62adbdede8.zip
chromium_src-9b73d0393037452d13358f4e2766cb62adbdede8.tar.gz
chromium_src-9b73d0393037452d13358f4e2766cb62adbdede8.tar.bz2
Add a presubmit check that warns about declaring Singleton<T> in header files
(except for base/memory/singleton.h) This check is copied from presubmit_canned_checks.py in depot_tools/ with an added exception for base/memory/singleton.h. The corresponding code will be removed from presubmit_canned_checks.py afterwards. BUG=349861 R=phajdan.jr@chromium.org, Review URL: https://codereview.chromium.org/929043002 Cr-Commit-Position: refs/heads/master@{#316546}
Diffstat (limited to 'PRESUBMIT_test.py')
-rwxr-xr-xPRESUBMIT_test.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 00997b4..7de0c3b 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -384,6 +384,33 @@ class BadExtensionsTest(unittest.TestCase):
self.assertEqual({}, results)
+class CheckSingletonInHeadersTest(unittest.TestCase):
+ def testSingletonInArbitraryHeader(self):
+ diff_singleton_h = ['base::subtle::AtomicWord '
+ 'Singleton<Type, Traits, DifferentiatingType>::']
+ diff_foo_h = ['// Singleton<Foo> in comment.',
+ 'friend class Singleton<Foo>']
+ diff_bad_h = ['Foo* foo = Singleton<Foo>::get();']
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [MockFile('base/memory/singleton.h',
+ diff_singleton_h),
+ MockFile('foo.h', diff_foo_h),
+ MockFile('bad.h', diff_bad_h)]
+ warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
+ MockOutputApi())
+ self.assertEqual(1, len(warnings))
+ self.assertEqual('error', warnings[0].type)
+ self.assertTrue('Found Singleton<T>' in warnings[0].message)
+
+ def testSingletonInCC(self):
+ diff_cc = ['Foo* foo = Singleton<Foo>::get();']
+ mock_input_api = MockInputApi()
+ mock_input_api.files = [MockFile('some/path/foo.cc', diff_cc)]
+ warnings = PRESUBMIT._CheckSingletonInHeaders(mock_input_api,
+ MockOutputApi())
+ self.assertEqual(0, len(warnings))
+
+
class InvalidOSMacroNamesTest(unittest.TestCase):
def testInvalidOSMacroNames(self):
lines = ['#if defined(OS_WINDOWS)',