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

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

Issue 2014063002: Run format-webkit on webkitpy code (without string conversion). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 def test_parameter_list(self): 203 def test_parameter_list(self):
204 elided_lines = ['int blah(PassRefPtr<MyClass> paramName,', 204 elided_lines = ['int blah(PassRefPtr<MyClass> paramName,',
205 'const Other1Class& foo,', 205 'const Other1Class& foo,',
206 'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * param = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),', 206 'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * param = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),',
207 'int* myCount = 0);'] 207 'int* myCount = 0);']
208 start_position = cpp_style.Position(row=0, column=8) 208 start_position = cpp_style.Position(row=0, column=8)
209 end_position = cpp_style.Position(row=3, column=16) 209 end_position = cpp_style.Position(row=3, column=16)
210 210
211 expected_parameters = ({'type': 'PassRefPtr<MyClass>', 'name': 'paramNam e', 'row': 0}, 211 expected_parameters = ({'type': 'PassRefPtr<MyClass>', 'name': 'paramNam e', 'row': 0},
212 {'type': 'const Other1Class&', 'name': 'foo', 'ro w': 1}, 212 {'type': 'const Other1Class&', 'name': 'foo', 'ro w': 1},
213 {'type': 'const ComplexTemplate<Class1, NestedTem plate<P1, P2> >* const *', 'name': 'param', 'row': 2}, 213 {'type': 'const ComplexTemplate<Class1, NestedTem plate<P1, P2> >* const *',
214 'name': 'param',
215 'row': 2},
214 {'type': 'int*', 'name': 'myCount', 'row': 3}) 216 {'type': 'int*', 'name': 'myCount', 'row': 3})
215 index = 0 217 index = 0
216 for parameter in cpp_style.parameter_list(elided_lines, start_position, end_position): 218 for parameter in cpp_style.parameter_list(elided_lines, start_position, end_position):
217 expected_parameter = expected_parameters[index] 219 expected_parameter = expected_parameters[index]
218 self.assertEqual(parameter.type, expected_parameter['type']) 220 self.assertEqual(parameter.type, expected_parameter['type'])
219 self.assertEqual(parameter.name, expected_parameter['name']) 221 self.assertEqual(parameter.name, expected_parameter['name'])
220 self.assertEqual(parameter.row, expected_parameter['row']) 222 self.assertEqual(parameter.row, expected_parameter['row'])
221 index += 1 223 index += 1
222 self.assertEqual(index, len(expected_parameters)) 224 self.assertEqual(index, len(expected_parameters))
223 225
224 def test_check_parameter_against_text(self): 226 def test_check_parameter_against_text(self):
225 error_collector = ErrorCollector(self.assertTrue) 227 error_collector = ErrorCollector(self.assertTrue)
226 parameter = cpp_style.Parameter('FooF ooF', 4, 1) 228 parameter = cpp_style.Parameter('FooF ooF', 4, 1)
227 self.assertFalse(cpp_style._check_parameter_name_against_text(parameter, 'FooF', error_collector)) 229 self.assertFalse(cpp_style._check_parameter_name_against_text(parameter, 'FooF', error_collector))
228 self.assertEqual(error_collector.results(), 230 self.assertEqual(error_collector.results(),
229 'The parameter name "ooF" adds no information, so it sh ould be removed. [readability/parameter_name] [5]') 231 'The parameter name "ooF" adds no information, so it sh ould be removed. [readability/parameter_name] [5]')
230 232
231 233
232 class CppStyleTestBase(unittest.TestCase): 234 class CppStyleTestBase(unittest.TestCase):
235
233 """Provides some useful helper functions for cpp_style tests. 236 """Provides some useful helper functions for cpp_style tests.
234 237
235 Attributes: 238 Attributes:
236 min_confidence: An integer that is the current minimum confidence 239 min_confidence: An integer that is the current minimum confidence
237 level for the tests. 240 level for the tests.
238 241
239 """ 242 """
240 243
241 # FIXME: Refactor the unit tests so the confidence level is passed 244 # FIXME: Refactor the unit tests so the confidence level is passed
242 # explicitly, just like it is in the real code. 245 # explicitly, just like it is in the real code.
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 'is_pure': False, 582 'is_pure': False,
580 'is_declaration': True, 583 'is_declaration': True,
581 'parameter_list': 584 'parameter_list':
582 ({'type': 'unsigned', 'name': 'a', 'row': 0}, 585 ({'type': 'unsigned', 'name': 'a', 'row': 0},
583 {'type': 'short', 'name': 'b', 'row': 0}, 586 {'type': 'short', 'name': 'b', 'row': 0},
584 {'type': 'long', 'name': 'c', 'row': 0}, 587 {'type': 'long', 'name': 'c', 'row': 0},
585 {'type': 'long long short unsigned int', 'name': '', 'row': 0} )}) 588 {'type': 'long long short unsigned int', 'name': '', 'row': 0} )})
586 589
587 # Some parameter type with modifiers and no parameter names. 590 # Some parameter type with modifiers and no parameter names.
588 function_state = self.perform_function_detection( 591 function_state = self.perform_function_detection(
589 ['virtual void determineARIADropEffects(Vector<String>*&, const unsi gned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >, int );'], 592 [
593 'virtual void determineARIADropEffects(Vector<String>*&, const u nsigned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >, int);'],
qyearsley 2016/05/27 16:06:03 In cases like this, the formatting could be made b
590 {'name': 'determineARIADropEffects', 594 {'name': 'determineARIADropEffects',
591 'modifiers_and_return_type': 'virtual void', 595 'modifiers_and_return_type': 'virtual void',
592 'parameter_start_position': (0, 37), 596 'parameter_start_position': (0, 37),
593 'function_name_start_position': (0, 13), 597 'function_name_start_position': (0, 13),
594 'parameter_end_position': (0, 147), 598 'parameter_end_position': (0, 147),
595 'body_start_position': (0, 147), 599 'body_start_position': (0, 147),
596 'end_position': (0, 148), 600 'end_position': (0, 148),
597 'is_pure': False, 601 'is_pure': False,
598 'is_declaration': True, 602 'is_declaration': True,
599 'parameter_list': 603 'parameter_list':
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 filename='casting.cpp', 807 filename='casting.cpp',
804 fs=fs) 808 fs=fs)
805 self.assertEqual(message, 'static_cast of class objects is not allow ed. Add toFoo in Foo.h and use it instead.' 809 self.assertEqual(message, 'static_cast of class objects is not allow ed. Add toFoo in Foo.h and use it instead.'
806 ' [runtime/casting] [4]') 810 ' [runtime/casting] [4]')
807 finally: 811 finally:
808 fs.read_text_file = orig_read_text_file_fn 812 fs.read_text_file = orig_read_text_file_fn
809 813
810 # We cannot test this functionality because of difference of 814 # We cannot test this functionality because of difference of
811 # function definitions. Anyway, we may never enable this. 815 # function definitions. Anyway, we may never enable this.
812 # 816 #
813 # # Test for unnamed arguments in a method. 817 # Test for unnamed arguments in a method.
814 # def test_check_for_unnamed_params(self): 818 # def test_check_for_unnamed_params(self):
815 # message = ('All parameters should be named in a function' 819 # message = ('All parameters should be named in a function'
816 # ' [readability/function] [3]') 820 # ' [readability/function] [3]')
817 # self.assert_lint('virtual void A(int*) const;', message) 821 # self.assert_lint('virtual void A(int*) const;', message)
818 # self.assert_lint('virtual void B(void (*fn)(int*));', message) 822 # self.assert_lint('virtual void B(void (*fn)(int*));', message)
819 # self.assert_lint('virtual void C(int*);', message) 823 # self.assert_lint('virtual void C(int*);', message)
820 # self.assert_lint('void *(*f)(void *) = x;', message) 824 # self.assert_lint('void *(*f)(void *) = x;', message)
821 # self.assert_lint('void Method(char*) {', message) 825 # self.assert_lint('void Method(char*) {', message)
822 # self.assert_lint('void Method(char*);', message) 826 # self.assert_lint('void Method(char*);', message)
823 # self.assert_lint('void Method(char* /*x*/);', message) 827 # self.assert_lint('void Method(char* /*x*/);', message)
824 # self.assert_lint('typedef void (*Method)(int32);', message) 828 # self.assert_lint('typedef void (*Method)(int32);', message)
825 # self.assert_lint('static void operator delete[](void*) throw();', messag e) 829 # self.assert_lint('static void operator delete[](void*) throw();', messag e)
826 # 830 #
827 # self.assert_lint('virtual void D(int* p);', '') 831 # self.assert_lint('virtual void D(int* p);', '')
828 # self.assert_lint('void operator delete(void* x) throw();', '') 832 # self.assert_lint('void operator delete(void* x) throw();', '')
829 # self.assert_lint('void Method(char* x)\n{', '') 833 # self.assert_lint('void Method(char* x)\n{', '')
830 # self.assert_lint('void Method(char* /*x*/)\n{', '') 834 # self.assert_lint('void Method(char* /*x*/)\n{', '')
831 # self.assert_lint('void Method(char* x);', '') 835 # self.assert_lint('void Method(char* x);', '')
832 # self.assert_lint('typedef void (*Method)(int32 x);', '') 836 # self.assert_lint('typedef void (*Method)(int32 x);', '')
833 # self.assert_lint('static void operator delete[](void* x) throw();', '') 837 # self.assert_lint('static void operator delete[](void* x) throw();', '')
834 # self.assert_lint('static void operator delete[](void* /*x*/) throw();', '') 838 # self.assert_lint('static void operator delete[](void* /*x*/) throw();', '')
835 # 839 #
836 # # This one should technically warn, but doesn't because the function 840 # This one should technically warn, but doesn't because the function
837 # # pointer is confusing. 841 # pointer is confusing.
838 # self.assert_lint('virtual void E(void (*fn)(int* p));', '') 842 # self.assert_lint('virtual void E(void (*fn)(int* p));', '')
839 843
840 # Test deprecated casts such as int(d) 844 # Test deprecated casts such as int(d)
841 def test_deprecated_cast(self): 845 def test_deprecated_cast(self):
842 self.assert_lint( 846 self.assert_lint(
843 'int a = int(2.2);', 847 'int a = int(2.2);',
844 'Using deprecated casting style. ' 848 'Using deprecated casting style. '
845 'Use static_cast<int>(...) instead' 849 'Use static_cast<int>(...) instead'
846 ' [readability/casting] [4]') 850 ' [readability/casting] [4]')
847 # Checks for false positives... 851 # Checks for false positives...
(...skipping 2916 matching lines...) Expand 10 before | Expand all | Expand 10 after
3764 'Use adoptPtr and OwnPtr<HDC> when calling CreateCompatibleDC to avo id potential ' 3768 'Use adoptPtr and OwnPtr<HDC> when calling CreateCompatibleDC to avo id potential '
3765 'memory leaks. [runtime/leaky_pattern] [5]') 3769 'memory leaks. [runtime/leaky_pattern] [5]')
3766 self.assert_leaky_pattern_check( 3770 self.assert_leaky_pattern_check(
3767 'adoptPtr(CreateCompatibleDC(dc));', 3771 'adoptPtr(CreateCompatibleDC(dc));',
3768 '') 3772 '')
3769 3773
3770 3774
3771 class WebKitStyleTest(CppStyleTestBase): 3775 class WebKitStyleTest(CppStyleTestBase):
3772 3776
3773 # for http://webkit.org/coding/coding-style.html 3777 # for http://webkit.org/coding/coding-style.html
3778
3774 def test_indentation(self): 3779 def test_indentation(self):
3775 # 1. Use spaces, not tabs. Tabs should only appear in files that 3780 # 1. Use spaces, not tabs. Tabs should only appear in files that
3776 # require them for semantic meaning, like Makefiles. 3781 # require them for semantic meaning, like Makefiles.
3777 self.assert_multi_line_lint( 3782 self.assert_multi_line_lint(
3778 'class Foo {\n' 3783 'class Foo {\n'
3779 ' int goo;\n' 3784 ' int goo;\n'
3780 '};', 3785 '};',
3781 '') 3786 '')
3782 self.assert_multi_line_lint( 3787 self.assert_multi_line_lint(
3783 'class Foo {\n' 3788 'class Foo {\n'
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
4151 '}\n', 4156 '}\n',
4152 '') 4157 '')
4153 self.assert_multi_line_lint( 4158 self.assert_multi_line_lint(
4154 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n', 4159 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n',
4155 '') 4160 '')
4156 self.assert_multi_line_lint( 4161 self.assert_multi_line_lint(
4157 '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsCon troller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n', 4162 '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsCon troller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n',
4158 'Extra space after ( in if [whitespace/parens] [5]') 4163 'Extra space after ( in if [whitespace/parens] [5]')
4159 # FIXME: currently we only check first conditional, so we cannot detect errors in next ones. 4164 # FIXME: currently we only check first conditional, so we cannot detect errors in next ones.
4160 # self.assert_multi_line_lint( 4165 # self.assert_multi_line_lint(
4161 # '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCo ntroller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } whil e (0 )\n', 4166 # '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsContro ller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0 )\n',
4162 # 'Mismatching spaces inside () in if [whitespace/parens] [5]') 4167 # 'Mismatching spaces inside () in if [whitespace/parens] [5]')
4163 self.assert_multi_line_lint( 4168 self.assert_multi_line_lint(
4164 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', 4169 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n',
4165 '') 4170 '')
4166 self.assert_multi_line_lint( 4171 self.assert_multi_line_lint(
4167 'if (condition) {\n' 4172 'if (condition) {\n'
4168 ' doSomething();\n' 4173 ' doSomething();\n'
4169 ' doSomethingAgain();\n' 4174 ' doSomethingAgain();\n'
4170 '}\n' 4175 '}\n'
4171 'else {\n' 4176 'else {\n'
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
5288 def test_ne(self): 5293 def test_ne(self):
5289 """Test __ne__ inequality function.""" 5294 """Test __ne__ inequality function."""
5290 checker1 = self._checker() 5295 checker1 = self._checker()
5291 checker2 = self._checker() 5296 checker2 = self._checker()
5292 5297
5293 # != calls __ne__. 5298 # != calls __ne__.
5294 # By default, __ne__ always returns true on different objects. 5299 # By default, __ne__ always returns true on different objects.
5295 # Thus, just check the distinguishing case to verify that the 5300 # Thus, just check the distinguishing case to verify that the
5296 # code defines __ne__. 5301 # code defines __ne__.
5297 self.assertFalse(checker1 != checker2) 5302 self.assertFalse(checker1 != checker2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698