diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-18 14:34:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-04 11:15:27 +0000 |
commit | e6430e577f105ad8813c92e75c54660c4985026e (patch) | |
tree | 88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/PRESUBMIT_test.py | |
parent | 53d399fe6415a96ea6986ec0d402a9c07da72453 (diff) | |
download | qtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz |
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/PRESUBMIT_test.py')
-rwxr-xr-x | chromium/PRESUBMIT_test.py | 302 |
1 files changed, 63 insertions, 239 deletions
diff --git a/chromium/PRESUBMIT_test.py b/chromium/PRESUBMIT_test.py index 3fff4a2f252..eac824bf5a8 100755 --- a/chromium/PRESUBMIT_test.py +++ b/chromium/PRESUBMIT_test.py @@ -14,245 +14,6 @@ from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi _TEST_DATA_DIR = 'base/test/data/presubmit' -class IncludeOrderTest(unittest.TestCase): - def testSystemHeaderOrder(self): - scope = [(1, '#include <csystem.h>'), - (2, '#include <cppsystem>'), - (3, '#include "acustom.h"')] - all_linenums = [linenum for (linenum, _) in scope] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', all_linenums) - self.assertEqual(0, len(warnings)) - - def testSystemHeaderOrderMismatch1(self): - scope = [(10, '#include <cppsystem>'), - (20, '#include <csystem.h>'), - (30, '#include "acustom.h"')] - all_linenums = [linenum for (linenum, _) in scope] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', all_linenums) - self.assertEqual(1, len(warnings)) - self.assertTrue('20' in warnings[0]) - - def testSystemHeaderOrderMismatch2(self): - scope = [(10, '#include <cppsystem>'), - (20, '#include "acustom.h"'), - (30, '#include <csystem.h>')] - all_linenums = [linenum for (linenum, _) in scope] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', all_linenums) - self.assertEqual(1, len(warnings)) - self.assertTrue('30' in warnings[0]) - - def testSystemHeaderOrderMismatch3(self): - scope = [(10, '#include "acustom.h"'), - (20, '#include <csystem.h>'), - (30, '#include <cppsystem>')] - all_linenums = [linenum for (linenum, _) in scope] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', all_linenums) - self.assertEqual(2, len(warnings)) - self.assertTrue('20' in warnings[0]) - self.assertTrue('30' in warnings[1]) - - def testAlphabeticalOrderMismatch(self): - scope = [(10, '#include <csystem.h>'), - (15, '#include <bsystem.h>'), - (20, '#include <cppsystem>'), - (25, '#include <bppsystem>'), - (30, '#include "bcustom.h"'), - (35, '#include "acustom.h"')] - all_linenums = [linenum for (linenum, _) in scope] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', all_linenums) - self.assertEqual(3, len(warnings)) - self.assertTrue('15' in warnings[0]) - self.assertTrue('25' in warnings[1]) - self.assertTrue('35' in warnings[2]) - - def testSpecialFirstInclude1(self): - mock_input_api = MockInputApi() - contents = ['#include "some/path/foo.h"', - '#include "a/header.h"'] - mock_file = MockFile('some/path/foo.cc', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(0, len(warnings)) - - def testSpecialFirstInclude2(self): - mock_input_api = MockInputApi() - contents = ['#include "some/other/path/foo.h"', - '#include "a/header.h"'] - mock_file = MockFile('some/path/foo.cc', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(0, len(warnings)) - - def testSpecialFirstInclude3(self): - mock_input_api = MockInputApi() - contents = ['#include "some/path/foo.h"', - '#include "a/header.h"'] - mock_file = MockFile('some/path/foo_platform.cc', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(0, len(warnings)) - - def testSpecialFirstInclude4(self): - mock_input_api = MockInputApi() - contents = ['#include "some/path/bar.h"', - '#include "a/header.h"'] - mock_file = MockFile('some/path/foo_platform.cc', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - 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 testSpecialFirstInclude6(self): - mock_input_api = MockInputApi() - contents = ['#include "some/other/path/foo_win.h"', - '#include <set>', - '#include "a/header.h"'] - mock_file = MockFile('some/path/foo_unittest_win.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"'), - (3, '#include "c.h"')] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', [3]) - self.assertEqual(0, len(warnings)) - - def testConflictAdded1(self): - scope = [(1, '#include "a.h"'), - (2, '#include "c.h"'), - (3, '#include "b.h"')] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', [2]) - self.assertEqual(1, len(warnings)) - self.assertTrue('3' in warnings[0]) - - def testConflictAdded2(self): - scope = [(1, '#include "c.h"'), - (2, '#include "b.h"'), - (3, '#include "d.h"')] - mock_input_api = MockInputApi() - warnings = PRESUBMIT._CheckIncludeOrderForScope(scope, mock_input_api, - '', [2]) - self.assertEqual(1, len(warnings)) - self.assertTrue('2' in warnings[0]) - - 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', - '#include "c.h"', - '#else', - '#include "b.h"', - '#endif', - '#include "a.h"'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(0, len(warnings)) - - def testExcludedIncludes(self): - # #include <sys/...>'s can appear in any order. - mock_input_api = MockInputApi() - contents = ['#include <sys/b.h>', - '#include <sys/a.h>'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(0, len(warnings)) - - contents = ['#include <atlbase.h>', - '#include <aaa.h>'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(0, len(warnings)) - - contents = ['#include "build/build_config.h"', - '#include "aaa.h"'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - 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)) - self.assertEqual('promptOrNotify', warnings[0].type) - - def testUncheckableIncludes(self): - mock_input_api = MockInputApi() - contents = ['#include <windows.h>', - '#include "b.h"', - '#include "a.h"'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(1, len(warnings)) - - contents = ['#include "gpu/command_buffer/gles_autogen.h"', - '#include "b.h"', - '#include "a.h"'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(1, len(warnings)) - - contents = ['#include "gl_mock_autogen.h"', - '#include "b.h"', - '#include "a.h"'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(1, len(warnings)) - - contents = ['#include "ipc/some_macros.h"', - '#include "b.h"', - '#include "a.h"'] - mock_file = MockFile('', contents) - warnings = PRESUBMIT._CheckIncludeOrderInFile( - mock_input_api, mock_file, range(1, len(contents) + 1)) - self.assertEqual(1, len(warnings)) - - class VersionControlConflictsTest(unittest.TestCase): def testTypicalConflict(self): lines = ['<<<<<<< HEAD', @@ -1323,6 +1084,69 @@ class RiskyJsTest(unittest.TestCase): mock_input_api, MockOutputApi()) self.assertEqual(0, len(warnings)) +class RelativeIncludesTest(unittest.TestCase): + def testThirdPartyNotWebKitIgnored(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockAffectedFile('third_party/test.cpp', '#include "../header.h"'), + MockAffectedFile('third_party/test/test.cpp', '#include "../header.h"'), + ] + + mock_output_api = MockOutputApi() + + errors = PRESUBMIT._CheckForRelativeIncludes( + mock_input_api, mock_output_api) + self.assertEqual(0, len(errors)) + + def testNonCppFileIgnored(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockAffectedFile('test.py', '#include "../header.h"'), + ] + + mock_output_api = MockOutputApi() + + errors = PRESUBMIT._CheckForRelativeIncludes( + mock_input_api, mock_output_api) + self.assertEqual(0, len(errors)) + + def testInnocuousChangesAllowed(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockAffectedFile('test.cpp', '#include "header.h"'), + MockAffectedFile('test2.cpp', '../'), + ] + + mock_output_api = MockOutputApi() + + errors = PRESUBMIT._CheckForRelativeIncludes( + mock_input_api, mock_output_api) + self.assertEqual(0, len(errors)) + + def testRelativeIncludeNonWebKitProducesError(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockAffectedFile('test.cpp', ['#include "../header.h"']), + ] + + mock_output_api = MockOutputApi() + + errors = PRESUBMIT._CheckForRelativeIncludes( + mock_input_api, mock_output_api) + self.assertEqual(1, len(errors)) + + def testRelativeIncludeWebKitProducesError(self): + mock_input_api = MockInputApi() + mock_input_api.files = [ + MockAffectedFile('third_party/WebKit/test.cpp', + ['#include "../header.h']), + ] + + mock_output_api = MockOutputApi() + + errors = PRESUBMIT._CheckForRelativeIncludes( + mock_input_api, mock_output_api) + self.assertEqual(1, len(errors)) if __name__ == '__main__': unittest.main() |