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

Unified Diff: PRESUBMIT_test.py

Issue 2598173002: Add a Presubmit to check if a file must be included or imported.
Patch Set: feedback Created 3 years, 11 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') | no next file » | 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 7f3ee91a4bbdbd2d71952a974c6e0e810ffdb21e..d49841808792fa4b8d37f90e302e521317f6f364 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -13,6 +13,120 @@ from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi
_TEST_DATA_DIR = 'base/test/data/presubmit'
+class IncludeImportTest(unittest.TestCase):
+ def testDetectObjectiveCHeaderInterface(self):
+ content = ['# Copyright line',
+ '',
+ '@interface Class']
+ mock_input_api = MockInputApi()
+ mock_name = 'some/ios/foo.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, True)
+ self.assertEqual(is_objc, True)
+
+ def testDetectObjectiveCNotIosMacFile(self):
+ content = ['# Copyright line',
+ '',
+ '@interface Class']
+ mock_input_api = MockInputApi()
+ mock_name = 'some/bar/foo.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, False)
+ self.assertEqual(is_objc, False)
+
+
+ def testDetectObjectiveCBlock(self):
+ content = ['# Copyright line',
+ '',
+ 'typedef void (^ProceduralBlock)(void);']
+ mock_input_api = MockInputApi()
+ mock_name = 'some/path/foo_mac.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, True)
+ self.assertEqual(is_objc, True)
+
+ def testDetectObjectiveCImport(self):
+ content = ['# Copyright line',
+ '',
+ '#include "foo.h',
+ '#include "bar.h',
+ '#import "example.h',
+ '#include "chromium.h']
+ mock_input_api = MockInputApi()
+ mock_name = 'some/mac/foo.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, True)
+ self.assertEqual(is_objc, True)
+
+ def testDetectObjectiveCHeaderCPlusPlus(self):
+ content = ['# Copyright line',
+ '',
+ '#include <cstdio>',
+ 'class Foo']
+ mock_input_api = MockInputApi()
+ mock_name = 'some/path/foo_ios.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, True)
+ self.assertEqual(is_objc, False)
+
+ def testDetectObjectiveCHeaderCPlusPlus(self):
+ content = ['# Copyright line',
+ '',
+ '#if !defined(__OBJC__)',
+ '#error "ObjectiveC required"',
+ '#endif',
+ '',
+ '#include <cstdio>',
+ 'class Foo']
+ mock_input_api = MockInputApi()
+ mock_name = 'ios/path/foo.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, True)
+ self.assertEqual(is_objc, True)
+
+ def testDetectObjectiveCNoObjcGuard(self):
+ content = ['# Copyright line',
+ '',
+ '#if !defined(__OBJC__)',
+ '#include "foo.h"',
+ '#else',
+ '#import "foo.h"',
+ '#endif']
+ mock_input_api = MockInputApi()
+ mock_name = 'mac/path/foo.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, False)
+
+
+ def testDetectObjectiveCNoObjcGuard(self):
+ content = ['# Copyright line',
+ '',
+ '#if defined(__OBJC__)',
+ '#import "foo.h"',
+ '#else',
+ '#include "foo.h"',
+ '#endif']
+ mock_input_api = MockInputApi()
+ mock_name = 'some/path_ios/foo.h'
+ mock_file = MockFile(mock_name, content)
+ (detection_ok, is_objc) = \
+ PRESUBMIT._CheckHeaderIsObjectiveC(mock_input_api, mock_name, mock_file)
+ self.assertEqual(detection_ok, False)
+
class IncludeOrderTest(unittest.TestCase):
def testSystemHeaderOrder(self):
scope = [(1, '#include <csystem.h>'),
« 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