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

Unified Diff: PRESUBMIT_test.py

Issue 11441035: PRESUBMIT #include check enhancements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years 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 debe33b899bae74da065b2f5d14e5e875127cd01..9bc7db5dd2f1e4e4a5d3d936dea2f227e47646dc 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -28,13 +28,16 @@ class MockOutputApi(object):
self.long_text = long_text
class PresubmitError(PresubmitResult):
- pass
+ def __init__(self, message, items, long_text=''):
+ MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
class PresubmitPromptWarning(PresubmitResult):
- pass
+ def __init__(self, message, items, long_text=''):
+ MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
class PresubmitNotifyResult(PresubmitResult):
- pass
+ def __init__(self, message, items, long_text=''):
+ MockOutputApi.PresubmitResult.__init__(self, message, items, long_text)
class MockFile(object):
@@ -120,7 +123,7 @@ class IncludeOrderTest(unittest.TestCase):
'#include "a/header.h"']
mock_file = MockFile('some/path/foo.cc', contents)
warnings = PRESUBMIT._CheckIncludeOrderInFile(
- mock_input_api, mock_file, True, range(1, len(contents) + 1))
+ mock_input_api, mock_file, range(1, len(contents) + 1))
self.assertEqual(0, len(warnings))
def testSpecialFirstInclude2(self):
@@ -129,7 +132,7 @@ class IncludeOrderTest(unittest.TestCase):
'#include "a/header.h"']
mock_file = MockFile('some/path/foo.cc', contents)
warnings = PRESUBMIT._CheckIncludeOrderInFile(
- mock_input_api, mock_file, True, range(1, len(contents) + 1))
+ mock_input_api, mock_file, range(1, len(contents) + 1))
self.assertEqual(0, len(warnings))
def testSpecialFirstInclude3(self):
@@ -138,7 +141,7 @@ class IncludeOrderTest(unittest.TestCase):
'#include "a/header.h"']
mock_file = MockFile('some/path/foo_platform.cc', contents)
warnings = PRESUBMIT._CheckIncludeOrderInFile(
- mock_input_api, mock_file, True, range(1, len(contents) + 1))
+ mock_input_api, mock_file, range(1, len(contents) + 1))
self.assertEqual(0, len(warnings))
def testSpecialFirstInclude4(self):
@@ -147,10 +150,19 @@ class IncludeOrderTest(unittest.TestCase):
'#include "a/header.h"']
mock_file = MockFile('some/path/foo_platform.cc', contents)
warnings = PRESUBMIT._CheckIncludeOrderInFile(
- mock_input_api, mock_file, True, range(1, len(contents) + 1))
+ mock_input_api, mock_file, range(1, len(contents) + 1))
self.assertEqual(1, len(warnings))
self.assertTrue('2' in warnings[0])
+ def testSpecialFirstInclude5(self):
+ mock_input_api = MockInputApi()
+ contents = ['#include "some/other/path/foo.h"',
+ '#include "a/header.h"']
+ mock_file = MockFile('some/path/foo-suffix.h', contents)
+ warnings = PRESUBMIT._CheckIncludeOrderInFile(
+ mock_input_api, mock_file, range(1, len(contents) + 1))
+ self.assertEqual(0, len(warnings))
+
def testOrderAlreadyWrong(self):
scope = [(1, '#include "b.h"'),
(2, '#include "a.h"'),
@@ -183,6 +195,10 @@ class IncludeOrderTest(unittest.TestCase):
def testIfElifElseEndif(self):
mock_input_api = MockInputApi()
contents = ['#include "e.h"',
+ '#define foo',
+ '#include "f.h"',
+ '#undef foo',
+ '#include "e.h"',
'#if foo',
'#include "d.h"',
'#elif bar',
@@ -193,7 +209,7 @@ class IncludeOrderTest(unittest.TestCase):
'#include "a.h"']
mock_file = MockFile('', contents)
warnings = PRESUBMIT._CheckIncludeOrderInFile(
- mock_input_api, mock_file, True, range(1, len(contents) + 1))
+ mock_input_api, mock_file, range(1, len(contents) + 1))
self.assertEqual(0, len(warnings))
def testSysIncludes(self):
@@ -203,9 +219,22 @@ class IncludeOrderTest(unittest.TestCase):
'#include <sys/a.h>']
mock_file = MockFile('', contents)
warnings = PRESUBMIT._CheckIncludeOrderInFile(
- mock_input_api, mock_file, True, range(1, len(contents) + 1))
+ mock_input_api, mock_file, range(1, len(contents) + 1))
self.assertEqual(0, len(warnings))
+ def testCheckOnlyCFiles(self):
+ mock_input_api = MockInputApi()
+ mock_output_api = MockOutputApi()
+ contents = ['#include <b.h>',
+ '#include <a.h>']
+ mock_file_cc = MockFile('something.cc', contents)
+ mock_file_h = MockFile('something.h', contents)
+ mock_file_other = MockFile('something.py', contents)
+ mock_input_api.files = [mock_file_cc, mock_file_h, mock_file_other]
+ warnings = PRESUBMIT._CheckIncludeOrder(mock_input_api, mock_output_api)
+ self.assertEqual(1, len(warnings))
+ self.assertEqual(2, len(warnings[0].items))
+
class VersionControlerConflictsTest(unittest.TestCase):
def testTypicalConflict(self):
« 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