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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

Issue 2329263002: Run format-webkitpy and fix long lines. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 self.assertEqual(cpp_style.create_skeleton_parameters('b{d}'), 'b ,') 197 self.assertEqual(cpp_style.create_skeleton_parameters('b{d}'), 'b ,')
198 198
199 def test_find_parameter_name_index(self): 199 def test_find_parameter_name_index(self):
200 self.assertEqual(cpp_style.find_parameter_name_index(' int a '), 5) 200 self.assertEqual(cpp_style.find_parameter_name_index(' int a '), 5)
201 self.assertEqual(cpp_style.find_parameter_name_index(' PassRefPtr ') , 16) 201 self.assertEqual(cpp_style.find_parameter_name_index(' PassRefPtr ') , 16)
202 self.assertEqual(cpp_style.find_parameter_name_index('double'), 6) 202 self.assertEqual(cpp_style.find_parameter_name_index('double'), 6)
203 203
204 def test_parameter_list(self): 204 def test_parameter_list(self):
205 elided_lines = ['int blah(PassRefPtr<MyClass> paramName,', 205 elided_lines = ['int blah(PassRefPtr<MyClass> paramName,',
206 'const Other1Class& foo,', 206 'const Other1Class& foo,',
207 'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * param = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),', 207 ('const ComplexTemplate<Class1, NestedTemplate<P1, P2> > * const * param = '
208 'new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(3 4, 42),'),
208 'int* myCount = 0);'] 209 'int* myCount = 0);']
209 start_position = cpp_style.Position(row=0, column=8) 210 start_position = cpp_style.Position(row=0, column=8)
210 end_position = cpp_style.Position(row=3, column=16) 211 end_position = cpp_style.Position(row=3, column=16)
211 212
212 expected_parameters = ({'type': 'PassRefPtr<MyClass>', 'name': 'paramNam e', 'row': 0}, 213 expected_parameters = ({'type': 'PassRefPtr<MyClass>', 'name': 'paramNam e', 'row': 0},
213 {'type': 'const Other1Class&', 'name': 'foo', 'ro w': 1}, 214 {'type': 'const Other1Class&', 'name': 'foo', 'ro w': 1},
214 {'type': 'const ComplexTemplate<Class1, NestedTem plate<P1, P2> >* const *', 215 {'type': 'const ComplexTemplate<Class1, NestedTem plate<P1, P2> >* const *',
215 'name': 'param', 216 'name': 'param',
216 'row': 2}, 217 'row': 2},
217 {'type': 'int*', 'name': 'myCount', 'row': 3}) 218 {'type': 'int*', 'name': 'myCount', 'row': 3})
218 index = 0 219 index = 0
219 for parameter in cpp_style.parameter_list(elided_lines, start_position, end_position): 220 for parameter in cpp_style.parameter_list(elided_lines, start_position, end_position):
220 expected_parameter = expected_parameters[index] 221 expected_parameter = expected_parameters[index]
221 self.assertEqual(parameter.type, expected_parameter['type']) 222 self.assertEqual(parameter.type, expected_parameter['type'])
222 self.assertEqual(parameter.name, expected_parameter['name']) 223 self.assertEqual(parameter.name, expected_parameter['name'])
223 self.assertEqual(parameter.row, expected_parameter['row']) 224 self.assertEqual(parameter.row, expected_parameter['row'])
224 index += 1 225 index += 1
225 self.assertEqual(index, len(expected_parameters)) 226 self.assertEqual(index, len(expected_parameters))
226 227
227 def test_check_parameter_against_text(self): 228 def test_check_parameter_against_text(self):
228 error_collector = ErrorCollector(self.assertTrue) 229 error_collector = ErrorCollector(self.assertTrue)
229 parameter = cpp_style.Parameter('FooF ooF', 4, 1) 230 parameter = cpp_style.Parameter('FooF ooF', 4, 1)
230 self.assertFalse(cpp_style._check_parameter_name_against_text(parameter, 'FooF', error_collector)) 231 self.assertFalse(cpp_style._check_parameter_name_against_text(parameter, 'FooF', error_collector))
231 self.assertEqual(error_collector.results(), 232 self.assertEqual(
232 'The parameter name "ooF" adds no information, so it sh ould be removed. [readability/parameter_name] [5]') 233 error_collector.results(),
234 'The parameter name "ooF" adds no information, so it should be remov ed. [readability/parameter_name] [5]')
233 235
234 236
235 class CppStyleTestBase(unittest.TestCase): 237 class CppStyleTestBase(unittest.TestCase):
236 """Provides some useful helper functions for cpp_style tests. 238 """Provides some useful helper functions for cpp_style tests.
237 239
238 Attributes: 240 Attributes:
239 min_confidence: An integer that is the current minimum confidence 241 min_confidence: An integer that is the current minimum confidence
240 level for the tests. 242 level for the tests.
241 """ 243 """
242 244
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 'is_declaration': True, 585 'is_declaration': True,
584 'parameter_list': 586 'parameter_list':
585 ({'type': 'unsigned', 'name': 'a', 'row': 0}, 587 ({'type': 'unsigned', 'name': 'a', 'row': 0},
586 {'type': 'short', 'name': 'b', 'row': 0}, 588 {'type': 'short', 'name': 'b', 'row': 0},
587 {'type': 'long', 'name': 'c', 'row': 0}, 589 {'type': 'long', 'name': 'c', 'row': 0},
588 {'type': 'long long short unsigned int', 'name': '', 'row': 0} )}) 590 {'type': 'long long short unsigned int', 'name': '', 'row': 0} )})
589 591
590 # Some parameter type with modifiers and no parameter names. 592 # Some parameter type with modifiers and no parameter names.
591 self.perform_function_detection( 593 self.perform_function_detection(
592 [ 594 [
593 'virtual void determineARIADropEffects(Vector<String>*&, const u nsigned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >, int);'], 595 'virtual void determineARIADropEffects(Vector<String>*&, '
596 'const unsigned long int*&, const MediaPlayer::Preload, '
597 'Other<Other2, Other3<P1, P2> >, int);'
598 ],
594 {'name': 'determineARIADropEffects', 599 {'name': 'determineARIADropEffects',
595 'modifiers_and_return_type': 'virtual void', 600 'modifiers_and_return_type': 'virtual void',
596 'parameter_start_position': (0, 37), 601 'parameter_start_position': (0, 37),
597 'function_name_start_position': (0, 13), 602 'function_name_start_position': (0, 13),
598 'parameter_end_position': (0, 147), 603 'parameter_end_position': (0, 147),
599 'body_start_position': (0, 147), 604 'body_start_position': (0, 147),
600 'end_position': (0, 148), 605 'end_position': (0, 148),
601 'is_pure': False, 606 'is_pure': False,
602 'is_declaration': True, 607 'is_declaration': True,
603 'parameter_list': 608 'parameter_list':
604 ({'type': 'Vector<String>*&', 'name': '', 'row': 0}, 609 ({'type': 'Vector<String>*&', 'name': '', 'row': 0},
605 {'type': 'const unsigned long int*&', 'name': '', 'row': 0}, 610 {'type': 'const unsigned long int*&', 'name': '', 'row': 0},
606 {'type': 'const MediaPlayer::Preload', 'name': '', 'row': 0}, 611 {'type': 'const MediaPlayer::Preload', 'name': '', 'row': 0},
607 {'type': 'Other<Other2, Other3<P1, P2> >', 'name': '', 'row': 0}, 612 {'type': 'Other<Other2, Other3<P1, P2> >', 'name': '', 'row': 0},
608 {'type': 'int', 'name': '', 'row': 0})}) 613 {'type': 'int', 'name': '', 'row': 0})})
609 614
610 # Try parsing a function with a very complex definition. 615 # Try parsing a function with a very complex definition.
611 self.perform_function_detection( 616 self.perform_function_detection(
612 ['#define MyMacro(a) a', 617 ['#define MyMacro(a) a',
613 'virtual', 618 'virtual',
614 'AnotherTemplate<Class1, Class2> aFunctionName(PassRefPtr<MyClass> paramName,', 619 'AnotherTemplate<Class1, Class2> aFunctionName(PassRefPtr<MyClass> paramName,',
615 'const Other1Class& foo,', 620 'const Other1Class& foo,',
616 'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * pa ram = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),', 621 ('const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * p aram = '
622 'new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),'),
617 'int* myCount = 0);'], 623 'int* myCount = 0);'],
618 {'name': 'aFunctionName', 624 {'name': 'aFunctionName',
619 'modifiers_and_return_type': 'virtual AnotherTemplate<Class1, Class 2>', 625 'modifiers_and_return_type': 'virtual AnotherTemplate<Class1, Class 2>',
620 'function_name_start_position': (2, 32), 626 'function_name_start_position': (2, 32),
621 'parameter_start_position': (2, 45), 627 'parameter_start_position': (2, 45),
622 'parameter_end_position': (5, 17), 628 'parameter_end_position': (5, 17),
623 'body_start_position': (5, 17), 629 'body_start_position': (5, 17),
624 'end_position': (5, 18), 630 'end_position': (5, 18),
625 'is_pure': False, 631 'is_pure': False,
626 'is_declaration': True, 632 'is_declaration': True,
(...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 self.assert_language_rules_check('foo.h', 2818 self.assert_language_rules_check('foo.h',
2813 '#include "a.h"\n' 2819 '#include "a.h"\n'
2814 '#include "c.h"\n' 2820 '#include "c.h"\n'
2815 '#include "b.h"\n', 2821 '#include "b.h"\n',
2816 'Alphabetical sorting problem. [build/ include_order] [4]') 2822 'Alphabetical sorting problem. [build/ include_order] [4]')
2817 2823
2818 def test_check_line_break_after_own_header(self): 2824 def test_check_line_break_after_own_header(self):
2819 self.assert_language_rules_check('foo.cpp', 2825 self.assert_language_rules_check('foo.cpp',
2820 '#include "foo.h"\n' 2826 '#include "foo.h"\n'
2821 '#include "bar.h"\n', 2827 '#include "bar.h"\n',
2822 'You should add a blank line after impl ementation file\'s own header. [build/include_order] [4]') 2828 ('You should add a blank line after imp lementation file\'s own header.'
2829 ' [build/include_order] [4]'))
2823 2830
2824 self.assert_language_rules_check('foo.cpp', 2831 self.assert_language_rules_check('foo.cpp',
2825 '#include "foo.h"\n' 2832 '#include "foo.h"\n'
2826 '\n' 2833 '\n'
2827 '#include "bar.h"\n', 2834 '#include "bar.h"\n',
2828 '') 2835 '')
2829 2836
2830 def test_check_preprocessor_in_include_section(self): 2837 def test_check_preprocessor_in_include_section(self):
2831 self.assert_language_rules_check('foo.cpp', 2838 self.assert_language_rules_check('foo.cpp',
2832 '#include "foo.h"\n' 2839 '#include "foo.h"\n'
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after
4117 '') 4124 '')
4118 self.assert_multi_line_lint( 4125 self.assert_multi_line_lint(
4119 'if (condition) {\n' 4126 'if (condition) {\n'
4120 ' doSomething();\n' 4127 ' doSomething();\n'
4121 '} else {\n' 4128 '} else {\n'
4122 ' doSomethingElse();\n' 4129 ' doSomethingElse();\n'
4123 ' doSomethingElseAgain();\n' 4130 ' doSomethingElseAgain();\n'
4124 '}\n', 4131 '}\n',
4125 '') 4132 '')
4126 self.assert_multi_line_lint( 4133 self.assert_multi_line_lint(
4127 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n', 4134 '#define TEST_ASSERT(expression) do { if (!(expression)) { '
4135 'TestsController::shared().testFailed(__FILE__, __LINE__, #expressio n); '
4136 'return; } } while (0)\n',
4128 '') 4137 '')
4129 self.assert_multi_line_lint( 4138 self.assert_multi_line_lint(
4130 '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsCon troller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n', 4139 '#define TEST_ASSERT(expression) do { if ( !(expression)) { '
4140 'TestsController::shared().testFailed(__FILE__, __LINE__, #expressio n); '
4141 'return; } } while (0)\n',
4131 'Extra space after ( in if [whitespace/parens] [5]') 4142 'Extra space after ( in if [whitespace/parens] [5]')
4132 # FIXME: currently we only check first conditional, so we cannot detect errors in next ones. 4143 # FIXME: currently we only check first conditional, so we cannot detect errors in next ones.
4133 # self.assert_multi_line_lint(
4134 # '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsContro ller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0 )\n',
4135 # 'Mismatching spaces inside () in if [whitespace/parens] [5]')
4136 self.assert_multi_line_lint( 4144 self.assert_multi_line_lint(
4137 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', 4145 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n',
4138 '') 4146 '')
4139 self.assert_multi_line_lint( 4147 self.assert_multi_line_lint(
4140 'if (condition) {\n' 4148 'if (condition) {\n'
4141 ' doSomething();\n' 4149 ' doSomething();\n'
4142 ' doSomethingAgain();\n' 4150 ' doSomethingAgain();\n'
4143 '}\n' 4151 '}\n'
4144 'else {\n' 4152 'else {\n'
4145 ' doSomethingElse();\n' 4153 ' doSomethingElse();\n'
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
4890 'foo.h') 4898 'foo.h')
4891 4899
4892 def test_ctype_fucntion(self): 4900 def test_ctype_fucntion(self):
4893 self.assert_lint( 4901 self.assert_lint(
4894 'int i = isascii(8);', 4902 'int i = isascii(8);',
4895 'Use equivalent function in <wtf/ASCIICType.h> instead of the ' 4903 'Use equivalent function in <wtf/ASCIICType.h> instead of the '
4896 'isascii() function. [runtime/ctype_function] [4]', 4904 'isascii() function. [runtime/ctype_function] [4]',
4897 'foo.cpp') 4905 'foo.cpp')
4898 4906
4899 def test_names(self): 4907 def test_names(self):
4900 name_underscore_error_message = " is incorrectly named. Don't use unders cores in your identifier names. [readability/naming/underscores] [4]" 4908 name_underscore_error_message = (" is incorrectly named. Don't use under scores in your identifier names."
4901 name_tooshort_error_message = " is incorrectly named. Don't use the sing le letter 'l' as an identifier name. [readability/naming] [4]" 4909 " [readability/naming/underscores] [4] ")
4910 name_tooshort_error_message = (" is incorrectly named. Don't use the sin gle letter 'l' as an identifier name."
4911 " [readability/naming] [4]")
4902 4912
4903 # Basic cases from WebKit style guide. 4913 # Basic cases from WebKit style guide.
4904 self.assert_lint('struct Data;', '') 4914 self.assert_lint('struct Data;', '')
4905 self.assert_lint('size_t bufferSize;', '') 4915 self.assert_lint('size_t bufferSize;', '')
4906 self.assert_lint('class HTMLDocument;', '') 4916 self.assert_lint('class HTMLDocument;', '')
4907 self.assert_lint('String mimeType();', '') 4917 self.assert_lint('String mimeType();', '')
4908 self.assert_lint('size_t buffer_size;', 4918 self.assert_lint('size_t buffer_size;',
4909 'buffer_size' + name_underscore_error_message) 4919 'buffer_size' + name_underscore_error_message)
4910 self.assert_lint('short m_length;', '') 4920 self.assert_lint('short m_length;', '')
4911 self.assert_lint('short _length;', 4921 self.assert_lint('short _length;',
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5036 5046
5037 # There is an exception for GTK+ API. 5047 # There is an exception for GTK+ API.
5038 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S ource/Webkit/gtk/webkit/foo.cpp') 5048 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S ource/Webkit/gtk/webkit/foo.cpp')
5039 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S ource/Webkit2/UIProcess/gtk/foo.cpp') 5049 self.assert_lint('void webkit_web_view_load(int var1, int var2)', '', 'S ource/Webkit2/UIProcess/gtk/foo.cpp')
5040 5050
5041 # Test that this doesn't also apply to files not in a 'gtk' directory. 5051 # Test that this doesn't also apply to files not in a 'gtk' directory.
5042 self.assert_lint('void webkit_web_view_load(int var1, int var2)', 5052 self.assert_lint('void webkit_web_view_load(int var1, int var2)',
5043 'webkit_web_view_load is incorrectly named. Don\'t use underscores in your identifier names.' 5053 'webkit_web_view_load is incorrectly named. Don\'t use underscores in your identifier names.'
5044 ' [readability/naming/underscores] [4]', 'Source/Webki t/webkit/foo.cpp') 5054 ' [readability/naming/underscores] [4]', 'Source/Webki t/webkit/foo.cpp')
5045 # Test that this doesn't also apply to names that don't start with 'webk it_'. 5055 # Test that this doesn't also apply to names that don't start with 'webk it_'.
5046 self.assert_lint_one_of_many_errors_re('void otherkit_web_view_load(int var1, int var2)', 5056 self.assert_lint_one_of_many_errors_re(
5047 'otherkit_web_view_load is incorr ectly named. Don\'t use underscores in your identifier names.' 5057 'void otherkit_web_view_load(int var1, int var2)',
5048 ' [readability/naming/underscore s] [4]', 'Source/Webkit/webkit/foo.cpp') 5058 'otherkit_web_view_load is incorrectly named. Don\'t use underscores in your identifier names.'
5059 ' [readability/naming/underscores] [4]', 'Source/Webkit/webkit/foo. cpp')
5049 5060
5050 # There is an exception for some unit tests that begin with "tst_". 5061 # There is an exception for some unit tests that begin with "tst_".
5051 self.assert_lint('void tst_QWebFrame::arrayObjectEnumerable(int var1, in t var2)', '') 5062 self.assert_lint('void tst_QWebFrame::arrayObjectEnumerable(int var1, in t var2)', '')
5052 5063
5053 # The Qt API uses names that begin with "qt_" or "_q_". 5064 # The Qt API uses names that begin with "qt_" or "_q_".
5054 self.assert_lint('void QTFrame::qt_drt_is_awesome(int var1, int var2)', '') 5065 self.assert_lint('void QTFrame::qt_drt_is_awesome(int var1, int var2)', '')
5055 self.assert_lint('void QTFrame::_q_drt_is_awesome(int var1, int var2)', '') 5066 self.assert_lint('void QTFrame::_q_drt_is_awesome(int var1, int var2)', '')
5056 self.assert_lint('void qt_drt_is_awesome(int var1, int var2);', '') 5067 self.assert_lint('void qt_drt_is_awesome(int var1, int var2);', '')
5057 self.assert_lint('void _q_drt_is_awesome(int var1, int var2);', '') 5068 self.assert_lint('void _q_drt_is_awesome(int var1, int var2);', '')
5058 5069
(...skipping 28 matching lines...) Expand all
5087 self.assert_lint('OwnPtr<uint32_t> variable(new uint32_t);', '') 5098 self.assert_lint('OwnPtr<uint32_t> variable(new uint32_t);', '')
5088 self.assert_lint('OwnPtr<uint32_t> variable(new (expr) uint32_t);', '') 5099 self.assert_lint('OwnPtr<uint32_t> variable(new (expr) uint32_t);', '')
5089 self.assert_lint('OwnPtr<uint32_t> under_score(new uint32_t);', 5100 self.assert_lint('OwnPtr<uint32_t> under_score(new uint32_t);',
5090 'under_score' + name_underscore_error_message) 5101 'under_score' + name_underscore_error_message)
5091 5102
5092 # Conversion operator declaration. 5103 # Conversion operator declaration.
5093 self.assert_lint('operator int64_t();', '') 5104 self.assert_lint('operator int64_t();', '')
5094 5105
5095 def test_parameter_names(self): 5106 def test_parameter_names(self):
5096 # Leave meaningless variable names out of function declarations. 5107 # Leave meaningless variable names out of function declarations.
5097 meaningless_variable_name_error_message = 'The parameter name "%s" adds no information, so it should be removed. [readability/parameter_name] [5]' 5108 # This variable name is very long. # pylint: disable=invalid-name
5109 meaningless_variable_name_error_message = ('The parameter name "%s" adds no information, '
5110 'so it should be removed. [r eadability/parameter_name] [5]')
5098 5111
5099 parameter_error_rules = ('-', 5112 parameter_error_rules = ('-', '+readability/parameter_name')
5100 '+readability/parameter_name')
5101 # No variable name, so no error. 5113 # No variable name, so no error.
5102 self.assertEqual('', 5114 self.assertEqual(
5103 self.perform_lint('void func(int);', 'test.cpp', parame ter_error_rules)) 5115 '',
5116 self.perform_lint('void func(int);', 'test.cpp', parameter_error_rul es))
5104 5117
5105 # Verify that copying the name of the set function causes the error (wit h some odd casing). 5118 # Verify that copying the name of the set function causes the error (wit h some odd casing).
5106 self.assertEqual(meaningless_variable_name_error_message % 'itemCount', 5119 self.assertEqual(
5107 self.perform_lint('void setItemCount(size_t itemCount); ', 'test.cpp', parameter_error_rules)) 5120 meaningless_variable_name_error_message % 'itemCount',
5108 self.assertEqual(meaningless_variable_name_error_message % 'abcCount', 5121 self.perform_lint('void setItemCount(size_t itemCount);', 'test.cpp' , parameter_error_rules))
5109 self.perform_lint('void setABCCount(size_t abcCount);', 'test.cpp', parameter_error_rules)) 5122 self.assertEqual(
5123 meaningless_variable_name_error_message % 'abcCount',
5124 self.perform_lint('void setABCCount(size_t abcCount);', 'test.cpp', parameter_error_rules))
5110 5125
5111 # Verify that copying a type name will trigger the warning (even if the type is a template parameter). 5126 # Verify that copying a type name will trigger the warning (even if the type is a template parameter).
5112 self.assertEqual(meaningless_variable_name_error_message % 'context', 5127 self.assertEqual(
5113 self.perform_lint('void funct(PassRefPtr<ScriptExecutio nContext> context);', 'test.cpp', parameter_error_rules)) 5128 meaningless_variable_name_error_message % 'context',
5129 self.perform_lint('void funct(PassRefPtr<ScriptExecutionContext> con text);', 'test.cpp', parameter_error_rules))
5114 5130
5115 # Verify that acronyms as variable names trigger the error (for both set functions and type names). 5131 # Verify that acronyms as variable names trigger the error (for both set functions and type names).
5116 self.assertEqual(meaningless_variable_name_error_message % 'ec', 5132 self.assertEqual(
5117 self.perform_lint('void setExceptionCode(int ec);', 'te st.cpp', parameter_error_rules)) 5133 meaningless_variable_name_error_message % 'ec',
5118 self.assertEqual(meaningless_variable_name_error_message % 'ec', 5134 self.perform_lint('void setExceptionCode(int ec);', 'test.cpp', para meter_error_rules))
5119 self.perform_lint('void funct(ExceptionCode ec);', 'tes t.cpp', parameter_error_rules)) 5135 self.assertEqual(
5136 meaningless_variable_name_error_message % 'ec',
5137 self.perform_lint('void funct(ExceptionCode ec);', 'test.cpp', param eter_error_rules))
5120 5138
5121 # 'object' alone, appended, or as part of an acronym is meaningless. 5139 # 'object' alone, appended, or as part of an acronym is meaningless.
5122 self.assertEqual(meaningless_variable_name_error_message % 'object', 5140 self.assertEqual(
5123 self.perform_lint('void funct(RenderView object);', 'te st.cpp', parameter_error_rules)) 5141 meaningless_variable_name_error_message % 'object',
5124 self.assertEqual(meaningless_variable_name_error_message % 'viewObject', 5142 self.perform_lint('void funct(RenderView object);', 'test.cpp', para meter_error_rules))
5125 self.perform_lint('void funct(RenderView viewObject);', 'test.cpp', parameter_error_rules)) 5143 self.assertEqual(
5126 self.assertEqual(meaningless_variable_name_error_message % 'rvo', 5144 meaningless_variable_name_error_message % 'viewObject',
5127 self.perform_lint('void funct(RenderView rvo);', 'test. cpp', parameter_error_rules)) 5145 self.perform_lint('void funct(RenderView viewObject);', 'test.cpp', parameter_error_rules))
5146 self.assertEqual(
5147 meaningless_variable_name_error_message % 'rvo',
5148 self.perform_lint('void funct(RenderView rvo);', 'test.cpp', paramet er_error_rules))
5128 5149
5129 # Check that r, g, b, and a are allowed. 5150 # Check that r, g, b, and a are allowed.
5130 self.assertEqual('', 5151 self.assertEqual(
5131 self.perform_lint('void setRGBAValues(int r, int g, int b, int a);', 'test.cpp', parameter_error_rules)) 5152 '',
5153 self.perform_lint('void setRGBAValues(int r, int g, int b, int a);', 'test.cpp', parameter_error_rules))
5132 5154
5133 # Verify that a simple substring match isn't done which would cause fals e positives. 5155 # Verify that a simple substring match isn't done which would cause fals e positives.
5134 self.assertEqual('', 5156 self.assertEqual(
5135 self.perform_lint('void setNateLateCount(size_t elate); ', 'test.cpp', parameter_error_rules)) 5157 '',
5136 self.assertEqual('', 5158 self.perform_lint('void setNateLateCount(size_t elate);', 'test.cpp' , parameter_error_rules))
5137 self.perform_lint('void funct(NateLate elate);', 'test. cpp', parameter_error_rules)) 5159 self.assertEqual(
5160 '',
5161 self.perform_lint('void funct(NateLate elate);', 'test.cpp', paramet er_error_rules))
5138 5162
5139 # Don't have generate warnings for functions (only declarations). 5163 # Don't have generate warnings for functions (only declarations).
5140 self.assertEqual('', 5164 self.assertEqual(
5141 self.perform_lint('void funct(PassRefPtr<ScriptExecutio nContext> context)\n' 5165 '',
5142 '{\n' 5166 self.perform_lint('void funct(PassRefPtr<ScriptExecutionContext> con text)\n{\n}\n', 'test.cpp', parameter_error_rules))
5143 '}\n', 'test.cpp', parameter_error_ru les))
5144 5167
5145 def test_comments(self): 5168 def test_comments(self):
5146 # A comment at the beginning of a line is ok. 5169 # A comment at the beginning of a line is ok.
5147 self.assert_lint('// comment', '') 5170 self.assert_lint('// comment', '')
5148 self.assert_lint(' // comment', '') 5171 self.assert_lint(' // comment', '')
5149 5172
5150 self.assert_lint('} // namespace WebCore', 5173 self.assert_lint('} // namespace WebCore',
5151 'One space before end of line comments' 5174 'One space before end of line comments'
5152 ' [whitespace/comments] [5]') 5175 ' [whitespace/comments] [5]')
5153 5176
(...skipping 25 matching lines...) Expand all
5179 'WebKit/chromium/public/test.h', 5202 'WebKit/chromium/public/test.h',
5180 webkit_export_error_rules)) 5203 webkit_export_error_rules))
5181 self.assertEqual('', 5204 self.assertEqual('',
5182 self.perform_lint('WEBKIT_EXPORT int foo();\n', 5205 self.perform_lint('WEBKIT_EXPORT int foo();\n',
5183 'WebKit/chromium/tests/test.h', 5206 'WebKit/chromium/tests/test.h',
5184 webkit_export_error_rules)) 5207 webkit_export_error_rules))
5185 self.assertEqual('WEBKIT_EXPORT should only be used in header files. [r eadability/webkit_export] [5]', 5208 self.assertEqual('WEBKIT_EXPORT should only be used in header files. [r eadability/webkit_export] [5]',
5186 self.perform_lint('WEBKIT_EXPORT int foo();\n', 5209 self.perform_lint('WEBKIT_EXPORT int foo();\n',
5187 'WebKit/chromium/public/test.cpp', 5210 'WebKit/chromium/public/test.cpp',
5188 webkit_export_error_rules)) 5211 webkit_export_error_rules))
5189 self.assertEqual('WEBKIT_EXPORT should only appear in the chromium publi c (or tests) directory. [readability/webkit_export] [5]', 5212 self.assertEqual('WEBKIT_EXPORT should only appear in the chromium publi c (or tests) directory. '
5213 '[readability/webkit_export] [5]',
5190 self.perform_lint('WEBKIT_EXPORT int foo();\n', 5214 self.perform_lint('WEBKIT_EXPORT int foo();\n',
5191 'WebKit/chromium/src/test.h', 5215 'WebKit/chromium/src/test.h',
5192 webkit_export_error_rules)) 5216 webkit_export_error_rules))
5193 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a body. [readability/webkit_export] [5]', 5217 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a body. [readability/webkit_export] [5]',
5194 self.perform_lint('WEBKIT_EXPORT int foo() { }\n', 5218 self.perform_lint('WEBKIT_EXPORT int foo() { }\n',
5195 'WebKit/chromium/public/test.h', 5219 'WebKit/chromium/public/test.h',
5196 webkit_export_error_rules)) 5220 webkit_export_error_rules))
5197 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a body. [readability/webkit_export] [5]', 5221 self.assertEqual('WEBKIT_EXPORT should not be used on a function with a body. [readability/webkit_export] [5]',
5198 self.perform_lint('WEBKIT_EXPORT inline int foo()\n' 5222 self.perform_lint('WEBKIT_EXPORT inline int foo()\n'
5199 '{\n' 5223 '{\n'
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5261 def test_ne(self): 5285 def test_ne(self):
5262 """Test __ne__ inequality function.""" 5286 """Test __ne__ inequality function."""
5263 checker1 = self._checker() 5287 checker1 = self._checker()
5264 checker2 = self._checker() 5288 checker2 = self._checker()
5265 5289
5266 # != calls __ne__. 5290 # != calls __ne__.
5267 # By default, __ne__ always returns true on different objects. 5291 # By default, __ne__ always returns true on different objects.
5268 # Thus, just check the distinguishing case to verify that the 5292 # Thus, just check the distinguishing case to verify that the
5269 # code defines __ne__. 5293 # code defines __ne__.
5270 self.assertFalse(checker1 != checker2) 5294 self.assertFalse(checker1 != checker2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698