summaryrefslogtreecommitdiffstats
path: root/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py')
-rw-r--r--WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py98
1 files changed, 94 insertions, 4 deletions
diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index 6d5c24b..13b053c 100644
--- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -205,10 +205,27 @@ class CppStyleTestBase(unittest.TestCase):
cpp_style.remove_multi_line_comments(lines, error_collector)
lines = cpp_style.CleansedLines(lines)
for i in xrange(lines.num_lines()):
+ cpp_style.detect_functions(lines, i,
+ function_state, error_collector)
cpp_style.check_for_function_lengths(lines, i,
function_state, error_collector)
return error_collector.results()
+ # Similar to perform_function_lengths_check, but calls check_pass_ptr_usage
+ # instead of check_for_function_lengths.
+ def perform_pass_ptr_check(self, code):
+ error_collector = ErrorCollector(self.assert_)
+ function_state = cpp_style._FunctionState(self.min_confidence)
+ lines = code.split('\n')
+ cpp_style.remove_multi_line_comments(lines, error_collector)
+ lines = cpp_style.CleansedLines(lines)
+ for i in xrange(lines.num_lines()):
+ cpp_style.detect_functions(lines, i,
+ function_state, error_collector)
+ cpp_style.check_pass_ptr_usage(lines, i,
+ function_state, error_collector)
+ return error_collector.results()
+
def perform_include_what_you_use(self, code, filename='foo.h', io=codecs):
# First, build up the include state.
error_collector = ErrorCollector(self.assert_)
@@ -2432,6 +2449,20 @@ class CheckForFunctionLengthsTest(CppStyleTestBase):
def test_function_length_check_definition_above_severity1(self):
self.assert_function_length_check_above_error_level(1)
+ def test_function_length_check_definition_severity1_plus_indented(self):
+ error_level = 1
+ error_lines = self.trigger_lines(error_level) + 1
+ trigger_level = self.trigger_lines(self.min_confidence)
+ indent_spaces = ' '
+ self.assert_function_lengths_check(
+ re.sub(r'(?m)^(.)', indent_spaces + r'\1',
+ 'void test_indent(int x)\n' + self.function_body(error_lines)),
+ ('Small and focused functions are preferred: '
+ 'test_indent() has %d non-comment lines '
+ '(error triggered by exceeding %d lines).'
+ ' [readability/fn_size] [%d]')
+ % (error_lines, trigger_level, error_level))
+
def test_function_length_check_definition_severity1_plus_blanks(self):
error_level = 1
error_lines = self.trigger_lines(error_level) + 1
@@ -2449,11 +2480,11 @@ class CheckForFunctionLengthsTest(CppStyleTestBase):
error_lines = self.trigger_lines(error_level) + 1
trigger_level = self.trigger_lines(self.min_confidence)
self.assert_function_lengths_check(
- ('my_namespace::my_other_namespace::MyVeryLongTypeName*\n'
- 'my_namespace::my_other_namespace::MyFunction(int arg1, char* arg2)'
+ ('my_namespace::my_other_namespace::MyVeryLongTypeName<Type1, bool func(const Element*)>*\n'
+ 'my_namespace::my_other_namespace<Type3, Type4>::~MyFunction<Type5<Type6, Type7> >(int arg1, char* arg2)'
+ self.function_body(error_lines)),
('Small and focused functions are preferred: '
- 'my_namespace::my_other_namespace::MyFunction()'
+ 'my_namespace::my_other_namespace<Type3, Type4>::~MyFunction<Type5<Type6, Type7> >()'
' has %d non-comment lines '
'(error triggered by exceeding %d lines).'
' [readability/fn_size] [%d]')
@@ -2484,7 +2515,7 @@ class CheckForFunctionLengthsTest(CppStyleTestBase):
'FixGoogleUpdate_AllValues_MachineApp) has %d non-comment lines '
'(error triggered by exceeding %d lines).'
' [readability/fn_size] [%d]')
- % (error_lines+1, trigger_level, error_level))
+ % (error_lines, trigger_level, error_level))
def test_function_length_check_definition_severity1_for_bad_test_doesnt_break(self):
error_level = 1
@@ -2714,6 +2745,65 @@ class NoNonVirtualDestructorsTest(CppStyleTestBase):
'virtual method(s), one declared at line 2. [runtime/virtual] [4]'])
+class PassPtrTest(CppStyleTestBase):
+ # For http://webkit.org/coding/RefPtr.html
+
+ def assert_pass_ptr_check(self, code, expected_message):
+ """Check warnings for Pass*Ptr are as expected.
+
+ Args:
+ code: C++ source code expected to generate a warning message.
+ expected_message: Message expected to be generated by the C++ code.
+ """
+ self.assertEquals(expected_message,
+ self.perform_pass_ptr_check(code))
+
+ def test_pass_ref_ptr_in_function(self):
+ # Local variables should never be PassRefPtr.
+ self.assert_pass_ptr_check(
+ 'int myFunction()\n'
+ '{\n'
+ ' PassRefPtr<Type1> variable = variable2;\n'
+ '}',
+ 'Local variables should never be PassRefPtr (see '
+ 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]')
+
+ def test_pass_own_ptr_in_function(self):
+ # Local variables should never be PassRefPtr.
+ self.assert_pass_ptr_check(
+ 'int myFunction()\n'
+ '{\n'
+ ' PassOwnPtr<Type1> variable = variable2;\n'
+ '}',
+ 'Local variables should never be PassOwnPtr (see '
+ 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]')
+
+ def test_pass_other_type_ptr_in_function(self):
+ # Local variables should never be PassRefPtr.
+ self.assert_pass_ptr_check(
+ 'int myFunction()\n'
+ '{\n'
+ ' PassOtherTypePtr<Type1> variable;\n'
+ '}',
+ 'Local variables should never be PassOtherTypePtr (see '
+ 'http://webkit.org/coding/RefPtr.html). [readability/pass_ptr] [5]')
+
+ def test_pass_ref_ptr_return_value(self):
+ self.assert_pass_ptr_check(
+ 'PassRefPtr<Type1>\n'
+ 'myFunction(int)\n'
+ '{\n'
+ '}',
+ '')
+
+ def test_pass_ref_ptr_parameter_value(self):
+ self.assert_pass_ptr_check(
+ 'int myFunction(PassRefPtr<Type1>)\n'
+ '{\n'
+ '}',
+ '')
+
+
class WebKitStyleTest(CppStyleTestBase):
# for http://webkit.org/coding/coding-style.html