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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | PRESUBMIT_test_mocks.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT_test.py
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index 00997b43e8a170ecb8b3e1f30b1a14051424d013..7de0c3b61f5da2e8ec7d46c2f532477223a6d3ef 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)',
« 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