diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 16:38:43 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 16:38:43 +0000 |
commit | ac294a1800342deca5407ef4ebe12016f3ce6be3 (patch) | |
tree | f021ebef766a9a845e460a286888112aab4e6013 /PRESUBMIT_test.py | |
parent | 4aec5d3d6520115c2f7626cb7337f4b69e63018f (diff) | |
download | chromium_src-ac294a1800342deca5407ef4ebe12016f3ce6be3.zip chromium_src-ac294a1800342deca5407ef4ebe12016f3ce6be3.tar.gz chromium_src-ac294a1800342deca5407ef4ebe12016f3ce6be3.tar.bz2 |
PRESUBMIT #include check enhancements.
1) Handle #define and #undef the same way as #if etc. See e.g.,
https://codereview.chromium.org/11363222/diff/10015/chrome/browser/history/history_unittest.cc
line 545.
2) Also headers can have the special first include, not only sources. See e.g.,
net/disk_cache/storage_block-inl.h.
NOTRY=true
BUG=NONE
Review URL: https://chromiumcodereview.appspot.com/11441035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171511 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT_test.py')
-rwxr-xr-x | PRESUBMIT_test.py | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index debe33b..9bc7db5 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): |