| OLD | NEW |
| 1 # -*- coding: utf-8; -*- | 1 # -*- coding: utf-8; -*- |
| 2 # | 2 # |
| 3 # Copyright (C) 2011 Google Inc. All rights reserved. | 3 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 # Copyright (C) 2009 Torch Mobile Inc. | 4 # Copyright (C) 2009 Torch Mobile Inc. |
| 5 # Copyright (C) 2009 Apple Inc. All rights reserved. | 5 # Copyright (C) 2009 Apple Inc. All rights reserved. |
| 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 7 # | 7 # |
| 8 # Redistribution and use in source and binary forms, with or without | 8 # Redistribution and use in source and binary forms, with or without |
| 9 # modification, are permitted provided that the following conditions are | 9 # modification, are permitted provided that the following conditions are |
| 10 # met: | 10 # met: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 import unittest | 41 import unittest |
| 42 | 42 |
| 43 import cpp as cpp_style | 43 import cpp as cpp_style |
| 44 from cpp import CppChecker | 44 from cpp import CppChecker |
| 45 from ..filter import FilterConfiguration | 45 from ..filter import FilterConfiguration |
| 46 from webkitpy.common.system.filesystem import FileSystem | 46 from webkitpy.common.system.filesystem import FileSystem |
| 47 | 47 |
| 48 # This class works as an error collector and replaces cpp_style.Error | 48 # This class works as an error collector and replaces cpp_style.Error |
| 49 # function for the unit tests. We also verify each category we see | 49 # function for the unit tests. We also verify each category we see |
| 50 # is in STYLE_CATEGORIES, to help keep that list up to date. | 50 # is in STYLE_CATEGORIES, to help keep that list up to date. |
| 51 |
| 52 |
| 51 class ErrorCollector: | 53 class ErrorCollector: |
| 52 _all_style_categories = CppChecker.categories | 54 _all_style_categories = CppChecker.categories |
| 53 # This is a list including all categories seen in any unit test. | 55 # This is a list including all categories seen in any unit test. |
| 54 _seen_style_categories = {} | 56 _seen_style_categories = {} |
| 55 | 57 |
| 56 def __init__(self, assert_fn, filter=None, lines_to_check=None): | 58 def __init__(self, assert_fn, filter=None, lines_to_check=None): |
| 57 """assert_fn: a function to call when we notice a problem. | 59 """assert_fn: a function to call when we notice a problem. |
| 58 filter: filters the errors that we are concerned about.""" | 60 filter: filters the errors that we are concerned about.""" |
| 59 self._assert_fn = assert_fn | 61 self._assert_fn = assert_fn |
| 60 self._errors = [] | 62 self._errors = [] |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 self.assertEqual(single_line_view.single_line, '""') | 177 self.assertEqual(single_line_view.single_line, '""') |
| 176 | 178 |
| 177 def test_create_skeleton_parameters(self): | 179 def test_create_skeleton_parameters(self): |
| 178 self.assertEqual(cpp_style.create_skeleton_parameters(''), '') | 180 self.assertEqual(cpp_style.create_skeleton_parameters(''), '') |
| 179 self.assertEqual(cpp_style.create_skeleton_parameters(' '), ' ') | 181 self.assertEqual(cpp_style.create_skeleton_parameters(' '), ' ') |
| 180 self.assertEqual(cpp_style.create_skeleton_parameters('long'), 'long,') | 182 self.assertEqual(cpp_style.create_skeleton_parameters('long'), 'long,') |
| 181 self.assertEqual(cpp_style.create_skeleton_parameters('const unsigned lo
ng int'), ' int,') | 183 self.assertEqual(cpp_style.create_skeleton_parameters('const unsigned lo
ng int'), ' int,') |
| 182 self.assertEqual(cpp_style.create_skeleton_parameters('long int*'), '
int ,') | 184 self.assertEqual(cpp_style.create_skeleton_parameters('long int*'), '
int ,') |
| 183 self.assertEqual(cpp_style.create_skeleton_parameters('PassRefPtr<Foo> a
'), 'PassRefPtr a,') | 185 self.assertEqual(cpp_style.create_skeleton_parameters('PassRefPtr<Foo> a
'), 'PassRefPtr a,') |
| 184 self.assertEqual(cpp_style.create_skeleton_parameters( | 186 self.assertEqual(cpp_style.create_skeleton_parameters( |
| 185 'ComplexTemplate<NestedTemplate1<MyClass1, MyClass2>, NestedTemp
late1<MyClass1, MyClass2> > param, int second'), | 187 'ComplexTemplate<NestedTemplate1<MyClass1, MyClass2>, NestedTemplate
1<MyClass1, MyClass2> > param, int second'), |
| 186 'ComplexTemplate
param, int second,') | 188 'ComplexTemplate
param, int second,') |
| 187 self.assertEqual(cpp_style.create_skeleton_parameters('int = 0, Namespac
e::Type& a'), 'int , Type a,') | 189 self.assertEqual(cpp_style.create_skeleton_parameters('int = 0, Namespac
e::Type& a'), 'int , Type a,') |
| 188 # Create skeleton parameters is a bit too aggressive with function varia
bles, but | 190 # Create skeleton parameters is a bit too aggressive with function varia
bles, but |
| 189 # it allows for parsing other parameters and declarations like this are
rare. | 191 # it allows for parsing other parameters and declarations like this are
rare. |
| 190 self.assertEqual(cpp_style.create_skeleton_parameters('void (*fn)(int a,
int b), Namespace::Type& a'), | 192 self.assertEqual(cpp_style.create_skeleton_parameters('void (*fn)(int a,
int b), Namespace::Type& a'), |
| 191 'void , Type a,') | 193 'void , Type a,') |
| 192 | 194 |
| 193 # This doesn't look like functions declarations but the simplifications
help to eliminate false positives. | 195 # This doesn't look like functions declarations but the simplifications
help to eliminate false positives. |
| 194 self.assertEqual(cpp_style.create_skeleton_parameters('b{d}'), 'b ,') | 196 self.assertEqual(cpp_style.create_skeleton_parameters('b{d}'), 'b ,') |
| 195 | 197 |
| 196 def test_find_parameter_name_index(self): | 198 def test_find_parameter_name_index(self): |
| 197 self.assertEqual(cpp_style.find_parameter_name_index(' int a '), 5) | 199 self.assertEqual(cpp_style.find_parameter_name_index(' int a '), 5) |
| 198 self.assertEqual(cpp_style.find_parameter_name_index(' PassRefPtr ')
, 16) | 200 self.assertEqual(cpp_style.find_parameter_name_index(' PassRefPtr ')
, 16) |
| 199 self.assertEqual(cpp_style.find_parameter_name_index('double'), 6) | 201 self.assertEqual(cpp_style.find_parameter_name_index('double'), 6) |
| 200 | 202 |
| 201 def test_parameter_list(self): | 203 def test_parameter_list(self): |
| (...skipping 15 matching lines...) Expand all Loading... |
| 217 self.assertEqual(parameter.name, expected_parameter['name']) | 219 self.assertEqual(parameter.name, expected_parameter['name']) |
| 218 self.assertEqual(parameter.row, expected_parameter['row']) | 220 self.assertEqual(parameter.row, expected_parameter['row']) |
| 219 index += 1 | 221 index += 1 |
| 220 self.assertEqual(index, len(expected_parameters)) | 222 self.assertEqual(index, len(expected_parameters)) |
| 221 | 223 |
| 222 def test_check_parameter_against_text(self): | 224 def test_check_parameter_against_text(self): |
| 223 error_collector = ErrorCollector(self.assertTrue) | 225 error_collector = ErrorCollector(self.assertTrue) |
| 224 parameter = cpp_style.Parameter('FooF ooF', 4, 1) | 226 parameter = cpp_style.Parameter('FooF ooF', 4, 1) |
| 225 self.assertFalse(cpp_style._check_parameter_name_against_text(parameter,
'FooF', error_collector)) | 227 self.assertFalse(cpp_style._check_parameter_name_against_text(parameter,
'FooF', error_collector)) |
| 226 self.assertEqual(error_collector.results(), | 228 self.assertEqual(error_collector.results(), |
| 227 'The parameter name "ooF" adds no information, so it s
hould be removed. [readability/parameter_name] [5]') | 229 'The parameter name "ooF" adds no information, so it sh
ould be removed. [readability/parameter_name] [5]') |
| 230 |
| 228 | 231 |
| 229 class CppStyleTestBase(unittest.TestCase): | 232 class CppStyleTestBase(unittest.TestCase): |
| 230 """Provides some useful helper functions for cpp_style tests. | 233 """Provides some useful helper functions for cpp_style tests. |
| 231 | 234 |
| 232 Attributes: | 235 Attributes: |
| 233 min_confidence: An integer that is the current minimum confidence | 236 min_confidence: An integer that is the current minimum confidence |
| 234 level for the tests. | 237 level for the tests. |
| 235 | 238 |
| 236 """ | 239 """ |
| 237 | 240 |
| 238 # FIXME: Refactor the unit tests so the confidence level is passed | 241 # FIXME: Refactor the unit tests so the confidence level is passed |
| 239 # explicitly, just like it is in the real code. | 242 # explicitly, just like it is in the real code. |
| 240 min_confidence = 1; | 243 min_confidence = 1 |
| 241 | 244 |
| 242 # Helper function to avoid needing to explicitly pass confidence | 245 # Helper function to avoid needing to explicitly pass confidence |
| 243 # in all the unit test calls to cpp_style.process_file_data(). | 246 # in all the unit test calls to cpp_style.process_file_data(). |
| 244 def process_file_data(self, filename, file_extension, lines, error, fs=None)
: | 247 def process_file_data(self, filename, file_extension, lines, error, fs=None)
: |
| 245 """Call cpp_style.process_file_data() with the min_confidence.""" | 248 """Call cpp_style.process_file_data() with the min_confidence.""" |
| 246 return cpp_style.process_file_data(filename, file_extension, lines, | 249 return cpp_style.process_file_data(filename, file_extension, lines, |
| 247 error, self.min_confidence, fs) | 250 error, self.min_confidence, fs) |
| 248 | 251 |
| 249 def perform_lint(self, code, filename, basic_error_rules, fs=None, lines_to_
check=None): | 252 def perform_lint(self, code, filename, basic_error_rules, fs=None, lines_to_
check=None): |
| 250 error_collector = ErrorCollector(self.assertTrue, FilterConfiguration(ba
sic_error_rules), lines_to_check) | 253 error_collector = ErrorCollector(self.assertTrue, FilterConfiguration(ba
sic_error_rules), lines_to_check) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 self.assertEqual(expected_message, self.perform_multi_line_lint(code, fi
le_extension)) | 329 self.assertEqual(expected_message, self.perform_multi_line_lint(code, fi
le_extension)) |
| 327 | 330 |
| 328 def assert_multi_line_lint_re(self, code, expected_message_re, file_name='fo
o.h'): | 331 def assert_multi_line_lint_re(self, code, expected_message_re, file_name='fo
o.h'): |
| 329 file_extension = file_name[file_name.rfind('.') + 1:] | 332 file_extension = file_name[file_name.rfind('.') + 1:] |
| 330 message = self.perform_multi_line_lint(code, file_extension) | 333 message = self.perform_multi_line_lint(code, file_extension) |
| 331 if not re.search(expected_message_re, message): | 334 if not re.search(expected_message_re, message): |
| 332 self.fail('Message was:\n' + message + 'Expected match to "' + expec
ted_message_re + '"') | 335 self.fail('Message was:\n' + message + 'Expected match to "' + expec
ted_message_re + '"') |
| 333 | 336 |
| 334 def assert_language_rules_check(self, file_name, code, expected_message, lin
es_to_check=None): | 337 def assert_language_rules_check(self, file_name, code, expected_message, lin
es_to_check=None): |
| 335 self.assertEqual(expected_message, | 338 self.assertEqual(expected_message, |
| 336 self.perform_language_rules_check(file_name, code, lin
es_to_check)) | 339 self.perform_language_rules_check(file_name, code, line
s_to_check)) |
| 337 | 340 |
| 338 def assert_include_what_you_use(self, code, expected_message): | 341 def assert_include_what_you_use(self, code, expected_message): |
| 339 self.assertEqual(expected_message, | 342 self.assertEqual(expected_message, |
| 340 self.perform_include_what_you_use(code)) | 343 self.perform_include_what_you_use(code)) |
| 341 | 344 |
| 342 def assert_blank_lines_check(self, lines, start_errors, end_errors): | 345 def assert_blank_lines_check(self, lines, start_errors, end_errors): |
| 343 error_collector = ErrorCollector(self.assertTrue) | 346 error_collector = ErrorCollector(self.assertTrue) |
| 344 self.process_file_data('foo.cpp', 'cpp', lines, error_collector) | 347 self.process_file_data('foo.cpp', 'cpp', lines, error_collector) |
| 345 self.assertEqual( | 348 self.assertEqual( |
| 346 start_errors, | 349 start_errors, |
| 347 error_collector.results().count( | 350 error_collector.results().count( |
| 348 'Blank line at the start of a code block. Is this needed?' | 351 'Blank line at the start of a code block. Is this needed?' |
| 349 ' [whitespace/blank_line] [2]')) | 352 ' [whitespace/blank_line] [2]')) |
| 350 self.assertEqual( | 353 self.assertEqual( |
| 351 end_errors, | 354 end_errors, |
| 352 error_collector.results().count( | 355 error_collector.results().count( |
| 353 'Blank line at the end of a code block. Is this needed?' | 356 'Blank line at the end of a code block. Is this needed?' |
| 354 ' [whitespace/blank_line] [3]')) | 357 ' [whitespace/blank_line] [3]')) |
| 355 | 358 |
| 356 def assert_positions_equal(self, position, tuple_position): | 359 def assert_positions_equal(self, position, tuple_position): |
| 357 """Checks if the two positions are equal. | 360 """Checks if the two positions are equal. |
| 358 | 361 |
| 359 position: a cpp_style.Position object. | 362 position: a cpp_style.Position object. |
| 360 tuple_position: a tuple (row, column) to compare against.""" | 363 tuple_position: a tuple (row, column) to compare against.""" |
| 361 self.assertEqual(position, cpp_style.Position(tuple_position[0], tuple_p
osition[1]), | 364 self.assertEqual(position, cpp_style.Position(tuple_position[0], tuple_p
osition[1]), |
| 362 'position %s, tuple_position %s' % (position, tuple_po
sition)) | 365 'position %s, tuple_position %s' % (position, tuple_pos
ition)) |
| 363 | 366 |
| 364 | 367 |
| 365 class FunctionDetectionTest(CppStyleTestBase): | 368 class FunctionDetectionTest(CppStyleTestBase): |
| 369 |
| 366 def perform_function_detection(self, lines, function_information, detection_
line=0): | 370 def perform_function_detection(self, lines, function_information, detection_
line=0): |
| 367 clean_lines = cpp_style.CleansedLines(lines) | 371 clean_lines = cpp_style.CleansedLines(lines) |
| 368 function_state = cpp_style._FunctionState(5) | 372 function_state = cpp_style._FunctionState(5) |
| 369 error_collector = ErrorCollector(self.assertTrue) | 373 error_collector = ErrorCollector(self.assertTrue) |
| 370 cpp_style.detect_functions(clean_lines, detection_line, function_state,
error_collector) | 374 cpp_style.detect_functions(clean_lines, detection_line, function_state,
error_collector) |
| 371 if not function_information: | 375 if not function_information: |
| 372 self.assertEqual(function_state.in_a_function, False) | 376 self.assertEqual(function_state.in_a_function, False) |
| 373 return | 377 return |
| 374 self.assertEqual(function_state.in_a_function, True) | 378 self.assertEqual(function_state.in_a_function, True) |
| 375 self.assertEqual(function_state.current_function, function_information['
name'] + '()') | 379 self.assertEqual(function_state.current_function, function_information['
name'] + '()') |
| 376 self.assertEqual(function_state.modifiers_and_return_type(), function_in
formation['modifiers_and_return_type']) | 380 self.assertEqual(function_state.modifiers_and_return_type(), function_in
formation['modifiers_and_return_type']) |
| 377 self.assertEqual(function_state.is_pure, function_information['is_pure']
) | 381 self.assertEqual(function_state.is_pure, function_information['is_pure']
) |
| 378 self.assertEqual(function_state.is_declaration, function_information['is
_declaration']) | 382 self.assertEqual(function_state.is_declaration, function_information['is
_declaration']) |
| 379 self.assert_positions_equal(function_state.function_name_start_position,
function_information['function_name_start_position']) | 383 self.assert_positions_equal(function_state.function_name_start_position, |
| 384 function_information['function_name_start_po
sition']) |
| 380 self.assert_positions_equal(function_state.parameter_start_position, fun
ction_information['parameter_start_position']) | 385 self.assert_positions_equal(function_state.parameter_start_position, fun
ction_information['parameter_start_position']) |
| 381 self.assert_positions_equal(function_state.parameter_end_position, funct
ion_information['parameter_end_position']) | 386 self.assert_positions_equal(function_state.parameter_end_position, funct
ion_information['parameter_end_position']) |
| 382 self.assert_positions_equal(function_state.body_start_position, function
_information['body_start_position']) | 387 self.assert_positions_equal(function_state.body_start_position, function
_information['body_start_position']) |
| 383 self.assert_positions_equal(function_state.end_position, function_inform
ation['end_position']) | 388 self.assert_positions_equal(function_state.end_position, function_inform
ation['end_position']) |
| 384 expected_parameters = function_information.get('parameter_list') | 389 expected_parameters = function_information.get('parameter_list') |
| 385 if expected_parameters: | 390 if expected_parameters: |
| 386 actual_parameters = function_state.parameter_list() | 391 actual_parameters = function_state.parameter_list() |
| 387 self.assertEqual(len(actual_parameters), len(expected_parameters)) | 392 self.assertEqual(len(actual_parameters), len(expected_parameters)) |
| 388 for index in range(len(expected_parameters)): | 393 for index in range(len(expected_parameters)): |
| 389 actual_parameter = actual_parameters[index] | 394 actual_parameter = actual_parameters[index] |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 self.assert_lint( | 892 self.assert_lint( |
| 888 'typedef void Func(int x);', | 893 'typedef void Func(int x);', |
| 889 '') | 894 '') |
| 890 self.assert_lint( | 895 self.assert_lint( |
| 891 'typedef void Func(int *x);', | 896 'typedef void Func(int *x);', |
| 892 '') | 897 '') |
| 893 | 898 |
| 894 def test_include_what_you_use_no_implementation_files(self): | 899 def test_include_what_you_use_no_implementation_files(self): |
| 895 code = 'std::vector<int> foo;' | 900 code = 'std::vector<int> foo;' |
| 896 self.assertEqual('Add #include <vector> for vector<>' | 901 self.assertEqual('Add #include <vector> for vector<>' |
| 897 ' [build/include_what_you_use] [4]', | 902 ' [build/include_what_you_use] [4]', |
| 898 self.perform_include_what_you_use(code, 'foo.h')) | 903 self.perform_include_what_you_use(code, 'foo.h')) |
| 899 self.assertEqual('', | 904 self.assertEqual('', |
| 900 self.perform_include_what_you_use(code, 'foo.cpp')) | 905 self.perform_include_what_you_use(code, 'foo.cpp')) |
| 901 | 906 |
| 902 def test_include_what_you_use(self): | 907 def test_include_what_you_use(self): |
| 903 self.assert_include_what_you_use( | 908 self.assert_include_what_you_use( |
| 904 '''#include <vector> | 909 '''#include <vector> |
| 905 std::vector<int> foo; | 910 std::vector<int> foo; |
| 906 ''', | 911 ''', |
| 907 '') | 912 '') |
| 908 self.assert_include_what_you_use( | 913 self.assert_include_what_you_use( |
| 909 '''#include <map> | 914 '''#include <map> |
| 910 std::pair<int,int> foo; | 915 std::pair<int,int> foo; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 void a(const std::multimap<int,string> &foobar); | 1005 void a(const std::multimap<int,string> &foobar); |
| 1001 ''', | 1006 ''', |
| 1002 'Add #include <map> for multimap<>' | 1007 'Add #include <map> for multimap<>' |
| 1003 ' [build/include_what_you_use] [4]') | 1008 ' [build/include_what_you_use] [4]') |
| 1004 self.assert_include_what_you_use( | 1009 self.assert_include_what_you_use( |
| 1005 '''#include <queue> | 1010 '''#include <queue> |
| 1006 void a(const std::priority_queue<int> &foobar); | 1011 void a(const std::priority_queue<int> &foobar); |
| 1007 ''', | 1012 ''', |
| 1008 '') | 1013 '') |
| 1009 self.assert_include_what_you_use( | 1014 self.assert_include_what_you_use( |
| 1010 '''#include "base/basictypes.h" | 1015 '''#include "base/basictypes.h" |
| 1011 #include "base/port.h" | 1016 #include "base/port.h" |
| 1012 #include <assert.h> | 1017 #include <assert.h> |
| 1013 #include <string> | 1018 #include <string> |
| 1014 #include <vector> | 1019 #include <vector> |
| 1015 vector<string> hajoa;''', '') | 1020 vector<string> hajoa;''', '') |
| 1016 self.assert_include_what_you_use( | 1021 self.assert_include_what_you_use( |
| 1017 '''#include <string> | 1022 '''#include <string> |
| 1018 int i = numeric_limits<int>::max() | 1023 int i = numeric_limits<int>::max() |
| 1019 ''', | 1024 ''', |
| 1020 'Add #include <limits> for numeric_limits<>' | 1025 'Add #include <limits> for numeric_limits<>' |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 # Make sure we find the headers with relative paths. | 1069 # Make sure we find the headers with relative paths. |
| 1065 mock_header_contents = [''] | 1070 mock_header_contents = [''] |
| 1066 message = self.perform_include_what_you_use( | 1071 message = self.perform_include_what_you_use( |
| 1067 '''#include "config.h" | 1072 '''#include "config.h" |
| 1068 #include "%s%sa.h" | 1073 #include "%s%sa.h" |
| 1069 | 1074 |
| 1070 std::set<int> foo;''' % (os.path.basename(os.getcwd()), os.pa
th.sep), | 1075 std::set<int> foo;''' % (os.path.basename(os.getcwd()), os.pa
th.sep), |
| 1071 filename='a.cpp', | 1076 filename='a.cpp', |
| 1072 fs=fs) | 1077 fs=fs) |
| 1073 self.assertEqual(message, 'Add #include <set> for set<> ' | 1078 self.assertEqual(message, 'Add #include <set> for set<> ' |
| 1074 '[build/include_what_you_use] [4]') | 1079 '[build/include_what_you_use] [4]') |
| 1075 finally: | 1080 finally: |
| 1076 fs.read_text_file = orig_read_text_file_fn | 1081 fs.read_text_file = orig_read_text_file_fn |
| 1077 | 1082 |
| 1078 def test_files_belong_to_same_module(self): | 1083 def test_files_belong_to_same_module(self): |
| 1079 f = cpp_style.files_belong_to_same_module | 1084 f = cpp_style.files_belong_to_same_module |
| 1080 self.assertEqual((True, ''), f('a.cpp', 'a.h')) | 1085 self.assertEqual((True, ''), f('a.cpp', 'a.h')) |
| 1081 self.assertEqual((True, ''), f('base/google.cpp', 'base/google.h')) | 1086 self.assertEqual((True, ''), f('base/google.cpp', 'base/google.h')) |
| 1082 self.assertEqual((True, ''), f('base/google_test.cpp', 'base/google.h')) | 1087 self.assertEqual((True, ''), f('base/google_test.cpp', 'base/google.h')) |
| 1083 self.assertEqual((True, ''), | 1088 self.assertEqual((True, ''), |
| 1084 f('base/google_unittest.cpp', 'base/google.h')) | 1089 f('base/google_unittest.cpp', 'base/google.h')) |
| 1085 self.assertEqual((True, ''), | 1090 self.assertEqual((True, ''), |
| 1086 f('base/internal/google_unittest.cpp', | 1091 f('base/internal/google_unittest.cpp', |
| 1087 'base/public/google.h')) | 1092 'base/public/google.h')) |
| 1088 self.assertEqual((True, 'xxx/yyy/'), | 1093 self.assertEqual((True, 'xxx/yyy/'), |
| 1089 f('xxx/yyy/base/internal/google_unittest.cpp', | 1094 f('xxx/yyy/base/internal/google_unittest.cpp', |
| 1090 'base/public/google.h')) | 1095 'base/public/google.h')) |
| 1091 self.assertEqual((True, 'xxx/yyy/'), | 1096 self.assertEqual((True, 'xxx/yyy/'), |
| 1092 f('xxx/yyy/base/google_unittest.cpp', | 1097 f('xxx/yyy/base/google_unittest.cpp', |
| 1093 'base/public/google.h')) | 1098 'base/public/google.h')) |
| 1094 self.assertEqual((True, ''), | 1099 self.assertEqual((True, ''), |
| 1095 f('base/google_unittest.cpp', 'base/google-inl.h')) | 1100 f('base/google_unittest.cpp', 'base/google-inl.h')) |
| 1096 self.assertEqual((True, '/home/build/google3/'), | 1101 self.assertEqual((True, '/home/build/google3/'), |
| 1097 f('/home/build/google3/base/google.cpp', 'base/google.
h')) | 1102 f('/home/build/google3/base/google.cpp', 'base/google.h
')) |
| 1098 | 1103 |
| 1099 self.assertEqual((False, ''), | 1104 self.assertEqual((False, ''), |
| 1100 f('/home/build/google3/base/google.cpp', 'basu/google.
h')) | 1105 f('/home/build/google3/base/google.cpp', 'basu/google.h
')) |
| 1101 self.assertEqual((False, ''), f('a.cpp', 'b.h')) | 1106 self.assertEqual((False, ''), f('a.cpp', 'b.h')) |
| 1102 | 1107 |
| 1103 def test_cleanse_line(self): | 1108 def test_cleanse_line(self): |
| 1104 self.assertEqual('int foo = 0; ', | 1109 self.assertEqual('int foo = 0; ', |
| 1105 cpp_style.cleanse_comments('int foo = 0; // danger!')
) | 1110 cpp_style.cleanse_comments('int foo = 0; // danger!')) |
| 1106 self.assertEqual('int o = 0;', | 1111 self.assertEqual('int o = 0;', |
| 1107 cpp_style.cleanse_comments('int /* foo */ o = 0;')) | 1112 cpp_style.cleanse_comments('int /* foo */ o = 0;')) |
| 1108 self.assertEqual('foo(int a, int b);', | 1113 self.assertEqual('foo(int a, int b);', |
| 1109 cpp_style.cleanse_comments('foo(int a /* abc */, int b
);')) | 1114 cpp_style.cleanse_comments('foo(int a /* abc */, int b)
;')) |
| 1110 self.assertEqual('f(a, b);', | 1115 self.assertEqual('f(a, b);', |
| 1111 cpp_style.cleanse_comments('f(a, /* name */ b);')) | 1116 cpp_style.cleanse_comments('f(a, /* name */ b);')) |
| 1112 self.assertEqual('f(a, b);', | 1117 self.assertEqual('f(a, b);', |
| 1113 cpp_style.cleanse_comments('f(a /* name */, b);')) | 1118 cpp_style.cleanse_comments('f(a /* name */, b);')) |
| 1114 self.assertEqual('f(a, b);', | 1119 self.assertEqual('f(a, b);', |
| 1115 cpp_style.cleanse_comments('f(a, /* name */b);')) | 1120 cpp_style.cleanse_comments('f(a, /* name */b);')) |
| 1116 | 1121 |
| 1117 def test_multi_line_comments(self): | 1122 def test_multi_line_comments(self): |
| 1118 # missing explicit is bad | 1123 # missing explicit is bad |
| 1119 self.assert_multi_line_lint( | 1124 self.assert_multi_line_lint( |
| 1120 r'''int a = 0; | 1125 r'''int a = 0; |
| 1121 /* multi-liner | 1126 /* multi-liner |
| 1122 class Foo { | 1127 class Foo { |
| 1123 Foo(int f); // should cause a lint warning in code | 1128 Foo(int f); // should cause a lint warning in code |
| 1124 } | 1129 } |
| 1125 */ ''', | 1130 */ ''', |
| 1126 '') | 1131 '') |
| 1127 self.assert_multi_line_lint( | 1132 self.assert_multi_line_lint( |
| 1128 '''\ | 1133 '''\ |
| 1129 /* int a = 0; multi-liner | 1134 /* int a = 0; multi-liner |
| 1130 static const int b = 0;''', | 1135 static const int b = 0;''', |
| 1131 ['Could not find end of multi-line comment' | 1136 ['Could not find end of multi-line comment' |
| 1132 ' [readability/multiline_comment] [5]', | 1137 ' [readability/multiline_comment] [5]', |
| 1133 'Complex multi-line /*...*/-style comment found. ' | 1138 'Complex multi-line /*...*/-style comment found. ' |
| 1134 'Lint may give bogus warnings. Consider replacing these with ' | 1139 'Lint may give bogus warnings. Consider replacing these with ' |
| 1135 '//-style comments, with #if 0...#endif, or with more clearly ' | 1140 '//-style comments, with #if 0...#endif, or with more clearly ' |
| 1136 'structured multi-line comments. [readability/multiline_comment] [
5]']) | 1141 'structured multi-line comments. [readability/multiline_comment] [
5]']) |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 self.assert_lint('a<Foo*>&& t = &b;', '') | 1773 self.assert_lint('a<Foo*>&& t = &b;', '') |
| 1769 self.assert_lint('a<Foo*> t >>= &b|c;', 'Missing spaces around |' | 1774 self.assert_lint('a<Foo*> t >>= &b|c;', 'Missing spaces around |' |
| 1770 ' [whitespace/operators] [3]') | 1775 ' [whitespace/operators] [3]') |
| 1771 self.assert_lint('a<Foo*> t <<= *b/c;', 'Missing spaces around /' | 1776 self.assert_lint('a<Foo*> t <<= *b/c;', 'Missing spaces around /' |
| 1772 ' [whitespace/operators] [3]') | 1777 ' [whitespace/operators] [3]') |
| 1773 self.assert_lint('a<Foo*> t <<= b/c; //Test', [ | 1778 self.assert_lint('a<Foo*> t <<= b/c; //Test', [ |
| 1774 'Should have a space between // and comment ' | 1779 'Should have a space between // and comment ' |
| 1775 '[whitespace/comments] [4]', 'Missing' | 1780 '[whitespace/comments] [4]', 'Missing' |
| 1776 ' spaces around / [whitespace/operators] [3]']) | 1781 ' spaces around / [whitespace/operators] [3]']) |
| 1777 self.assert_lint('a<Foo*> t <<= b||c; //Test', ['One space before end' | 1782 self.assert_lint('a<Foo*> t <<= b||c; //Test', ['One space before end' |
| 1778 ' of line comments [whitespace/comments] [5]', | 1783 ' of line comments [wh
itespace/comments] [5]', |
| 1779 'Should have a space between // and comment ' | 1784 'Should have a space be
tween // and comment ' |
| 1780 '[whitespace/comments] [4]', | 1785 '[whitespace/comments]
[4]', |
| 1781 'Missing spaces around || [whitespace/operators] [3]']
) | 1786 'Missing spaces around
|| [whitespace/operators] [3]']) |
| 1782 self.assert_lint('a<Foo*> t <<= b && *c; // Test', '') | 1787 self.assert_lint('a<Foo*> t <<= b && *c; // Test', '') |
| 1783 self.assert_lint('a<Foo*> t <<= b && &c; // Test', '') | 1788 self.assert_lint('a<Foo*> t <<= b && &c; // Test', '') |
| 1784 self.assert_lint('a<Foo*> t <<= b || &c; /*Test', 'Complex multi-line ' | 1789 self.assert_lint('a<Foo*> t <<= b || &c; /*Test', 'Complex multi-line ' |
| 1785 '/*...*/-style comment found. Lint may give bogus ' | 1790 '/*...*/-style comment found. Lint may give bogus ' |
| 1786 'warnings. Consider replacing these with //-style' | 1791 'warnings. Consider replacing these with //-style' |
| 1787 ' comments, with #if 0...#endif, or with more clearly' | 1792 ' comments, with #if 0...#endif, or with more clearly' |
| 1788 ' structured multi-line comments. [readability/multili
ne_comment] [5]') | 1793 ' structured multi-line comments. [readability/multili
ne_comment] [5]') |
| 1789 self.assert_lint('a<Foo&> t <<= &b | &c;', '') | 1794 self.assert_lint('a<Foo&> t <<= &b | &c;', '') |
| 1790 self.assert_lint('a<Foo*> t <<= &b & &c; // Test', '') | 1795 self.assert_lint('a<Foo*> t <<= &b & &c; // Test', '') |
| 1791 self.assert_lint('a<Foo*> t <<= *b / &c; // Test', '') | 1796 self.assert_lint('a<Foo*> t <<= *b / &c; // Test', '') |
| 1792 self.assert_lint('if (a=b == 1)', 'Missing spaces around = [whitespace/
operators] [4]') | 1797 self.assert_lint('if (a=b == 1)', 'Missing spaces around = [whitespace/
operators] [4]') |
| 1793 self.assert_lint('a = 1<<20', 'Missing spaces around << [whitespace/ope
rators] [3]') | 1798 self.assert_lint('a = 1<<20', 'Missing spaces around << [whitespace/ope
rators] [3]') |
| 1794 self.assert_lint('a = 1>> 20', 'Missing spaces around >> [whitespace/op
erators] [3]') | 1799 self.assert_lint('a = 1>> 20', 'Missing spaces around >> [whitespace/op
erators] [3]') |
| 1795 self.assert_lint('a = 1 >>20', 'Missing spaces around >> [whitespace/op
erators] [3]') | 1800 self.assert_lint('a = 1 >>20', 'Missing spaces around >> [whitespace/op
erators] [3]') |
| 1796 self.assert_lint('a = 1>>20', 'Missing spaces around >> [whitespace/ope
rators] [3]') | 1801 self.assert_lint('a = 1>>20', 'Missing spaces around >> [whitespace/ope
rators] [3]') |
| 1797 self.assert_lint('func(OwnPtr<Vector<Foo>>)', '') | 1802 self.assert_lint('func(OwnPtr<Vector<Foo>>)', '') |
| 1798 self.assert_lint('func(OwnPtr<Vector<Foo>> foo)', '') | 1803 self.assert_lint('func(OwnPtr<Vector<Foo>> foo)', '') |
| 1799 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>>>)', '') | 1804 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>>>)', '') |
| 1800 self.assert_lint('func(OwnPtr<Vector<Foo> >)', 'Use >> for ending templa
te instead of > >. [readability/templatebrackets] [3]') | 1805 self.assert_lint('func(OwnPtr<Vector<Foo> >)', |
| 1801 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>> >)', 'Use >> for
ending template instead of > >. [readability/templatebrackets] [3]') | 1806 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') |
| 1802 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar> >>)', 'Use >> for
ending template instead of > >. [readability/templatebrackets] [3]') | 1807 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>> >)', |
| 1803 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar> > >)', 'Use >> fo
r ending template instead of > >. [readability/templatebrackets] [3]') | 1808 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') |
| 1809 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar> >>)', |
| 1810 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') |
| 1811 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar> > >)', |
| 1812 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') |
| 1804 self.assert_lint('Vector< ::Foo>)', 'Use <:: for template start instead
of < ::. [readability/templatebrackets] [3]') | 1813 self.assert_lint('Vector< ::Foo>)', 'Use <:: for template start instead
of < ::. [readability/templatebrackets] [3]') |
| 1805 self.assert_lint('Vector<Vector< ::Foo>>)', 'Use <:: for template start
instead of < ::. [readability/templatebrackets] [3]') | 1814 self.assert_lint('Vector<Vector< ::Foo>>)', |
| 1815 'Use <:: for template start instead of < ::. [readabil
ity/templatebrackets] [3]') |
| 1806 # FIXME: The following test should not show any error. | 1816 # FIXME: The following test should not show any error. |
| 1807 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar\n >>>)', | 1817 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar\n >>>)', |
| 1808 'Missing spaces around < [whitespace/operators] [3]') | 1818 'Missing spaces around < [whitespace/operators] [3]') |
| 1809 self.assert_lint('if (a = b == 1)', '') | 1819 self.assert_lint('if (a = b == 1)', '') |
| 1810 self.assert_lint('a = 1 << 20', '') | 1820 self.assert_lint('a = 1 << 20', '') |
| 1811 self.assert_multi_line_lint('#include <sys/io.h>\n', '') | 1821 self.assert_multi_line_lint('#include <sys/io.h>\n', '') |
| 1812 self.assert_multi_line_lint('#import <foo/bar.h>\n', '') | 1822 self.assert_multi_line_lint('#import <foo/bar.h>\n', '') |
| 1813 | 1823 |
| 1814 def test_operator_methods(self): | 1824 def test_operator_methods(self): |
| 1815 self.assert_lint('String operator+(const String&, const String&);', '') | 1825 self.assert_lint('String operator+(const String&, const String&);', '') |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 '') | 1917 '') |
| 1908 | 1918 |
| 1909 def test_one_spaces_between_code_and_comments(self): | 1919 def test_one_spaces_between_code_and_comments(self): |
| 1910 self.assert_lint('} // namespace foo', | 1920 self.assert_lint('} // namespace foo', |
| 1911 '') | 1921 '') |
| 1912 self.assert_lint('}// namespace foo', | 1922 self.assert_lint('}// namespace foo', |
| 1913 'One space before end of line comments' | 1923 'One space before end of line comments' |
| 1914 ' [whitespace/comments] [5]') | 1924 ' [whitespace/comments] [5]') |
| 1915 self.assert_lint('printf("foo"); // Outside quotes.', | 1925 self.assert_lint('printf("foo"); // Outside quotes.', |
| 1916 '') | 1926 '') |
| 1917 self.assert_lint('int i = 0; // Having one space is fine.','') | 1927 self.assert_lint('int i = 0; // Having one space is fine.', '') |
| 1918 self.assert_lint('int i = 0; // Having two spaces is bad.', | 1928 self.assert_lint('int i = 0; // Having two spaces is bad.', |
| 1919 'One space before end of line comments' | 1929 'One space before end of line comments' |
| 1920 ' [whitespace/comments] [5]') | 1930 ' [whitespace/comments] [5]') |
| 1921 self.assert_lint('int i = 0; // Having three spaces is bad.', | 1931 self.assert_lint('int i = 0; // Having three spaces is bad.', |
| 1922 'One space before end of line comments' | 1932 'One space before end of line comments' |
| 1923 ' [whitespace/comments] [5]') | 1933 ' [whitespace/comments] [5]') |
| 1924 self.assert_lint('// Top level comment', '') | 1934 self.assert_lint('// Top level comment', '') |
| 1925 self.assert_lint(' // Line starts with four spaces.', '') | 1935 self.assert_lint(' // Line starts with four spaces.', '') |
| 1926 self.assert_lint('foo();\n' | 1936 self.assert_lint('foo();\n' |
| 1927 '{ // A scope is opening.', '') | 1937 '{ // A scope is opening.', '') |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2126 '}\n', | 2136 '}\n', |
| 2127 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | 2137 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') |
| 2128 | 2138 |
| 2129 self.assert_multi_line_lint( | 2139 self.assert_multi_line_lint( |
| 2130 'if (true) {\n' | 2140 'if (true) {\n' |
| 2131 ' myFunction(reallyLongParam1, reallyLongParam2,\n' | 2141 ' myFunction(reallyLongParam1, reallyLongParam2,\n' |
| 2132 ' reallyLongParam3);\n' | 2142 ' reallyLongParam3);\n' |
| 2133 '}\n', | 2143 '}\n', |
| 2134 'When wrapping a line, only indent 4 spaces. [whitespace/indent] [3
]') | 2144 'When wrapping a line, only indent 4 spaces. [whitespace/indent] [3
]') |
| 2135 | 2145 |
| 2136 | |
| 2137 def test_not_alabel(self): | 2146 def test_not_alabel(self): |
| 2138 self.assert_lint('MyVeryLongNamespace::MyVeryLongClassName::', '') | 2147 self.assert_lint('MyVeryLongNamespace::MyVeryLongClassName::', '') |
| 2139 | 2148 |
| 2140 def test_tab(self): | 2149 def test_tab(self): |
| 2141 self.assert_lint('\tint a;', | 2150 self.assert_lint('\tint a;', |
| 2142 'Tab found; better to use spaces [whitespace/tab] [1]'
) | 2151 'Tab found; better to use spaces [whitespace/tab] [1]'
) |
| 2143 self.assert_lint('int a = 5;\t// set a to 5', | 2152 self.assert_lint('int a = 5;\t// set a to 5', |
| 2144 'Tab found; better to use spaces [whitespace/tab] [1]'
) | 2153 'Tab found; better to use spaces [whitespace/tab] [1]'
) |
| 2145 | 2154 |
| 2146 def test_unnamed_namespaces_in_headers(self): | 2155 def test_unnamed_namespaces_in_headers(self): |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2307 # Verify that we don't blindly suggest the WTF prefix for all headers. | 2316 # Verify that we don't blindly suggest the WTF prefix for all headers. |
| 2308 self.assertFalse(expected_guard.startswith('WTF_')) | 2317 self.assertFalse(expected_guard.startswith('WTF_')) |
| 2309 | 2318 |
| 2310 # Allow the WTF_ prefix for files in that directory. | 2319 # Allow the WTF_ prefix for files in that directory. |
| 2311 header_guard_filter = FilterConfiguration(('-', '+build/header_guard')) | 2320 header_guard_filter = FilterConfiguration(('-', '+build/header_guard')) |
| 2312 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) | 2321 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) |
| 2313 self.process_file_data('Source/JavaScriptCore/wtf/TestName.h', 'h', | 2322 self.process_file_data('Source/JavaScriptCore/wtf/TestName.h', 'h', |
| 2314 ['#ifndef WTF_TestName_h', '#define WTF_TestName_
h'], | 2323 ['#ifndef WTF_TestName_h', '#define WTF_TestName_
h'], |
| 2315 error_collector) | 2324 error_collector) |
| 2316 self.assertEqual(0, len(error_collector.result_list()), | 2325 self.assertEqual(0, len(error_collector.result_list()), |
| 2317 error_collector.result_list()) | 2326 error_collector.result_list()) |
| 2318 | 2327 |
| 2319 # Also allow the non WTF_ prefix for files in that directory. | 2328 # Also allow the non WTF_ prefix for files in that directory. |
| 2320 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) | 2329 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) |
| 2321 self.process_file_data('Source/JavaScriptCore/wtf/TestName.h', 'h', | 2330 self.process_file_data('Source/JavaScriptCore/wtf/TestName.h', 'h', |
| 2322 ['#ifndef TestName_h', '#define TestName_h'], | 2331 ['#ifndef TestName_h', '#define TestName_h'], |
| 2323 error_collector) | 2332 error_collector) |
| 2324 self.assertEqual(0, len(error_collector.result_list()), | 2333 self.assertEqual(0, len(error_collector.result_list()), |
| 2325 error_collector.result_list()) | 2334 error_collector.result_list()) |
| 2326 | 2335 |
| 2327 # Verify that we suggest the WTF prefix version. | 2336 # Verify that we suggest the WTF prefix version. |
| 2328 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) | 2337 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) |
| 2329 self.process_file_data('Source/JavaScriptCore/wtf/TestName.h', 'h', | 2338 self.process_file_data('Source/JavaScriptCore/wtf/TestName.h', 'h', |
| 2330 ['#ifndef BAD_TestName_h', '#define BAD_TestName_
h'], | 2339 ['#ifndef BAD_TestName_h', '#define BAD_TestName_
h'], |
| 2331 error_collector) | 2340 error_collector) |
| 2332 self.assertEqual( | 2341 self.assertEqual( |
| 2333 1, | 2342 1, |
| 2334 error_collector.result_list().count( | 2343 error_collector.result_list().count( |
| 2335 '#ifndef header guard has wrong style, please use: WTF_TestName_
h' | 2344 '#ifndef header guard has wrong style, please use: WTF_TestName_
h' |
| 2336 ' [build/header_guard] [5]'), | 2345 ' [build/header_guard] [5]'), |
| 2337 error_collector.result_list()) | 2346 error_collector.result_list()) |
| 2338 | 2347 |
| 2339 # Verify that the Chromium-style header guard is allowed as well. | 2348 # Verify that the Chromium-style header guard is allowed as well. |
| 2340 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) | 2349 error_collector = ErrorCollector(self.assertTrue, header_guard_filter) |
| 2341 self.process_file_data('Source/foo/testname.h', 'h', | 2350 self.process_file_data('Source/foo/testname.h', 'h', |
| 2342 ['#ifndef BLINK_FOO_TESTNAME_H_', | 2351 ['#ifndef BLINK_FOO_TESTNAME_H_', |
| 2343 '#define BLINK_FOO_TESTNAME_H_'], | 2352 '#define BLINK_FOO_TESTNAME_H_'], |
| 2344 error_collector) | 2353 error_collector) |
| 2345 self.assertEqual(0, len(error_collector.result_list()), | 2354 self.assertEqual(0, len(error_collector.result_list()), |
| 2346 error_collector.result_list()) | 2355 error_collector.result_list()) |
| 2347 | 2356 |
| 2348 def test_build_printf_format(self): | 2357 def test_build_printf_format(self): |
| 2349 self.assert_lint( | 2358 self.assert_lint( |
| 2350 r'printf("\%%d", value);', | 2359 r'printf("\%%d", value);', |
| 2351 '%, [, (, and { are undefined character escapes. Unescape them.' | 2360 '%, [, (, and { are undefined character escapes. Unescape them.' |
| 2352 ' [build/printf_format] [3]') | 2361 ' [build/printf_format] [3]') |
| 2353 | 2362 |
| 2354 self.assert_lint( | 2363 self.assert_lint( |
| 2355 r'snprintf(buffer, sizeof(buffer), "\[%d", value);', | 2364 r'snprintf(buffer, sizeof(buffer), "\[%d", value);', |
| 2356 '%, [, (, and { are undefined character escapes. Unescape them.' | 2365 '%, [, (, and { are undefined character escapes. Unescape them.' |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2597 | 2606 |
| 2598 safe_bitfield_test('a', 'A', 'unsigned', 22) | 2607 safe_bitfield_test('a', 'A', 'unsigned', 22) |
| 2599 safe_bitfield_test('m_someField', 'SomeClass', 'bool', 1) | 2608 safe_bitfield_test('m_someField', 'SomeClass', 'bool', 1) |
| 2600 safe_bitfield_test('m_someField', 'SomeClass', 'unsigned', 2) | 2609 safe_bitfield_test('m_someField', 'SomeClass', 'unsigned', 2) |
| 2601 | 2610 |
| 2602 # Declarations in 'Expected' or 'SameSizeAs' classes are OK. | 2611 # Declarations in 'Expected' or 'SameSizeAs' classes are OK. |
| 2603 warning_bitfield_test('m_bitfields', 'SomeClass', 'int32_t', 32) | 2612 warning_bitfield_test('m_bitfields', 'SomeClass', 'int32_t', 32) |
| 2604 safe_bitfield_test('m_bitfields', 'ExpectedSomeClass', 'int32_t', 32) | 2613 safe_bitfield_test('m_bitfields', 'ExpectedSomeClass', 'int32_t', 32) |
| 2605 safe_bitfield_test('m_bitfields', 'SameSizeAsSomeClass', 'int32_t', 32) | 2614 safe_bitfield_test('m_bitfields', 'SameSizeAsSomeClass', 'int32_t', 32) |
| 2606 | 2615 |
| 2616 |
| 2607 class CleansedLinesTest(unittest.TestCase): | 2617 class CleansedLinesTest(unittest.TestCase): |
| 2618 |
| 2608 def test_init(self): | 2619 def test_init(self): |
| 2609 lines = ['Line 1', | 2620 lines = ['Line 1', |
| 2610 'Line 2', | 2621 'Line 2', |
| 2611 'Line 3 // Comment test', | 2622 'Line 3 // Comment test', |
| 2612 'Line 4 "foo"'] | 2623 'Line 4 "foo"'] |
| 2613 | 2624 |
| 2614 clean_lines = cpp_style.CleansedLines(lines) | 2625 clean_lines = cpp_style.CleansedLines(lines) |
| 2615 self.assertEqual(lines, clean_lines.raw_lines) | 2626 self.assertEqual(lines, clean_lines.raw_lines) |
| 2616 self.assertEqual(4, clean_lines.num_lines()) | 2627 self.assertEqual(4, clean_lines.num_lines()) |
| 2617 | 2628 |
| 2618 self.assertEqual(['Line 1', | 2629 self.assertEqual(['Line 1', |
| 2619 'Line 2', | 2630 'Line 2', |
| 2620 'Line 3 ', | 2631 'Line 3 ', |
| 2621 'Line 4 "foo"'], | 2632 'Line 4 "foo"'], |
| 2622 clean_lines.lines) | 2633 clean_lines.lines) |
| 2623 | 2634 |
| 2624 self.assertEqual(['Line 1', | 2635 self.assertEqual(['Line 1', |
| 2625 'Line 2', | 2636 'Line 2', |
| 2626 'Line 3 ', | 2637 'Line 3 ', |
| 2627 'Line 4 ""'], | 2638 'Line 4 ""'], |
| 2628 clean_lines.elided) | 2639 clean_lines.elided) |
| 2629 | 2640 |
| 2630 def test_init_empty(self): | 2641 def test_init_empty(self): |
| 2631 clean_lines = cpp_style.CleansedLines([]) | 2642 clean_lines = cpp_style.CleansedLines([]) |
| 2632 self.assertEqual([], clean_lines.raw_lines) | 2643 self.assertEqual([], clean_lines.raw_lines) |
| 2633 self.assertEqual(0, clean_lines.num_lines()) | 2644 self.assertEqual(0, clean_lines.num_lines()) |
| 2634 | 2645 |
| 2635 def test_collapse_strings(self): | 2646 def test_collapse_strings(self): |
| 2636 collapse = cpp_style.CleansedLines.collapse_strings | 2647 collapse = cpp_style.CleansedLines.collapse_strings |
| 2637 self.assertEqual('""', collapse('""')) # "" (empty) | 2648 self.assertEqual('""', collapse('""')) # "" (empty) |
| 2638 self.assertEqual('"""', collapse('"""')) # """ (bad) | 2649 self.assertEqual('"""', collapse('"""')) # """ (bad) |
| 2639 self.assertEqual('""', collapse('"xyz"')) # "xyz" (string) | 2650 self.assertEqual('""', collapse('"xyz"')) # "xyz" (string) |
| 2640 self.assertEqual('""', collapse('"\\\""')) # "\"" (string) | 2651 self.assertEqual('""', collapse('"\\\""')) # "\"" (string) |
| 2641 self.assertEqual('""', collapse('"\'"')) # "'" (string) | 2652 self.assertEqual('""', collapse('"\'"')) # "'" (string) |
| 2642 self.assertEqual('"\"', collapse('"\"')) # "\" (bad) | 2653 self.assertEqual('"\"', collapse('"\"')) # "\" (bad) |
| 2643 self.assertEqual('""', collapse('"\\\\"')) # "\\" (string) | 2654 self.assertEqual('""', collapse('"\\\\"')) # "\\" (string) |
| 2644 self.assertEqual('"', collapse('"\\\\\\"')) # "\\\" (bad) | 2655 self.assertEqual('"', collapse('"\\\\\\"')) # "\\\" (bad) |
| 2645 self.assertEqual('""', collapse('"\\\\\\\\"')) # "\\\\" (string) | 2656 self.assertEqual('""', collapse('"\\\\\\\\"')) # "\\\\" (string) |
| 2646 | 2657 |
| 2647 self.assertEqual('\'\'', collapse('\'\'')) # '' (empty) | 2658 self.assertEqual('\'\'', collapse('\'\'')) # '' (empty) |
| 2648 self.assertEqual('\'\'', collapse('\'a\'')) # 'a' (char) | 2659 self.assertEqual('\'\'', collapse('\'a\'')) # 'a' (char) |
| 2649 self.assertEqual('\'\'', collapse('\'\\\'\'')) # '\'' (char) | 2660 self.assertEqual('\'\'', collapse('\'\\\'\'')) # '\'' (char) |
| 2650 self.assertEqual('\'', collapse('\'\\\'')) # '\' (bad) | 2661 self.assertEqual('\'', collapse('\'\\\'')) # '\' (bad) |
| 2651 self.assertEqual('', collapse('\\012')) # '\012' (char) | 2662 self.assertEqual('', collapse('\\012')) # '\012' (char) |
| 2652 self.assertEqual('', collapse('\\xfF0')) # '\xfF0' (char) | 2663 self.assertEqual('', collapse('\\xfF0')) # '\xfF0' (char) |
| 2653 self.assertEqual('', collapse('\\n')) # '\n' (char) | 2664 self.assertEqual('', collapse('\\n')) # '\n' (char) |
| 2654 self.assertEqual('\#', collapse('\\#')) # '\#' (bad) | 2665 self.assertEqual('\#', collapse('\\#')) # '\#' (bad) |
| 2655 | 2666 |
| 2656 self.assertEqual('StringReplace(body, "", "");', | 2667 self.assertEqual('StringReplace(body, "", "");', |
| 2657 collapse('StringReplace(body, "\\\\", "\\\\\\\\");')) | 2668 collapse('StringReplace(body, "\\\\", "\\\\\\\\");')) |
| 2658 self.assertEqual('\'\' ""', | 2669 self.assertEqual('\'\' ""', |
| 2659 collapse('\'"\' "foo"')) | 2670 collapse('\'"\' "foo"')) |
| 2660 self.assertEqual('""', collapse('"a" "b" "c"')) | 2671 self.assertEqual('""', collapse('"a" "b" "c"')) |
| 2661 | 2672 |
| 2662 | 2673 |
| 2663 class OrderOfIncludesTest(CppStyleTestBase): | 2674 class OrderOfIncludesTest(CppStyleTestBase): |
| 2675 |
| 2664 def setUp(self): | 2676 def setUp(self): |
| 2665 self.include_state = cpp_style._IncludeState() | 2677 self.include_state = cpp_style._IncludeState() |
| 2666 | 2678 |
| 2667 # Cheat os.path.abspath called in FileInfo class. | 2679 # Cheat os.path.abspath called in FileInfo class. |
| 2668 self.os_path_abspath_orig = os.path.abspath | 2680 self.os_path_abspath_orig = os.path.abspath |
| 2669 os.path.abspath = lambda value: value | 2681 os.path.abspath = lambda value: value |
| 2670 | 2682 |
| 2671 def tearDown(self): | 2683 def tearDown(self): |
| 2672 os.path.abspath = self.os_path_abspath_orig | 2684 os.path.abspath = self.os_path_abspath_orig |
| 2673 | 2685 |
| 2674 def test_try_drop_common_suffixes(self): | 2686 def test_try_drop_common_suffixes(self): |
| 2675 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl
.h')) | 2687 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo-inl
.h')) |
| 2676 self.assertEqual('foo/bar/foo', | 2688 self.assertEqual('foo/bar/foo', |
| 2677 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h')) | 2689 cpp_style._drop_common_suffixes('foo/bar/foo_inl.h')) |
| 2678 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp
')) | 2690 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp
')) |
| 2679 self.assertEqual('foo/foo_unusualinternal', | 2691 self.assertEqual('foo/foo_unusualinternal', |
| 2680 cpp_style._drop_common_suffixes('foo/foo_unusualinterna
l.h')) | 2692 cpp_style._drop_common_suffixes('foo/foo_unusualinterna
l.h')) |
| 2681 self.assertEqual('', | 2693 self.assertEqual('', |
| 2682 cpp_style._drop_common_suffixes('_test.cpp')) | 2694 cpp_style._drop_common_suffixes('_test.cpp')) |
| 2683 self.assertEqual('test', | 2695 self.assertEqual('test', |
| 2684 cpp_style._drop_common_suffixes('test.cpp')) | 2696 cpp_style._drop_common_suffixes('test.cpp')) |
| 2685 | 2697 |
| 2686 | 2698 |
| 2687 class OrderOfIncludesTest(CppStyleTestBase): | 2699 class OrderOfIncludesTest(CppStyleTestBase): |
| 2700 |
| 2688 def setUp(self): | 2701 def setUp(self): |
| 2689 self.include_state = cpp_style._IncludeState() | 2702 self.include_state = cpp_style._IncludeState() |
| 2690 | 2703 |
| 2691 # Cheat os.path.abspath called in FileInfo class. | 2704 # Cheat os.path.abspath called in FileInfo class. |
| 2692 self.os_path_abspath_orig = os.path.abspath | 2705 self.os_path_abspath_orig = os.path.abspath |
| 2693 self.os_path_isfile_orig = os.path.isfile | 2706 self.os_path_isfile_orig = os.path.isfile |
| 2694 os.path.abspath = lambda value: value | 2707 os.path.abspath = lambda value: value |
| 2695 | 2708 |
| 2696 def tearDown(self): | 2709 def tearDown(self): |
| 2697 os.path.abspath = self.os_path_abspath_orig | 2710 os.path.abspath = self.os_path_abspath_orig |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2784 | 2797 |
| 2785 def test_check_preprocessor_in_include_section(self): | 2798 def test_check_preprocessor_in_include_section(self): |
| 2786 self.assert_language_rules_check('foo.cpp', | 2799 self.assert_language_rules_check('foo.cpp', |
| 2787 '#include "foo.h"\n' | 2800 '#include "foo.h"\n' |
| 2788 '\n' | 2801 '\n' |
| 2789 '#ifdef BAZ\n' | 2802 '#ifdef BAZ\n' |
| 2790 '#include "baz.h"\n' | 2803 '#include "baz.h"\n' |
| 2791 '#else\n' | 2804 '#else\n' |
| 2792 '#include "foobar.h"\n' | 2805 '#include "foobar.h"\n' |
| 2793 '#endif"\n' | 2806 '#endif"\n' |
| 2794 '#include "bar.h"\n', # No flag because
previous is in preprocessor section | 2807 '#include "bar.h"\n', # No flag becaus
e previous is in preprocessor section |
| 2795 '') | 2808 '') |
| 2796 | 2809 |
| 2797 self.assert_language_rules_check('foo.cpp', | 2810 self.assert_language_rules_check('foo.cpp', |
| 2798 '#include "foo.h"\n' | 2811 '#include "foo.h"\n' |
| 2799 '\n' | 2812 '\n' |
| 2800 '#ifdef BAZ\n' | 2813 '#ifdef BAZ\n' |
| 2801 '#include "baz.h"\n' | 2814 '#include "baz.h"\n' |
| 2802 '#endif"\n' | 2815 '#endif"\n' |
| 2803 '#include "bar.h"\n' | 2816 '#include "bar.h"\n' |
| 2804 '#include "a.h"\n', # Should still flag
this. | 2817 '#include "a.h"\n', # Should still fla
g this. |
| 2805 'Alphabetical sorting problem. [build/
include_order] [4]') | 2818 'Alphabetical sorting problem. [build/
include_order] [4]') |
| 2806 | 2819 |
| 2807 self.assert_language_rules_check('foo.cpp', | 2820 self.assert_language_rules_check('foo.cpp', |
| 2808 '#include "foo.h"\n' | 2821 '#include "foo.h"\n' |
| 2809 '\n' | 2822 '\n' |
| 2810 '#ifdef BAZ\n' | 2823 '#ifdef BAZ\n' |
| 2811 '#include "baz.h"\n' | 2824 '#include "baz.h"\n' |
| 2812 '#include "bar.h"\n' #Should still flag
this | 2825 '#include "bar.h"\n' # Should still fl
ag this |
| 2813 '#endif"\n', | 2826 '#endif"\n', |
| 2814 'Alphabetical sorting problem. [build/
include_order] [4]') | 2827 'Alphabetical sorting problem. [build/
include_order] [4]') |
| 2815 | 2828 |
| 2816 self.assert_language_rules_check('foo.cpp', | 2829 self.assert_language_rules_check('foo.cpp', |
| 2817 '#include "foo.h"\n' | 2830 '#include "foo.h"\n' |
| 2818 '\n' | 2831 '\n' |
| 2819 '#ifdef BAZ\n' | 2832 '#ifdef BAZ\n' |
| 2820 '#include "baz.h"\n' | 2833 '#include "baz.h"\n' |
| 2821 '#endif"\n' | 2834 '#endif"\n' |
| 2822 '#ifdef FOOBAR\n' | 2835 '#ifdef FOOBAR\n' |
| 2823 '#include "foobar.h"\n' | 2836 '#include "foobar.h"\n' |
| 2824 '#endif"\n' | 2837 '#endif"\n' |
| 2825 '#include "bar.h"\n' | 2838 '#include "bar.h"\n' |
| 2826 '#include "a.h"\n', # Should still flag
this. | 2839 '#include "a.h"\n', # Should still fla
g this. |
| 2827 'Alphabetical sorting problem. [build/
include_order] [4]') | 2840 'Alphabetical sorting problem. [build/
include_order] [4]') |
| 2828 | 2841 |
| 2829 # Check that after an already included error, the sorting rules still wo
rk. | 2842 # Check that after an already included error, the sorting rules still wo
rk. |
| 2830 self.assert_language_rules_check('foo.cpp', | 2843 self.assert_language_rules_check('foo.cpp', |
| 2831 '#include "foo.h"\n' | 2844 '#include "foo.h"\n' |
| 2832 '\n' | 2845 '\n' |
| 2833 '#include "foo.h"\n' | 2846 '#include "foo.h"\n' |
| 2834 '#include "g.h"\n', | 2847 '#include "g.h"\n', |
| 2835 '"foo.h" already included at foo.cpp:1
[build/include] [4]') | 2848 '"foo.h" already included at foo.cpp:1
[build/include] [4]') |
| 2836 | 2849 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2997 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp
')) | 3010 self.assertEqual('foo/foo', cpp_style._drop_common_suffixes('foo/foo.cpp
')) |
| 2998 self.assertEqual('foo/foo_unusualinternal', | 3011 self.assertEqual('foo/foo_unusualinternal', |
| 2999 cpp_style._drop_common_suffixes('foo/foo_unusualinterna
l.h')) | 3012 cpp_style._drop_common_suffixes('foo/foo_unusualinterna
l.h')) |
| 3000 self.assertEqual('', | 3013 self.assertEqual('', |
| 3001 cpp_style._drop_common_suffixes('_test.cpp')) | 3014 cpp_style._drop_common_suffixes('_test.cpp')) |
| 3002 self.assertEqual('test', | 3015 self.assertEqual('test', |
| 3003 cpp_style._drop_common_suffixes('test.cpp')) | 3016 cpp_style._drop_common_suffixes('test.cpp')) |
| 3004 self.assertEqual('test', | 3017 self.assertEqual('test', |
| 3005 cpp_style._drop_common_suffixes('test.cpp')) | 3018 cpp_style._drop_common_suffixes('test.cpp')) |
| 3006 | 3019 |
| 3020 |
| 3007 class CheckForFunctionLengthsTest(CppStyleTestBase): | 3021 class CheckForFunctionLengthsTest(CppStyleTestBase): |
| 3022 |
| 3008 def setUp(self): | 3023 def setUp(self): |
| 3009 # Reducing these thresholds for the tests speeds up tests significantly. | 3024 # Reducing these thresholds for the tests speeds up tests significantly. |
| 3010 self.old_normal_trigger = cpp_style._FunctionState._NORMAL_TRIGGER | 3025 self.old_normal_trigger = cpp_style._FunctionState._NORMAL_TRIGGER |
| 3011 self.old_test_trigger = cpp_style._FunctionState._TEST_TRIGGER | 3026 self.old_test_trigger = cpp_style._FunctionState._TEST_TRIGGER |
| 3012 | 3027 |
| 3013 cpp_style._FunctionState._NORMAL_TRIGGER = 10 | 3028 cpp_style._FunctionState._NORMAL_TRIGGER = 10 |
| 3014 cpp_style._FunctionState._TEST_TRIGGER = 25 | 3029 cpp_style._FunctionState._TEST_TRIGGER = 25 |
| 3015 | 3030 |
| 3016 def tearDown(self): | 3031 def tearDown(self): |
| 3017 cpp_style._FunctionState._NORMAL_TRIGGER = self.old_normal_trigger | 3032 cpp_style._FunctionState._NORMAL_TRIGGER = self.old_normal_trigger |
| 3018 cpp_style._FunctionState._TEST_TRIGGER = self.old_test_trigger | 3033 cpp_style._FunctionState._TEST_TRIGGER = self.old_test_trigger |
| 3019 | 3034 |
| 3020 # FIXME: Eliminate the need for this function. | 3035 # FIXME: Eliminate the need for this function. |
| 3021 def set_min_confidence(self, min_confidence): | 3036 def set_min_confidence(self, min_confidence): |
| 3022 """Set new test confidence and return old test confidence.""" | 3037 """Set new test confidence and return old test confidence.""" |
| 3023 old_min_confidence = self.min_confidence | 3038 old_min_confidence = self.min_confidence |
| 3024 self.min_confidence = min_confidence | 3039 self.min_confidence = min_confidence |
| 3025 return old_min_confidence | 3040 return old_min_confidence |
| 3026 | 3041 |
| 3027 def assert_function_lengths_check(self, code, expected_message): | 3042 def assert_function_lengths_check(self, code, expected_message): |
| 3028 """Check warnings for long function bodies are as expected. | 3043 """Check warnings for long function bodies are as expected. |
| 3029 | 3044 |
| 3030 Args: | 3045 Args: |
| 3031 code: C++ source code expected to generate a warning message. | 3046 code: C++ source code expected to generate a warning message. |
| 3032 expected_message: Message expected to be generated by the C++ code. | 3047 expected_message: Message expected to be generated by the C++ code. |
| 3033 """ | 3048 """ |
| 3034 self.assertEqual(expected_message, | 3049 self.assertEqual(expected_message, |
| 3035 self.perform_function_lengths_check(code)) | 3050 self.perform_function_lengths_check(code)) |
| 3036 | 3051 |
| 3037 def trigger_lines(self, error_level): | 3052 def trigger_lines(self, error_level): |
| 3038 """Return number of lines needed to trigger a function length warning. | 3053 """Return number of lines needed to trigger a function length warning. |
| 3039 | 3054 |
| 3040 Args: | 3055 Args: |
| 3041 error_level: --v setting for cpp_style. | 3056 error_level: --v setting for cpp_style. |
| 3042 | 3057 |
| 3043 Returns: | 3058 Returns: |
| 3044 Number of lines needed to trigger a function length warning. | 3059 Number of lines needed to trigger a function length warning. |
| 3045 """ | 3060 """ |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3534 # For http://webkit.org/coding/RefPtr.html | 3549 # For http://webkit.org/coding/RefPtr.html |
| 3535 | 3550 |
| 3536 def assert_pass_ptr_check(self, code, expected_message): | 3551 def assert_pass_ptr_check(self, code, expected_message): |
| 3537 """Check warnings for Pass*Ptr are as expected. | 3552 """Check warnings for Pass*Ptr are as expected. |
| 3538 | 3553 |
| 3539 Args: | 3554 Args: |
| 3540 code: C++ source code expected to generate a warning message. | 3555 code: C++ source code expected to generate a warning message. |
| 3541 expected_message: Message expected to be generated by the C++ code. | 3556 expected_message: Message expected to be generated by the C++ code. |
| 3542 """ | 3557 """ |
| 3543 self.assertEqual(expected_message, | 3558 self.assertEqual(expected_message, |
| 3544 self.perform_pass_ptr_check(code)) | 3559 self.perform_pass_ptr_check(code)) |
| 3545 | 3560 |
| 3546 def test_pass_ref_ptr_in_function(self): | 3561 def test_pass_ref_ptr_in_function(self): |
| 3547 self.assert_pass_ptr_check( | 3562 self.assert_pass_ptr_check( |
| 3548 'int myFunction()\n' | 3563 'int myFunction()\n' |
| 3549 '{\n' | 3564 '{\n' |
| 3550 ' PassRefPtr<Type1> variable = variable2;\n' | 3565 ' PassRefPtr<Type1> variable = variable2;\n' |
| 3551 '}', | 3566 '}', |
| 3552 'Local variables should never be PassRefPtr (see ' | 3567 'Local variables should never be PassRefPtr (see ' |
| 3553 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]'
) | 3568 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]'
) |
| 3554 | 3569 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3679 class LeakyPatternTest(CppStyleTestBase): | 3694 class LeakyPatternTest(CppStyleTestBase): |
| 3680 | 3695 |
| 3681 def assert_leaky_pattern_check(self, code, expected_message): | 3696 def assert_leaky_pattern_check(self, code, expected_message): |
| 3682 """Check warnings for leaky patterns are as expected. | 3697 """Check warnings for leaky patterns are as expected. |
| 3683 | 3698 |
| 3684 Args: | 3699 Args: |
| 3685 code: C++ source code expected to generate a warning message. | 3700 code: C++ source code expected to generate a warning message. |
| 3686 expected_message: Message expected to be generated by the C++ code. | 3701 expected_message: Message expected to be generated by the C++ code. |
| 3687 """ | 3702 """ |
| 3688 self.assertEqual(expected_message, | 3703 self.assertEqual(expected_message, |
| 3689 self.perform_leaky_pattern_check(code)) | 3704 self.perform_leaky_pattern_check(code)) |
| 3690 | 3705 |
| 3691 def test_get_dc(self): | 3706 def test_get_dc(self): |
| 3692 self.assert_leaky_pattern_check( | 3707 self.assert_leaky_pattern_check( |
| 3693 'HDC hdc = GetDC(hwnd);', | 3708 'HDC hdc = GetDC(hwnd);', |
| 3694 'Use the class HWndDC instead of calling GetDC to avoid potential ' | 3709 'Use the class HWndDC instead of calling GetDC to avoid potential ' |
| 3695 'memory leaks. [runtime/leaky_pattern] [5]') | 3710 'memory leaks. [runtime/leaky_pattern] [5]') |
| 3696 | 3711 |
| 3697 def test_get_dc(self): | 3712 def test_get_dc(self): |
| 3698 self.assert_leaky_pattern_check( | 3713 self.assert_leaky_pattern_check( |
| 3699 'HDC hdc = GetDCEx(hwnd, 0, 0);', | 3714 'HDC hdc = GetDCEx(hwnd, 0, 0);', |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4598 ' doSomething1();\n' | 4613 ' doSomething1();\n' |
| 4599 'else if (condition2) {\n' | 4614 'else if (condition2) {\n' |
| 4600 ' doSomething2();\n' | 4615 ' doSomething2();\n' |
| 4601 ' doSomething2_2();\n' | 4616 ' doSomething2_2();\n' |
| 4602 '} else {\n' | 4617 '} else {\n' |
| 4603 ' doSomething3();\n' | 4618 ' doSomething3();\n' |
| 4604 ' doSomething3_2();\n' | 4619 ' doSomething3_2();\n' |
| 4605 '}\n', | 4620 '}\n', |
| 4606 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') | 4621 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4607 | 4622 |
| 4608 | |
| 4609 # 5. Control clauses without a body should use empty braces. | 4623 # 5. Control clauses without a body should use empty braces. |
| 4610 self.assert_multi_line_lint( | 4624 self.assert_multi_line_lint( |
| 4611 'for ( ; current; current = current->next) { }\n', | 4625 'for ( ; current; current = current->next) { }\n', |
| 4612 '') | 4626 '') |
| 4613 self.assert_multi_line_lint( | 4627 self.assert_multi_line_lint( |
| 4614 'for ( ; current;\n' | 4628 'for ( ; current;\n' |
| 4615 ' current = current->next) { }\n', | 4629 ' current = current->next) { }\n', |
| 4616 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | 4630 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') |
| 4617 self.assert_multi_line_lint( | 4631 self.assert_multi_line_lint( |
| 4618 'for ( ; current; current = current->next);\n', | 4632 'for ( ; current; current = current->next);\n', |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5018 # GObject requires certain magical names in class declarations. | 5032 # GObject requires certain magical names in class declarations. |
| 5019 self.assert_lint('void webkit_dom_object_init();', '') | 5033 self.assert_lint('void webkit_dom_object_init();', '') |
| 5020 self.assert_lint('void webkit_dom_object_class_init();', '') | 5034 self.assert_lint('void webkit_dom_object_class_init();', '') |
| 5021 | 5035 |
| 5022 # There is an exception for GTK+ API. | 5036 # There is an exception for GTK+ API. |
| 5023 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S
ource/Webkit/gtk/webkit/foo.cpp') | 5037 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S
ource/Webkit/gtk/webkit/foo.cpp') |
| 5024 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S
ource/Webkit2/UIProcess/gtk/foo.cpp') | 5038 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S
ource/Webkit2/UIProcess/gtk/foo.cpp') |
| 5025 | 5039 |
| 5026 # Test that this doesn't also apply to files not in a 'gtk' directory. | 5040 # Test that this doesn't also apply to files not in a 'gtk' directory. |
| 5027 self.assert_lint('void webkit_web_view_load(int var1, int var2)', | 5041 self.assert_lint('void webkit_web_view_load(int var1, int var2)', |
| 5028 'webkit_web_view_load is incorrectly named. Don\'t use underscores i
n your identifier names.' | 5042 'webkit_web_view_load is incorrectly named. Don\'t use
underscores in your identifier names.' |
| 5029 ' [readability/naming/underscores] [4]', 'Source/Webkit/webkit/foo.
cpp') | 5043 ' [readability/naming/underscores] [4]', 'Source/Webki
t/webkit/foo.cpp') |
| 5030 # Test that this doesn't also apply to names that don't start with 'webk
it_'. | 5044 # Test that this doesn't also apply to names that don't start with 'webk
it_'. |
| 5031 self.assert_lint_one_of_many_errors_re('void otherkit_web_view_load(int
var1, int var2)', | 5045 self.assert_lint_one_of_many_errors_re('void otherkit_web_view_load(int
var1, int var2)', |
| 5032 'otherkit_web_view_load is incorrectly named. Don\'t use underscores
in your identifier names.' | 5046 'otherkit_web_view_load is incorr
ectly named. Don\'t use underscores in your identifier names.' |
| 5033 ' [readability/naming/underscores] [4]', 'Source/Webkit/webkit/foo.
cpp') | 5047 ' [readability/naming/underscore
s] [4]', 'Source/Webkit/webkit/foo.cpp') |
| 5034 | 5048 |
| 5035 # There is an exception for some unit tests that begin with "tst_". | 5049 # There is an exception for some unit tests that begin with "tst_". |
| 5036 self.assert_lint('void tst_QWebFrame::arrayObjectEnumerable(int var1, in
t var2)', '') | 5050 self.assert_lint('void tst_QWebFrame::arrayObjectEnumerable(int var1, in
t var2)', '') |
| 5037 | 5051 |
| 5038 # The Qt API uses names that begin with "qt_" or "_q_". | 5052 # The Qt API uses names that begin with "qt_" or "_q_". |
| 5039 self.assert_lint('void QTFrame::qt_drt_is_awesome(int var1, int var2)',
'') | 5053 self.assert_lint('void QTFrame::qt_drt_is_awesome(int var1, int var2)',
'') |
| 5040 self.assert_lint('void QTFrame::_q_drt_is_awesome(int var1, int var2)',
'') | 5054 self.assert_lint('void QTFrame::_q_drt_is_awesome(int var1, int var2)',
'') |
| 5041 self.assert_lint('void qt_drt_is_awesome(int var1, int var2);', '') | 5055 self.assert_lint('void qt_drt_is_awesome(int var1, int var2);', '') |
| 5042 self.assert_lint('void _q_drt_is_awesome(int var1, int var2);', '') | 5056 self.assert_lint('void _q_drt_is_awesome(int var1, int var2);', '') |
| 5043 | 5057 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5078 self.assert_lint('operator int64_t();', '') | 5092 self.assert_lint('operator int64_t();', '') |
| 5079 | 5093 |
| 5080 def test_parameter_names(self): | 5094 def test_parameter_names(self): |
| 5081 # Leave meaningless variable names out of function declarations. | 5095 # Leave meaningless variable names out of function declarations. |
| 5082 meaningless_variable_name_error_message = 'The parameter name "%s" adds
no information, so it should be removed. [readability/parameter_name] [5]' | 5096 meaningless_variable_name_error_message = 'The parameter name "%s" adds
no information, so it should be removed. [readability/parameter_name] [5]' |
| 5083 | 5097 |
| 5084 parameter_error_rules = ('-', | 5098 parameter_error_rules = ('-', |
| 5085 '+readability/parameter_name') | 5099 '+readability/parameter_name') |
| 5086 # No variable name, so no error. | 5100 # No variable name, so no error. |
| 5087 self.assertEqual('', | 5101 self.assertEqual('', |
| 5088 self.perform_lint('void func(int);', 'test.cpp', param
eter_error_rules)) | 5102 self.perform_lint('void func(int);', 'test.cpp', parame
ter_error_rules)) |
| 5089 | 5103 |
| 5090 # Verify that copying the name of the set function causes the error (wit
h some odd casing). | 5104 # Verify that copying the name of the set function causes the error (wit
h some odd casing). |
| 5091 self.assertEqual(meaningless_variable_name_error_message % 'itemCount', | 5105 self.assertEqual(meaningless_variable_name_error_message % 'itemCount', |
| 5092 self.perform_lint('void setItemCount(size_t itemCount)
;', 'test.cpp', parameter_error_rules)) | 5106 self.perform_lint('void setItemCount(size_t itemCount);
', 'test.cpp', parameter_error_rules)) |
| 5093 self.assertEqual(meaningless_variable_name_error_message % 'abcCount', | 5107 self.assertEqual(meaningless_variable_name_error_message % 'abcCount', |
| 5094 self.perform_lint('void setABCCount(size_t abcCount);'
, 'test.cpp', parameter_error_rules)) | 5108 self.perform_lint('void setABCCount(size_t abcCount);',
'test.cpp', parameter_error_rules)) |
| 5095 | 5109 |
| 5096 # Verify that copying a type name will trigger the warning (even if the
type is a template parameter). | 5110 # Verify that copying a type name will trigger the warning (even if the
type is a template parameter). |
| 5097 self.assertEqual(meaningless_variable_name_error_message % 'context', | 5111 self.assertEqual(meaningless_variable_name_error_message % 'context', |
| 5098 self.perform_lint('void funct(PassRefPtr<ScriptExecuti
onContext> context);', 'test.cpp', parameter_error_rules)) | 5112 self.perform_lint('void funct(PassRefPtr<ScriptExecutio
nContext> context);', 'test.cpp', parameter_error_rules)) |
| 5099 | 5113 |
| 5100 # Verify that acronyms as variable names trigger the error (for both set
functions and type names). | 5114 # Verify that acronyms as variable names trigger the error (for both set
functions and type names). |
| 5101 self.assertEqual(meaningless_variable_name_error_message % 'ec', | 5115 self.assertEqual(meaningless_variable_name_error_message % 'ec', |
| 5102 self.perform_lint('void setExceptionCode(int ec);', 't
est.cpp', parameter_error_rules)) | 5116 self.perform_lint('void setExceptionCode(int ec);', 'te
st.cpp', parameter_error_rules)) |
| 5103 self.assertEqual(meaningless_variable_name_error_message % 'ec', | 5117 self.assertEqual(meaningless_variable_name_error_message % 'ec', |
| 5104 self.perform_lint('void funct(ExceptionCode ec);', 'te
st.cpp', parameter_error_rules)) | 5118 self.perform_lint('void funct(ExceptionCode ec);', 'tes
t.cpp', parameter_error_rules)) |
| 5105 | 5119 |
| 5106 # 'object' alone, appended, or as part of an acronym is meaningless. | 5120 # 'object' alone, appended, or as part of an acronym is meaningless. |
| 5107 self.assertEqual(meaningless_variable_name_error_message % 'object', | 5121 self.assertEqual(meaningless_variable_name_error_message % 'object', |
| 5108 self.perform_lint('void funct(RenderView object);', 't
est.cpp', parameter_error_rules)) | 5122 self.perform_lint('void funct(RenderView object);', 'te
st.cpp', parameter_error_rules)) |
| 5109 self.assertEqual(meaningless_variable_name_error_message % 'viewObject', | 5123 self.assertEqual(meaningless_variable_name_error_message % 'viewObject', |
| 5110 self.perform_lint('void funct(RenderView viewObject);'
, 'test.cpp', parameter_error_rules)) | 5124 self.perform_lint('void funct(RenderView viewObject);',
'test.cpp', parameter_error_rules)) |
| 5111 self.assertEqual(meaningless_variable_name_error_message % 'rvo', | 5125 self.assertEqual(meaningless_variable_name_error_message % 'rvo', |
| 5112 self.perform_lint('void funct(RenderView rvo);', 'test
.cpp', parameter_error_rules)) | 5126 self.perform_lint('void funct(RenderView rvo);', 'test.
cpp', parameter_error_rules)) |
| 5113 | 5127 |
| 5114 # Check that r, g, b, and a are allowed. | 5128 # Check that r, g, b, and a are allowed. |
| 5115 self.assertEqual('', | 5129 self.assertEqual('', |
| 5116 self.perform_lint('void setRGBAValues(int r, int g, in
t b, int a);', 'test.cpp', parameter_error_rules)) | 5130 self.perform_lint('void setRGBAValues(int r, int g, int
b, int a);', 'test.cpp', parameter_error_rules)) |
| 5117 | 5131 |
| 5118 # Verify that a simple substring match isn't done which would cause fals
e positives. | 5132 # Verify that a simple substring match isn't done which would cause fals
e positives. |
| 5119 self.assertEqual('', | 5133 self.assertEqual('', |
| 5120 self.perform_lint('void setNateLateCount(size_t elate)
;', 'test.cpp', parameter_error_rules)) | 5134 self.perform_lint('void setNateLateCount(size_t elate);
', 'test.cpp', parameter_error_rules)) |
| 5121 self.assertEqual('', | 5135 self.assertEqual('', |
| 5122 self.perform_lint('void funct(NateLate elate);', 'test
.cpp', parameter_error_rules)) | 5136 self.perform_lint('void funct(NateLate elate);', 'test.
cpp', parameter_error_rules)) |
| 5123 | 5137 |
| 5124 # Don't have generate warnings for functions (only declarations). | 5138 # Don't have generate warnings for functions (only declarations). |
| 5125 self.assertEqual('', | 5139 self.assertEqual('', |
| 5126 self.perform_lint('void funct(PassRefPtr<ScriptExecuti
onContext> context)\n' | 5140 self.perform_lint('void funct(PassRefPtr<ScriptExecutio
nContext> context)\n' |
| 5127 '{\n' | 5141 '{\n' |
| 5128 '}\n', 'test.cpp', parameter_error_r
ules)) | 5142 '}\n', 'test.cpp', parameter_error_ru
les)) |
| 5129 | 5143 |
| 5130 def test_comments(self): | 5144 def test_comments(self): |
| 5131 # A comment at the beginning of a line is ok. | 5145 # A comment at the beginning of a line is ok. |
| 5132 self.assert_lint('// comment', '') | 5146 self.assert_lint('// comment', '') |
| 5133 self.assert_lint(' // comment', '') | 5147 self.assert_lint(' // comment', '') |
| 5134 | 5148 |
| 5135 self.assert_lint('} // namespace WebCore', | 5149 self.assert_lint('} // namespace WebCore', |
| 5136 'One space before end of line comments' | 5150 'One space before end of line comments' |
| 5137 ' [whitespace/comments] [5]') | 5151 ' [whitespace/comments] [5]') |
| 5138 | 5152 |
| 5139 def test_redundant_virtual(self): | 5153 def test_redundant_virtual(self): |
| 5140 self.assert_lint('virtual void fooMethod() override;', '"virtual" is red
undant since function is already declared as "override" [readability/inheritanc
e] [4]') | 5154 self.assert_lint('virtual void fooMethod() override;', |
| 5141 self.assert_lint('virtual void fooMethod(\n) override {}', '"virtual" is
redundant since function is already declared as "override" [readability/inheri
tance] [4]') | 5155 '"virtual" is redundant since function is already decla
red as "override" [readability/inheritance] [4]') |
| 5142 self.assert_lint('virtual void fooMethod() final;', '"virtual" is redund
ant since function is already declared as "final" [readability/inheritance] [4]
') | 5156 self.assert_lint('virtual void fooMethod(\n) override {}', |
| 5143 self.assert_lint('virtual void fooMethod(\n) final {}', '"virtual" is re
dundant since function is already declared as "final" [readability/inheritance]
[4]') | 5157 '"virtual" is redundant since function is already decla
red as "override" [readability/inheritance] [4]') |
| 5158 self.assert_lint('virtual void fooMethod() final;', |
| 5159 '"virtual" is redundant since function is already decla
red as "final" [readability/inheritance] [4]') |
| 5160 self.assert_lint('virtual void fooMethod(\n) final {}', |
| 5161 '"virtual" is redundant since function is already decla
red as "final" [readability/inheritance] [4]') |
| 5144 | 5162 |
| 5145 def test_redundant_override(self): | 5163 def test_redundant_override(self): |
| 5146 self.assert_lint('void fooMethod() override final;', '"override" is redu
ndant since function is already declared as "final" [readability/inheritance] [
4]') | 5164 self.assert_lint('void fooMethod() override final;', |
| 5147 self.assert_lint('void fooMethod(\n) override final {}', '"override" is
redundant since function is already declared as "final" [readability/inheritanc
e] [4]') | 5165 '"override" is redundant since function is already decl
ared as "final" [readability/inheritance] [4]') |
| 5148 self.assert_lint('void fooMethod() final override;', '"override" is redu
ndant since function is already declared as "final" [readability/inheritance] [
4]') | 5166 self.assert_lint('void fooMethod(\n) override final {}', |
| 5149 self.assert_lint('void fooMethod(\n) final override {}', '"override" is
redundant since function is already declared as "final" [readability/inheritanc
e] [4]') | 5167 '"override" is redundant since function is already decl
ared as "final" [readability/inheritance] [4]') |
| 5168 self.assert_lint('void fooMethod() final override;', |
| 5169 '"override" is redundant since function is already decl
ared as "final" [readability/inheritance] [4]') |
| 5170 self.assert_lint('void fooMethod(\n) final override {}', |
| 5171 '"override" is redundant since function is already decl
ared as "final" [readability/inheritance] [4]') |
| 5150 | 5172 |
| 5151 def test_webkit_export_check(self): | 5173 def test_webkit_export_check(self): |
| 5152 webkit_export_error_rules = ('-', | 5174 webkit_export_error_rules = ('-', |
| 5153 '+readability/webkit_export') | 5175 '+readability/webkit_export') |
| 5154 self.assertEqual('', | 5176 self.assertEqual('', |
| 5155 self.perform_lint('WEBKIT_EXPORT int foo();\n', | 5177 self.perform_lint('WEBKIT_EXPORT int foo();\n', |
| 5156 'WebKit/chromium/public/test.h', | 5178 'WebKit/chromium/public/test.h', |
| 5157 webkit_export_error_rules)) | 5179 webkit_export_error_rules)) |
| 5158 self.assertEqual('', | 5180 self.assertEqual('', |
| 5159 self.perform_lint('WEBKIT_EXPORT int foo();\n', | 5181 self.perform_lint('WEBKIT_EXPORT int foo();\n', |
| 5160 'WebKit/chromium/tests/test.h', | 5182 'WebKit/chromium/tests/test.h', |
| 5161 webkit_export_error_rules)) | 5183 webkit_export_error_rules)) |
| 5162 self.assertEqual('WEBKIT_EXPORT should only be used in header files. [r
eadability/webkit_export] [5]', | 5184 self.assertEqual('WEBKIT_EXPORT should only be used in header files. [r
eadability/webkit_export] [5]', |
| 5163 self.perform_lint('WEBKIT_EXPORT int foo();\n', | 5185 self.perform_lint('WEBKIT_EXPORT int foo();\n', |
| 5164 'WebKit/chromium/public/test.cpp', | 5186 'WebKit/chromium/public/test.cpp', |
| 5165 webkit_export_error_rules)) | 5187 webkit_export_error_rules)) |
| 5166 self.assertEqual('WEBKIT_EXPORT should only appear in the chromium publi
c (or tests) directory. [readability/webkit_export] [5]', | 5188 self.assertEqual('WEBKIT_EXPORT should only appear in the chromium publi
c (or tests) directory. [readability/webkit_export] [5]', |
| 5167 self.perform_lint('WEBKIT_EXPORT int foo();\n', | 5189 self.perform_lint('WEBKIT_EXPORT int foo();\n', |
| 5168 'WebKit/chromium/src/test.h', | 5190 'WebKit/chromium/src/test.h', |
| 5169 webkit_export_error_rules)) | 5191 webkit_export_error_rules)) |
| 5170 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a
body. [readability/webkit_export] [5]', | 5192 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a
body. [readability/webkit_export] [5]', |
| 5171 self.perform_lint('WEBKIT_EXPORT int foo() { }\n', | 5193 self.perform_lint('WEBKIT_EXPORT int foo() { }\n', |
| 5172 'WebKit/chromium/public/test.h', | 5194 'WebKit/chromium/public/test.h', |
| 5173 webkit_export_error_rules)) | 5195 webkit_export_error_rules)) |
| 5174 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a
body. [readability/webkit_export] [5]', | 5196 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a
body. [readability/webkit_export] [5]', |
| 5175 self.perform_lint('WEBKIT_EXPORT inline int foo()\n' | 5197 self.perform_lint('WEBKIT_EXPORT inline int foo()\n' |
| 5176 '{\n' | 5198 '{\n' |
| 5177 '}\n', | 5199 '}\n', |
| 5178 'WebKit/chromium/public/test.h', | 5200 'WebKit/chromium/public/test.h', |
| 5179 webkit_export_error_rules)) | 5201 webkit_export_error_rules)) |
| 5180 self.assertEqual('WEBKIT_EXPORT should not be used with a pure virtual f
unction. [readability/webkit_export] [5]', | 5202 self.assertEqual('WEBKIT_EXPORT should not be used with a pure virtual f
unction. [readability/webkit_export] [5]', |
| 5181 self.perform_lint('{}\n' | 5203 self.perform_lint('{}\n' |
| 5182 'WEBKIT_EXPORT\n' | 5204 'WEBKIT_EXPORT\n' |
| 5183 'virtual\n' | 5205 'virtual\n' |
| 5184 'int\n' | 5206 'int\n' |
| 5185 'foo() = 0;\n', | 5207 'foo() = 0;\n', |
| 5186 'WebKit/chromium/public/test.h', | 5208 'WebKit/chromium/public/test.h', |
| 5187 webkit_export_error_rules)) | 5209 webkit_export_error_rules)) |
| 5188 self.assertEqual('', | 5210 self.assertEqual('', |
| 5189 self.perform_lint('{}\n' | 5211 self.perform_lint('{}\n' |
| 5190 'WEBKIT_EXPORT\n' | 5212 'WEBKIT_EXPORT\n' |
| 5191 'virtual\n' | 5213 'virtual\n' |
| 5192 'int\n' | 5214 'int\n' |
| 5193 'foo() = 0;\n', | 5215 'foo() = 0;\n', |
| 5194 'test.h', | 5216 'test.h', |
| 5195 webkit_export_error_rules)) | 5217 webkit_export_error_rules)) |
| 5196 | 5218 |
| 5197 def test_other(self): | 5219 def test_other(self): |
| 5198 # FIXME: Implement this. | 5220 # FIXME: Implement this. |
| 5199 pass | 5221 pass |
| 5200 | 5222 |
| 5201 | 5223 |
| 5202 class CppCheckerTest(unittest.TestCase): | 5224 class CppCheckerTest(unittest.TestCase): |
| 5203 | 5225 |
| 5204 """Tests CppChecker class.""" | 5226 """Tests CppChecker class.""" |
| 5205 | 5227 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5238 def test_ne(self): | 5260 def test_ne(self): |
| 5239 """Test __ne__ inequality function.""" | 5261 """Test __ne__ inequality function.""" |
| 5240 checker1 = self._checker() | 5262 checker1 = self._checker() |
| 5241 checker2 = self._checker() | 5263 checker2 = self._checker() |
| 5242 | 5264 |
| 5243 # != calls __ne__. | 5265 # != calls __ne__. |
| 5244 # By default, __ne__ always returns true on different objects. | 5266 # By default, __ne__ always returns true on different objects. |
| 5245 # Thus, just check the distinguishing case to verify that the | 5267 # Thus, just check the distinguishing case to verify that the |
| 5246 # code defines __ne__. | 5268 # code defines __ne__. |
| 5247 self.assertFalse(checker1 != checker2) | 5269 self.assertFalse(checker1 != checker2) |
| OLD | NEW |