[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9
cjerdonek at webkit.org
cjerdonek at webkit.org
Thu Feb 4 21:36:17 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 50f39fe4134e65268c7ab51691177282aea4ff9e
Author: cjerdonek at webkit.org <cjerdonek at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Feb 2 06:41:28 2010 +0000
Addressed FIXME in check-webkit-style so that the carriage-return
check will work for patches.
Reviewed by Shinichiro Hamaji.
https://bugs.webkit.org/show_bug.cgi?id=34260
Also added support for limiting the number of errors reported
per category, per file.
* Scripts/webkitpy/style/checker.py:
- Added new "whitespace/carriage_return" category from common.py.
- Added MAX_REPORTS_PER_CATEGORY dictionary.
- Added max_reports_per_category attribute to ProcessorOptions class.
- Refactored StyleChecker._process_file().
* Scripts/webkitpy/style/checker_unittest.py:
- Updated ProcessorOptionsTest tests.
- Added test to check MAX_REPORTS_PER_CATEGORY.
* Scripts/webkitpy/style/error_handlers.py:
- Added support for suppressing the display of errors after
reaching a per-category maximum (from max_reports_per_category).
* Scripts/webkitpy/style/error_handlers_unittest.py:
- Added test for suppressing error display.
* Scripts/webkitpy/style/processors/common.py: Added.
- Moved carriage-return check to new file.
* Scripts/webkitpy/style/processors/common_unittest.py: Added.
- Added unit tests for carriage-return check.
* Scripts/webkitpy/style/unittests.py:
- Added reference to common_unittest.py.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54206 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 9175eb8..f71248c 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,41 @@
+2010-02-01 Chris Jerdonek <cjerdonek at webkit.org>
+
+ Reviewed by Shinichiro Hamaji.
+
+ Addressed FIXME in check-webkit-style so that the carriage-return
+ check will work for patches.
+
+ https://bugs.webkit.org/show_bug.cgi?id=34260
+
+ Also added support for limiting the number of errors reported
+ per category, per file.
+
+ * Scripts/webkitpy/style/checker.py:
+ - Added new "whitespace/carriage_return" category from common.py.
+ - Added MAX_REPORTS_PER_CATEGORY dictionary.
+ - Added max_reports_per_category attribute to ProcessorOptions class.
+ - Refactored StyleChecker._process_file().
+
+ * Scripts/webkitpy/style/checker_unittest.py:
+ - Updated ProcessorOptionsTest tests.
+ - Added test to check MAX_REPORTS_PER_CATEGORY.
+
+ * Scripts/webkitpy/style/error_handlers.py:
+ - Added support for suppressing the display of errors after
+ reaching a per-category maximum (from max_reports_per_category).
+
+ * Scripts/webkitpy/style/error_handlers_unittest.py:
+ - Added test for suppressing error display.
+
+ * Scripts/webkitpy/style/processors/common.py: Added.
+ - Moved carriage-return check to new file.
+
+ * Scripts/webkitpy/style/processors/common_unittest.py: Added.
+ - Added unit tests for carriage-return check.
+
+ * Scripts/webkitpy/style/unittests.py:
+ - Added reference to common_unittest.py.
+
2010-02-01 Shinichiro Hamaji <hamaji at chromium.org>
Reviewed by Eric Seidel.
diff --git a/WebKitTools/Scripts/webkitpy/style/checker.py b/WebKitTools/Scripts/webkitpy/style/checker.py
index a365946..6dca715 100644
--- a/WebKitTools/Scripts/webkitpy/style/checker.py
+++ b/WebKitTools/Scripts/webkitpy/style/checker.py
@@ -37,6 +37,8 @@ import sys
from .. style_references import parse_patch
from error_handlers import DefaultStyleErrorHandler
from error_handlers import PatchStyleErrorHandler
+from processors.common import check_no_carriage_return
+from processors.common import categories as CommonCategories
from processors.cpp import CppProcessor
from processors.text import TextProcessor
@@ -106,10 +108,19 @@ SKIPPED_FILES_WITHOUT_WARNING = [
]
+# FIXME: Check that the keys are in _style_categories().
+#
+# The maximum number of errors to report per file, per category.
+# If a category is not a key, then it has no maximum.
+MAX_REPORTS_PER_CATEGORY = {
+ "whitespace/carriage_return": 1
+}
+
+
def style_categories():
"""Return the set of all categories used by check-webkit-style."""
- # If other processors had categories, we would take their union here.
- return CppProcessor.categories
+ # Take the union across all processors.
+ return CommonCategories.union(CppProcessor.categories)
def webkit_argument_defaults():
@@ -290,12 +301,19 @@ class ProcessorOptions(object):
"""
- def __init__(self, output_format="emacs", verbosity=1, filter=None,
- git_commit=None, extra_flag_values=None):
- if filter is None:
- filter = CategoryFilter()
+ def __init__(self,
+ output_format="emacs",
+ verbosity=1,
+ filter=None,
+ max_reports_per_category=None,
+ git_commit=None,
+ extra_flag_values=None):
if extra_flag_values is None:
extra_flag_values = {}
+ if filter is None:
+ filter = CategoryFilter()
+ if max_reports_per_category is None:
+ max_reports_per_category = {}
if output_format not in ("emacs", "vs7"):
raise ValueError('Invalid "output_format" parameter: '
@@ -307,24 +325,27 @@ class ProcessorOptions(object):
"value must be an integer between 1-5 inclusive. "
'Value given: "%s".' % verbosity)
- self.output_format = output_format
- self.verbosity = verbosity
+ self.extra_flag_values = extra_flag_values
self.filter = filter
self.git_commit = git_commit
- self.extra_flag_values = extra_flag_values
+ self.max_reports_per_category = max_reports_per_category
+ self.output_format = output_format
+ self.verbosity = verbosity
# Useful for unit testing.
def __eq__(self, other):
"""Return whether this ProcessorOptions instance is equal to another."""
- if self.output_format != other.output_format:
- return False
- if self.verbosity != other.verbosity:
+ if self.extra_flag_values != other.extra_flag_values:
return False
if self.filter != other.filter:
return False
if self.git_commit != other.git_commit:
return False
- if self.extra_flag_values != other.extra_flag_values:
+ if self.max_reports_per_category != other.max_reports_per_category:
+ return False
+ if self.output_format != other.output_format:
+ return False
+ if self.verbosity != other.verbosity:
return False
return True
@@ -568,8 +589,12 @@ class ArgumentParser(object):
filter = CategoryFilter(filter_rules)
- options = ProcessorOptions(output_format, verbosity, filter,
- git_commit, extra_flag_values)
+ options = ProcessorOptions(extra_flag_values=extra_flag_values,
+ filter=filter,
+ git_commit=git_commit,
+ max_reports_per_category=MAX_REPORTS_PER_CATEGORY,
+ output_format=output_format,
+ verbosity=verbosity)
return (filenames, options)
@@ -720,35 +745,36 @@ class StyleChecker(object):
# '\r\n' as in Windows), a warning is issued below if this file
# is processed.
if file_path == '-':
- lines = codecs.StreamReaderWriter(sys.stdin,
- codecs.getreader('utf8'),
- codecs.getwriter('utf8'),
- 'replace').read().split('\n')
+ file = codecs.StreamReaderWriter(sys.stdin,
+ codecs.getreader('utf8'),
+ codecs.getwriter('utf8'),
+ 'replace')
else:
- lines = codecs.open(file_path, 'r', 'utf8', 'replace').read().split('\n')
+ file = codecs.open(file_path, 'r', 'utf8', 'replace')
- carriage_return_found = False
- # Remove trailing '\r'.
- for line_number in range(len(lines)):
- if lines[line_number].endswith('\r'):
- lines[line_number] = lines[line_number].rstrip('\r')
- carriage_return_found = True
+ contents = file.read()
except IOError:
self._stderr_write("Skipping input '%s': Can't open for reading\n" % file_path)
return
- processor.process(lines)
+ lines = contents.split("\n")
- if carriage_return_found and os.linesep != '\r\n':
- # FIXME: Make sure this error also shows up when checking
- # patches, if appropriate.
+ for line_number in range(len(lines)):
+ # FIXME: We should probably use the SVN "eol-style" property
+ # or a white list to decide whether or not to do
+ # the carriage-return check. Originally, we did the
+ # check only if (os.linesep != '\r\n').
#
- # Use 0 for line_number since outputting only one error for
- # potentially several lines.
- handle_style_error(0, 'whitespace/newline', 1,
- 'One or more unexpected \\r (^M) found;'
- 'better to use only a \\n')
+ # FIXME: As a minor optimization, we can have
+ # check_no_carriage_return() return whether
+ # the line ends with "\r".
+ check_no_carriage_return(lines[line_number], line_number,
+ handle_style_error)
+ if lines[line_number].endswith("\r"):
+ lines[line_number] = lines[line_number].rstrip("\r")
+
+ processor.process(lines)
def check_file(self, file_path, handle_style_error=None, process_file=None):
"""Check style in the given file.
diff --git a/WebKitTools/Scripts/webkitpy/style/checker_unittest.py b/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
index 4d6b2e7..782d3c3 100755
--- a/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
@@ -110,6 +110,7 @@ class ProcessorOptionsTest(unittest.TestCase):
self.assertEquals(options.extra_flag_values, {})
self.assertEquals(options.filter, CategoryFilter())
self.assertEquals(options.git_commit, None)
+ self.assertEquals(options.max_reports_per_category, {})
self.assertEquals(options.output_format, "emacs")
self.assertEquals(options.verbosity, 1)
@@ -126,11 +127,13 @@ class ProcessorOptionsTest(unittest.TestCase):
options = ProcessorOptions(extra_flag_values={"extra_value" : 2},
filter=CategoryFilter(["+"]),
git_commit="commit",
+ max_reports_per_category={"category": 3},
output_format="vs7",
verbosity=3)
self.assertEquals(options.extra_flag_values, {"extra_value" : 2})
self.assertEquals(options.filter, CategoryFilter(["+"]))
self.assertEquals(options.git_commit, "commit")
+ self.assertEquals(options.max_reports_per_category, {"category": 3})
self.assertEquals(options.output_format, "vs7")
self.assertEquals(options.verbosity, 3)
@@ -143,11 +146,14 @@ class ProcessorOptionsTest(unittest.TestCase):
options = ProcessorOptions(extra_flag_values={"extra_value" : 1},
filter=CategoryFilter(["+"]),
git_commit="commit",
+ max_reports_per_category={"category": 3},
output_format="vs7",
verbosity=1)
self.assertFalse(options == ProcessorOptions(extra_flag_values={"extra_value" : 2}))
self.assertFalse(options == ProcessorOptions(filter=CategoryFilter(["-"])))
self.assertFalse(options == ProcessorOptions(git_commit="commit2"))
+ self.assertFalse(options == ProcessorOptions(max_reports_per_category=
+ {"category": 2}))
self.assertFalse(options == ProcessorOptions(output_format="emacs"))
self.assertFalse(options == ProcessorOptions(verbosity=2))
@@ -173,9 +179,9 @@ class ProcessorOptionsTest(unittest.TestCase):
self.assertFalse(options.is_reportable("xyz", 3))
-class WebKitArgumentDefaultsTest(unittest.TestCase):
+class GlobalVariablesTest(unittest.TestCase):
- """Tests validity of default arguments used by check-webkit-style."""
+ """Tests validity of the global variables."""
def defaults(self):
return style.webkit_argument_defaults()
@@ -206,6 +212,13 @@ class WebKitArgumentDefaultsTest(unittest.TestCase):
# on valid arguments elsewhere.
parser.parse([]) # arguments valid: no error or SystemExit
+ def test_max_reports_per_category(self):
+ """Check that MAX_REPORTS_PER_CATEGORY is valid."""
+ categories = style.style_categories()
+ for category in style.MAX_REPORTS_PER_CATEGORY.iterkeys():
+ self.assertTrue(category in categories,
+ 'Key "%s" is not a category' % category)
+
class ArgumentPrinterTest(unittest.TestCase):
@@ -217,8 +230,11 @@ class ArgumentPrinterTest(unittest.TestCase):
filter_rules=[], git_commit=None,
extra_flag_values={}):
filter = CategoryFilter(filter_rules)
- return style.ProcessorOptions(output_format, verbosity, filter,
- git_commit, extra_flag_values)
+ return style.ProcessorOptions(extra_flag_values=extra_flag_values,
+ filter=filter,
+ git_commit=git_commit,
+ output_format=output_format,
+ verbosity=verbosity)
def test_to_flag_string(self):
options = self._create_options('vs7', 5, ['+foo', '-bar'], 'git',
diff --git a/WebKitTools/Scripts/webkitpy/style/error_handlers.py b/WebKitTools/Scripts/webkitpy/style/error_handlers.py
index 54b1d76..31140de 100644
--- a/WebKitTools/Scripts/webkitpy/style/error_handlers.py
+++ b/WebKitTools/Scripts/webkitpy/style/error_handlers.py
@@ -32,7 +32,9 @@ Methods:
Handle the occurrence of a style error.
- Check whether the error is reportable. If so, report the details.
+ Check whether the error is reportable. If so, increment the total
+ error count and report the details. Note that error reporting can
+ be suppressed after reaching a certain number of reports.
Args:
line_number: The integer line number of the line containing the error.
@@ -79,6 +81,28 @@ class DefaultStyleErrorHandler(object):
self._options = options
self._stderr_write = stderr_write
+ # A string to integer dictionary cache of the number of reportable
+ # errors per category passed to this instance.
+ self._category_totals = { }
+
+ def _add_reportable_error(self, category):
+ """Increment the error count and return the new category total."""
+ self._increment_error_count() # Increment the total.
+
+ # Increment the category total.
+ if not category in self._category_totals:
+ self._category_totals[category] = 1
+ else:
+ self._category_totals[category] += 1
+
+ return self._category_totals[category]
+
+ def _max_reports(self, category):
+ """Return the maximum number of errors to report."""
+ if not category in self._options.max_reports_per_category:
+ return None
+ return self._options.max_reports_per_category[category]
+
def __call__(self, line_number, category, confidence, message):
"""Handle the occurrence of a style error.
@@ -88,13 +112,23 @@ class DefaultStyleErrorHandler(object):
if not self._options.is_reportable(category, confidence):
return
- self._increment_error_count()
+ category_total = self._add_reportable_error(category)
+
+ max_reports = self._max_reports(category)
+
+ if (max_reports is not None) and (category_total > max_reports):
+ # Then suppress displaying the error.
+ return
if self._options.output_format == 'vs7':
format_string = "%s(%s): %s [%s] [%d]\n"
else:
format_string = "%s:%s: %s [%s] [%d]\n"
+ if category_total == max_reports:
+ format_string += ("Suppressing further [%s] reports for this "
+ "file.\n" % category)
+
self._stderr_write(format_string % (self._file_path,
line_number,
message,
@@ -130,7 +164,7 @@ class PatchStyleErrorHandler(object):
if not self._line_numbers:
for line in self._diff.lines:
# When deleted line is not set, it means that
- # the line is newly added.
+ # the line is newly added (or modified).
if not line[0]:
self._line_numbers.add(line[1])
@@ -140,9 +174,9 @@ class PatchStyleErrorHandler(object):
"""Handle the occurrence of a style error.
This function does not report errors occurring in lines not
- modified or added.
+ marked as modified or added in the patch.
- Args: see the DefaultStyleErrorHandler.__call__() documentation.
+ See the docstring of this module for more information.
"""
if line_number not in self._get_line_numbers():
diff --git a/WebKitTools/Scripts/webkitpy/style/error_handlers_unittest.py b/WebKitTools/Scripts/webkitpy/style/error_handlers_unittest.py
index 6a91ff2..83bdbb9 100644
--- a/WebKitTools/Scripts/webkitpy/style/error_handlers_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/error_handlers_unittest.py
@@ -50,9 +50,6 @@ class DefaultStyleErrorHandlerTest(StyleErrorHandlerTestBase):
_category = "whitespace/tab"
- def _options(self, output_format):
- return ProcessorOptions(verbosity=3, output_format=output_format)
-
def _error_handler(self, options):
file_path = "foo.h"
return DefaultStyleErrorHandler(file_path,
@@ -60,29 +57,28 @@ class DefaultStyleErrorHandlerTest(StyleErrorHandlerTestBase):
self._mock_increment_error_count,
self._mock_stderr_write)
- def _prepare_call(self, output_format="emacs"):
- """Return options after initializing."""
- options = self._options(output_format)
-
- # Test that count is initialized to zero.
+ def _check_initialized(self):
+ """Check that count and error messages are initialized."""
self.assertEquals(0, self._error_count)
self.assertEquals("", self._error_messages)
- return options
-
- def _call_error_handler(self, options, confidence):
- """Handle an error with given confidence."""
- handle_error = self._error_handler(options)
-
+ def _call(self, handle_error, options, confidence):
+ """Handle an error with the given error handler."""
line_number = 100
message = "message"
handle_error(line_number, self._category, confidence, message)
+ def _call_error_handler(self, options, confidence):
+ """Handle an error using a new error handler."""
+ handle_error = self._error_handler(options)
+ self._call(handle_error, options, confidence)
+
def test_call_non_reportable(self):
"""Test __call__() method with a non-reportable error."""
confidence = 1
- options = self._prepare_call()
+ options = ProcessorOptions(verbosity=3)
+ self._check_initialized()
# Confirm the error is not reportable.
self.assertFalse(options.is_reportable(self._category, confidence))
@@ -95,7 +91,8 @@ class DefaultStyleErrorHandlerTest(StyleErrorHandlerTestBase):
def test_call_reportable_emacs(self):
"""Test __call__() method with a reportable error and emacs format."""
confidence = 5
- options = self._prepare_call("emacs")
+ options = ProcessorOptions(verbosity=3, output_format="emacs")
+ self._check_initialized()
self._call_error_handler(options, confidence)
@@ -106,7 +103,8 @@ class DefaultStyleErrorHandlerTest(StyleErrorHandlerTestBase):
def test_call_reportable_vs7(self):
"""Test __call__() method with a reportable error and vs7 format."""
confidence = 5
- options = self._prepare_call("vs7")
+ options = ProcessorOptions(verbosity=3, output_format="vs7")
+ self._check_initialized()
self._call_error_handler(options, confidence)
@@ -114,6 +112,36 @@ class DefaultStyleErrorHandlerTest(StyleErrorHandlerTestBase):
self.assertEquals(self._error_messages,
"foo.h(100): message [whitespace/tab] [5]\n")
+ def test_call_max_reports_per_category(self):
+ """Test error report suppression in __call__() method."""
+ confidence = 5
+ options = ProcessorOptions(verbosity=3,
+ max_reports_per_category={self._category: 2})
+ error_handler = self._error_handler(options)
+
+ self._check_initialized()
+
+ # First call: usual reporting.
+ self._call(error_handler, options, confidence)
+ self.assertEquals(1, self._error_count)
+ self.assertEquals(self._error_messages,
+ "foo.h:100: message [whitespace/tab] [5]\n")
+
+ # Second call: suppression message reported.
+ self._error_messages = ""
+ self._call(error_handler, options, confidence)
+ self.assertEquals(2, self._error_count)
+ self.assertEquals(self._error_messages,
+ "foo.h:100: message [whitespace/tab] [5]\n"
+ "Suppressing further [%s] reports for this file.\n"
+ % self._category)
+
+ # Third call: no report.
+ self._error_messages = ""
+ self._call(error_handler, options, confidence)
+ self.assertEquals(3, self._error_count)
+ self.assertEquals(self._error_messages, "")
+
class PatchStyleErrorHandlerTest(StyleErrorHandlerTestBase):
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/common.py b/WebKitTools/Scripts/webkitpy/style/processors/common.py
new file mode 100644
index 0000000..dbf4bea
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/processors/common.py
@@ -0,0 +1,59 @@
+# Copyright (C) 2010 Chris Jerdonek (cjerdonek at webkit.org)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Supports style checking not specific to any one processor."""
+
+
+# FIXME: Test this list in the same way that the list of CppProcessor
+# categories is tested, for example by checking that all of its
+# elements appear in the unit tests. This should probably be done
+# after moving the relevant cpp_unittest.ErrorCollector code
+# into a shared location and refactoring appropriately.
+categories = set([
+ "whitespace/carriage_return",
+])
+
+
+def check_no_carriage_return(line, line_number, error):
+ """Check that a line does not end with a carriage return.
+
+ Returns true if the check is successful (i.e. if the line does not
+ end with a carriage return), and false otherwise.
+
+ Args:
+ line: A string that is the line to check.
+ line_number: The line number.
+ error: The function to call with any errors found.
+
+ """
+
+ if line.endswith("\r"):
+ error(line_number,
+ "whitespace/carriage_return",
+ 1,
+ "One or more unexpected \\r (^M) found; "
+ "better to use only a \\n")
+ return False
+
+ return True
+
+
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/common_unittest.py b/WebKitTools/Scripts/webkitpy/style/processors/common_unittest.py
new file mode 100644
index 0000000..9362b65
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/processors/common_unittest.py
@@ -0,0 +1,82 @@
+# Copyright (C) 2010 Chris Jerdonek (cjerdonek at webkit.org)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Unit tests for common.py."""
+
+
+import unittest
+
+from common import check_no_carriage_return
+
+
+# FIXME: The unit tests for the cpp, text, and common processors should
+# share supporting test code. This can include, for example, the
+# mock style error handling code and the code to check that all
+# of a processor's categories are covered by the unit tests.
+# Such shared code can be located in a shared test file, perhaps
+# ilke this one.
+class CarriageReturnTest(unittest.TestCase):
+
+ """Tests check_no_carriage_return()."""
+
+ _category = "whitespace/carriage_return"
+ _confidence = 1
+
+ def setUp(self):
+ self._style_errors = [] # The list of accumulated style errors.
+
+ def _mock_style_error_handler(self, line_number, category, confidence,
+ message):
+ """Append the error information to the list of style errors."""
+ error = (line_number, category, confidence, message)
+ self._style_errors.append(error)
+
+ def assert_carriage_return(self, line, is_error):
+ """Call check_no_carriage_return() and assert the result."""
+ line_number = 100
+ handle_style_error = self._mock_style_error_handler
+
+ check_no_carriage_return(line, line_number, handle_style_error)
+
+ expected_message = ("One or more unexpected \\r (^M) found; "
+ "better to use only a \\n")
+
+ if is_error:
+ expected_errors = [(line_number, self._category, self._confidence,
+ expected_message)]
+ self.assertEquals(self._style_errors, expected_errors)
+ else:
+ self.assertEquals(self._style_errors, [])
+
+ def test_ends_with_carriage(self):
+ self.assert_carriage_return("carriage return\r", is_error=True)
+
+ def test_ends_with_nothing(self):
+ self.assert_carriage_return("no carriage return", is_error=False)
+
+ def test_ends_with_newline(self):
+ self.assert_carriage_return("no carriage return\n", is_error=False)
+
+ def test_ends_with_carriage_newline(self):
+ # Check_no_carriage_return only() checks the final character.
+ self.assert_carriage_return("carriage\r in a string", is_error=False)
+
diff --git a/WebKitTools/Scripts/webkitpy/style/unittests.py b/WebKitTools/Scripts/webkitpy/style/unittests.py
index 11c10e7..883e137 100644
--- a/WebKitTools/Scripts/webkitpy/style/unittests.py
+++ b/WebKitTools/Scripts/webkitpy/style/unittests.py
@@ -37,5 +37,6 @@ import unittest
from checker_unittest import *
from error_handlers_unittest import *
+from processors.common_unittest import *
from processors.cpp_unittest import *
from processors.text_unittest import *
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list