Commit b0621671 authored by cjerdonek@webkit.org's avatar cjerdonek@webkit.org

Eliminated the filename parameter from functions in

check-webkit-style's cpp.py where it is no longer used.

Reviewed by Shinichiro Hamaji.

https://bugs.webkit.org/show_bug.cgi?id=34249

* Scripts/webkitpy/style/processors/cpp.py:
  - Reduced number of occurrences of "filename" variable from
    approximately 200 to 120.

* Scripts/webkitpy/style/processors/cpp_unittest.py:
  - Refactored unit tests as necessary to accommodate changes to cpp.py.
  - Fixed bug in CppStyleTestBase.perform_include_what_you_use()
    where the incorrect file extension was getting passed to
    cpp_style.check_language().

git-svn-id: svn://svn.chromium.org/blink/trunk@53998 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6f7644ff
2010-01-28 Chris Jerdonek <cjerdonek@webkit.org>
Reviewed by Shinichiro Hamaji.
Eliminated the filename parameter from functions in
check-webkit-style's cpp.py where it is no longer used.
https://bugs.webkit.org/show_bug.cgi?id=34249
* Scripts/webkitpy/style/processors/cpp.py:
- Reduced number of occurrences of "filename" variable from
approximately 200 to 120.
* Scripts/webkitpy/style/processors/cpp_unittest.py:
- Refactored unit tests as necessary to accommodate changes to cpp.py.
- Fixed bug in CppStyleTestBase.perform_include_what_you_use()
where the incorrect file extension was getting passed to
cpp_style.check_language().
2010-01-28 Chris Jerdonek <cjerdonek@webkit.org> 2010-01-28 Chris Jerdonek <cjerdonek@webkit.org>
Reviewed by Shinichiro Hamaji. Reviewed by Shinichiro Hamaji.
......
...@@ -105,6 +105,16 @@ class MockIo: ...@@ -105,6 +105,16 @@ class MockIo:
return self.mock_file return self.mock_file
class CppFunctionsTest(unittest.TestCase):
"""Supports testing functions that do not need CppStyleTestBase."""
def test_is_c_or_objective_c(self):
self.assertTrue(cpp_style.is_c_or_objective_c("c"))
self.assertTrue(cpp_style.is_c_or_objective_c("m"))
self.assertFalse(cpp_style.is_c_or_objective_c("cpp"))
class CppStyleTestBase(unittest.TestCase): class CppStyleTestBase(unittest.TestCase):
"""Provides some useful helper functions for cpp_style tests. """Provides some useful helper functions for cpp_style tests.
...@@ -128,7 +138,7 @@ class CppStyleTestBase(unittest.TestCase): ...@@ -128,7 +138,7 @@ class CppStyleTestBase(unittest.TestCase):
def perform_single_line_lint(self, code, file_name): def perform_single_line_lint(self, code, file_name):
error_collector = ErrorCollector(self.assert_) error_collector = ErrorCollector(self.assert_)
lines = code.split('\n') lines = code.split('\n')
cpp_style.remove_multi_line_comments(file_name, lines, error_collector) cpp_style.remove_multi_line_comments(lines, error_collector)
clean_lines = cpp_style.CleansedLines(lines) clean_lines = cpp_style.CleansedLines(lines)
include_state = cpp_style._IncludeState() include_state = cpp_style._IncludeState()
function_state = cpp_style._FunctionState(self.verbosity) function_state = cpp_style._FunctionState(self.verbosity)
...@@ -145,19 +155,18 @@ class CppStyleTestBase(unittest.TestCase): ...@@ -145,19 +155,18 @@ class CppStyleTestBase(unittest.TestCase):
return error_collector.results() return error_collector.results()
# Perform lint over multiple lines and return the error message. # Perform lint over multiple lines and return the error message.
def perform_multi_line_lint(self, code, file_name): def perform_multi_line_lint(self, code, file_extension):
error_collector = ErrorCollector(self.assert_) error_collector = ErrorCollector(self.assert_)
lines = code.split('\n') lines = code.split('\n')
cpp_style.remove_multi_line_comments(file_name, lines, error_collector) cpp_style.remove_multi_line_comments(lines, error_collector)
lines = cpp_style.CleansedLines(lines) lines = cpp_style.CleansedLines(lines)
ext = file_name[file_name.rfind('.') + 1:]
class_state = cpp_style._ClassState() class_state = cpp_style._ClassState()
file_state = cpp_style._FileState() file_state = cpp_style._FileState()
for i in xrange(lines.num_lines()): for i in xrange(lines.num_lines()):
cpp_style.check_style(file_name, lines, i, ext, file_state, error_collector) cpp_style.check_style(lines, i, file_extension, file_state, error_collector)
cpp_style.check_for_non_standard_constructs(file_name, lines, i, class_state, cpp_style.check_for_non_standard_constructs(lines, i, class_state,
error_collector) error_collector)
class_state.check_finished(file_name, error_collector) class_state.check_finished(error_collector)
return error_collector.results() return error_collector.results()
# Similar to perform_multi_line_lint, but calls check_language instead of # Similar to perform_multi_line_lint, but calls check_language instead of
...@@ -166,7 +175,7 @@ class CppStyleTestBase(unittest.TestCase): ...@@ -166,7 +175,7 @@ class CppStyleTestBase(unittest.TestCase):
error_collector = ErrorCollector(self.assert_) error_collector = ErrorCollector(self.assert_)
include_state = cpp_style._IncludeState() include_state = cpp_style._IncludeState()
lines = code.split('\n') lines = code.split('\n')
cpp_style.remove_multi_line_comments(file_name, lines, error_collector) cpp_style.remove_multi_line_comments(lines, error_collector)
lines = cpp_style.CleansedLines(lines) lines = cpp_style.CleansedLines(lines)
ext = file_name[file_name.rfind('.') + 1:] ext = file_name[file_name.rfind('.') + 1:]
for i in xrange(lines.num_lines()): for i in xrange(lines.num_lines()):
...@@ -189,14 +198,13 @@ class CppStyleTestBase(unittest.TestCase): ...@@ -189,14 +198,13 @@ class CppStyleTestBase(unittest.TestCase):
Returns: Returns:
The accumulated errors. The accumulated errors.
""" """
file_name = 'foo.cpp'
error_collector = ErrorCollector(self.assert_) error_collector = ErrorCollector(self.assert_)
function_state = cpp_style._FunctionState(self.verbosity) function_state = cpp_style._FunctionState(self.verbosity)
lines = code.split('\n') lines = code.split('\n')
cpp_style.remove_multi_line_comments(file_name, lines, error_collector) cpp_style.remove_multi_line_comments(lines, error_collector)
lines = cpp_style.CleansedLines(lines) lines = cpp_style.CleansedLines(lines)
for i in xrange(lines.num_lines()): for i in xrange(lines.num_lines()):
cpp_style.check_for_function_lengths(file_name, lines, i, cpp_style.check_for_function_lengths(lines, i,
function_state, error_collector) function_state, error_collector)
return error_collector.results() return error_collector.results()
...@@ -205,10 +213,11 @@ class CppStyleTestBase(unittest.TestCase): ...@@ -205,10 +213,11 @@ class CppStyleTestBase(unittest.TestCase):
error_collector = ErrorCollector(self.assert_) error_collector = ErrorCollector(self.assert_)
include_state = cpp_style._IncludeState() include_state = cpp_style._IncludeState()
lines = code.split('\n') lines = code.split('\n')
cpp_style.remove_multi_line_comments(filename, lines, error_collector) cpp_style.remove_multi_line_comments(lines, error_collector)
lines = cpp_style.CleansedLines(lines) lines = cpp_style.CleansedLines(lines)
file_extension = filename[filename.rfind('.') + 1:]
for i in xrange(lines.num_lines()): for i in xrange(lines.num_lines()):
cpp_style.check_language(filename, lines, i, '.h', include_state, cpp_style.check_language(filename, lines, i, file_extension, include_state,
error_collector) error_collector)
# We could clear the error_collector here, but this should # We could clear the error_collector here, but this should
# also be fine, since our IncludeWhatYouUse unittests do not # also be fine, since our IncludeWhatYouUse unittests do not
...@@ -232,10 +241,12 @@ class CppStyleTestBase(unittest.TestCase): ...@@ -232,10 +241,12 @@ class CppStyleTestBase(unittest.TestCase):
self.assertEquals(expected_message, messages) self.assertEquals(expected_message, messages)
def assert_multi_line_lint(self, code, expected_message, file_name='foo.h'): def assert_multi_line_lint(self, code, expected_message, file_name='foo.h'):
self.assertEquals(expected_message, self.perform_multi_line_lint(code, file_name)) file_extension = file_name[file_name.rfind('.') + 1:]
self.assertEquals(expected_message, self.perform_multi_line_lint(code, file_extension))
def assert_multi_line_lint_re(self, code, expected_message_re, file_name='foo.h'): def assert_multi_line_lint_re(self, code, expected_message_re, file_name='foo.h'):
message = self.perform_multi_line_lint(code, file_name) file_extension = file_name[file_name.rfind('.') + 1:]
message = self.perform_multi_line_lint(code, file_extension)
if not re.search(expected_message_re, message): if not re.search(expected_message_re, message):
self.fail('Message was:\n' + message + 'Expected match to "' + expected_message_re + '"') self.fail('Message was:\n' + message + 'Expected match to "' + expected_message_re + '"')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment