| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 'is_pure': False, | 581 'is_pure': False, |
| 580 'is_declaration': True, | 582 'is_declaration': True, |
| 581 'parameter_list': | 583 'parameter_list': |
| 582 ({'type': 'unsigned', 'name': 'a', 'row': 0}, | 584 ({'type': 'unsigned', 'name': 'a', 'row': 0}, |
| 583 {'type': 'short', 'name': 'b', 'row': 0}, | 585 {'type': 'short', 'name': 'b', 'row': 0}, |
| 584 {'type': 'long', 'name': 'c', 'row': 0}, | 586 {'type': 'long', 'name': 'c', 'row': 0}, |
| 585 {'type': 'long long short unsigned int', 'name': '', 'row': 0}
)}) | 587 {'type': 'long long short unsigned int', 'name': '', 'row': 0}
)}) |
| 586 | 588 |
| 587 # Some parameter type with modifiers and no parameter names. | 589 # Some parameter type with modifiers and no parameter names. |
| 588 function_state = self.perform_function_detection( | 590 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
);'], | 591 [ |
| 592 'virtual void determineARIADropEffects(Vector<String>*&, const u
nsigned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >,
int);'], |
| 590 {'name': 'determineARIADropEffects', | 593 {'name': 'determineARIADropEffects', |
| 591 'modifiers_and_return_type': 'virtual void', | 594 'modifiers_and_return_type': 'virtual void', |
| 592 'parameter_start_position': (0, 37), | 595 'parameter_start_position': (0, 37), |
| 593 'function_name_start_position': (0, 13), | 596 'function_name_start_position': (0, 13), |
| 594 'parameter_end_position': (0, 147), | 597 'parameter_end_position': (0, 147), |
| 595 'body_start_position': (0, 147), | 598 'body_start_position': (0, 147), |
| 596 'end_position': (0, 148), | 599 'end_position': (0, 148), |
| 597 'is_pure': False, | 600 'is_pure': False, |
| 598 'is_declaration': True, | 601 'is_declaration': True, |
| 599 'parameter_list': | 602 'parameter_list': |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 filename='casting.cpp', | 806 filename='casting.cpp', |
| 804 fs=fs) | 807 fs=fs) |
| 805 self.assertEqual(message, 'static_cast of class objects is not allow
ed. Add toFoo in Foo.h and use it instead.' | 808 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]') | 809 ' [runtime/casting] [4]') |
| 807 finally: | 810 finally: |
| 808 fs.read_text_file = orig_read_text_file_fn | 811 fs.read_text_file = orig_read_text_file_fn |
| 809 | 812 |
| 810 # We cannot test this functionality because of difference of | 813 # We cannot test this functionality because of difference of |
| 811 # function definitions. Anyway, we may never enable this. | 814 # function definitions. Anyway, we may never enable this. |
| 812 # | 815 # |
| 813 # # Test for unnamed arguments in a method. | 816 # Test for unnamed arguments in a method. |
| 814 # def test_check_for_unnamed_params(self): | 817 # def test_check_for_unnamed_params(self): |
| 815 # message = ('All parameters should be named in a function' | 818 # message = ('All parameters should be named in a function' |
| 816 # ' [readability/function] [3]') | 819 # ' [readability/function] [3]') |
| 817 # self.assert_lint('virtual void A(int*) const;', message) | 820 # self.assert_lint('virtual void A(int*) const;', message) |
| 818 # self.assert_lint('virtual void B(void (*fn)(int*));', message) | 821 # self.assert_lint('virtual void B(void (*fn)(int*));', message) |
| 819 # self.assert_lint('virtual void C(int*);', message) | 822 # self.assert_lint('virtual void C(int*);', message) |
| 820 # self.assert_lint('void *(*f)(void *) = x;', message) | 823 # self.assert_lint('void *(*f)(void *) = x;', message) |
| 821 # self.assert_lint('void Method(char*) {', message) | 824 # self.assert_lint('void Method(char*) {', message) |
| 822 # self.assert_lint('void Method(char*);', message) | 825 # self.assert_lint('void Method(char*);', message) |
| 823 # self.assert_lint('void Method(char* /*x*/);', message) | 826 # self.assert_lint('void Method(char* /*x*/);', message) |
| 824 # self.assert_lint('typedef void (*Method)(int32);', message) | 827 # self.assert_lint('typedef void (*Method)(int32);', message) |
| 825 # self.assert_lint('static void operator delete[](void*) throw();', messag
e) | 828 # self.assert_lint('static void operator delete[](void*) throw();', messag
e) |
| 826 # | 829 # |
| 827 # self.assert_lint('virtual void D(int* p);', '') | 830 # self.assert_lint('virtual void D(int* p);', '') |
| 828 # self.assert_lint('void operator delete(void* x) throw();', '') | 831 # self.assert_lint('void operator delete(void* x) throw();', '') |
| 829 # self.assert_lint('void Method(char* x)\n{', '') | 832 # self.assert_lint('void Method(char* x)\n{', '') |
| 830 # self.assert_lint('void Method(char* /*x*/)\n{', '') | 833 # self.assert_lint('void Method(char* /*x*/)\n{', '') |
| 831 # self.assert_lint('void Method(char* x);', '') | 834 # self.assert_lint('void Method(char* x);', '') |
| 832 # self.assert_lint('typedef void (*Method)(int32 x);', '') | 835 # self.assert_lint('typedef void (*Method)(int32 x);', '') |
| 833 # self.assert_lint('static void operator delete[](void* x) throw();', '') | 836 # self.assert_lint('static void operator delete[](void* x) throw();', '') |
| 834 # self.assert_lint('static void operator delete[](void* /*x*/) throw();',
'') | 837 # self.assert_lint('static void operator delete[](void* /*x*/) throw();',
'') |
| 835 # | 838 # |
| 836 # # This one should technically warn, but doesn't because the function | 839 # This one should technically warn, but doesn't because the function |
| 837 # # pointer is confusing. | 840 # pointer is confusing. |
| 838 # self.assert_lint('virtual void E(void (*fn)(int* p));', '') | 841 # self.assert_lint('virtual void E(void (*fn)(int* p));', '') |
| 839 | 842 |
| 840 # Test deprecated casts such as int(d) | 843 # Test deprecated casts such as int(d) |
| 841 def test_deprecated_cast(self): | 844 def test_deprecated_cast(self): |
| 842 self.assert_lint( | 845 self.assert_lint( |
| 843 'int a = int(2.2);', | 846 'int a = int(2.2);', |
| 844 'Using deprecated casting style. ' | 847 'Using deprecated casting style. ' |
| 845 'Use static_cast<int>(...) instead' | 848 'Use static_cast<int>(...) instead' |
| 846 ' [readability/casting] [4]') | 849 ' [readability/casting] [4]') |
| 847 # Checks for false positives... | 850 # Checks for false positives... |
| (...skipping 3303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4151 '}\n', | 4154 '}\n', |
| 4152 '') | 4155 '') |
| 4153 self.assert_multi_line_lint( | 4156 self.assert_multi_line_lint( |
| 4154 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont
roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', | 4157 '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsCont
roller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', |
| 4155 '') | 4158 '') |
| 4156 self.assert_multi_line_lint( | 4159 self.assert_multi_line_lint( |
| 4157 '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsCon
troller::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while
(0)\n', | 4160 '#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]') | 4161 'Extra space after ( in if [whitespace/parens] [5]') |
| 4159 # FIXME: currently we only check first conditional, so we cannot detect
errors in next ones. | 4162 # FIXME: currently we only check first conditional, so we cannot detect
errors in next ones. |
| 4160 # self.assert_multi_line_lint( | 4163 # 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', | 4164 # '#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]') | 4165 # 'Mismatching spaces inside () in if [whitespace/parens] [5]') |
| 4163 self.assert_multi_line_lint( | 4166 self.assert_multi_line_lint( |
| 4164 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', | 4167 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', |
| 4165 '') | 4168 '') |
| 4166 self.assert_multi_line_lint( | 4169 self.assert_multi_line_lint( |
| 4167 'if (condition) {\n' | 4170 'if (condition) {\n' |
| 4168 ' doSomething();\n' | 4171 ' doSomething();\n' |
| 4169 ' doSomethingAgain();\n' | 4172 ' doSomethingAgain();\n' |
| 4170 '}\n' | 4173 '}\n' |
| 4171 'else {\n' | 4174 'else {\n' |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5288 def test_ne(self): | 5291 def test_ne(self): |
| 5289 """Test __ne__ inequality function.""" | 5292 """Test __ne__ inequality function.""" |
| 5290 checker1 = self._checker() | 5293 checker1 = self._checker() |
| 5291 checker2 = self._checker() | 5294 checker2 = self._checker() |
| 5292 | 5295 |
| 5293 # != calls __ne__. | 5296 # != calls __ne__. |
| 5294 # By default, __ne__ always returns true on different objects. | 5297 # By default, __ne__ always returns true on different objects. |
| 5295 # Thus, just check the distinguishing case to verify that the | 5298 # Thus, just check the distinguishing case to verify that the |
| 5296 # code defines __ne__. | 5299 # code defines __ne__. |
| 5297 self.assertFalse(checker1 != checker2) | 5300 self.assertFalse(checker1 != checker2) |
| OLD | NEW |