Changeset 65308 in webkit


Ignore:
Timestamp:
Aug 13, 2010 1:54:53 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-08-13 Kenichi Ishibashi <bashi@google.com>

Reviewed by Shinichiro Hamaji.

Add test_expectations.txt syntax checker to check-webkit-style.
https://bugs.webkit.org/show_bug.cgi?id=43899

Just utilizing layout_tests/layout_package/test_expectations.py for checking
the syntax of test_expectations.txt.
This change also moves tab checking class from style/checkers/text.py to
style/checkers/common.py for sharing code.

  • Scripts/webkitpy/layout_tests/layout_package/test_expectations.py:
  • Scripts/webkitpy/style/checker.py:
  • Scripts/webkitpy/style/checkers/common.py:
  • Scripts/webkitpy/style/checkers/common_unittest.py:
  • Scripts/webkitpy/style/checkers/test_expectations.py: Added.
  • Scripts/webkitpy/style/checkers/test_expectations_unittest.py: Added.
  • Scripts/webkitpy/style/checkers/text.py:
  • Scripts/webkitpy/style_references.py:
Location:
trunk/WebKitTools
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r65294 r65308  
     12010-08-13  Kenichi Ishibashi  <bashi@google.com>
     2
     3        Reviewed by Shinichiro Hamaji.
     4
     5        Add test_expectations.txt syntax checker to check-webkit-style.
     6        https://bugs.webkit.org/show_bug.cgi?id=43899
     7
     8        Just utilizing layout_tests/layout_package/test_expectations.py for checking
     9        the syntax of test_expectations.txt.
     10        This change also moves tab checking class from style/checkers/text.py to
     11        style/checkers/common.py for sharing code.
     12
     13        * Scripts/webkitpy/layout_tests/layout_package/test_expectations.py:
     14        * Scripts/webkitpy/style/checker.py:
     15        * Scripts/webkitpy/style/checkers/common.py:
     16        * Scripts/webkitpy/style/checkers/common_unittest.py:
     17        * Scripts/webkitpy/style/checkers/test_expectations.py: Added.
     18        * Scripts/webkitpy/style/checkers/test_expectations_unittest.py: Added.
     19        * Scripts/webkitpy/style/checkers/text.py:
     20        * Scripts/webkitpy/style_references.py:
     21
    1222010-08-12  Jon Honeycutt  <jhoneycutt@apple.com>
    223
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/layout_package/test_expectations.py

    r57934 r65308  
    460460        return ExpectationsJsonEncoder(separators=(',', ':')).encode(
    461461            self._all_expectations)
     462
     463    def get_non_fatal_errors(self):
     464        return self._non_fatal_errors
    462465
    463466    def contains(self, test):
  • trunk/WebKitTools/Scripts/webkitpy/style/checker.py

    r62490 r65308  
    3939from checkers.cpp import CppChecker
    4040from checkers.python import PythonChecker
     41from checkers.test_expectations import TestExpectationsChecker
    4142from checkers.text import TextChecker
    4243from error_handlers import DefaultStyleErrorHandler
     
    235236    # Take the union across all checkers.
    236237    categories = CommonCategories.union(CppChecker.categories)
     238    categories = categories.union(TestExpectationsChecker.categories)
    237239
    238240    # FIXME: Consider adding all of the pep8 categories.  Since they
     
    400402        # an exception to prevent files like "LayoutTests/ChangeLog" and
    401403        # "LayoutTests/ChangeLog-2009-06-16" from being skipped.
     404        # Files like 'test_expectations.txt' and 'drt_expectations.txt'
     405        # are also should not be skipped.
    402406        #
    403407        # FIXME: Figure out a good way to avoid having to add special logic
    404408        #        for this special case.
    405         if os.path.basename(file_path).startswith('ChangeLog'):
     409        basename = os.path.basename(file_path)
     410        if basename.startswith('ChangeLog'):
     411            return False
     412        elif basename == 'test_expectations.txt' or basename == 'drt_expectations.txt':
    406413            return False
    407414        for skipped_file in _SKIPPED_FILES_WITHOUT_WARNING:
     
    443450            checker = PythonChecker(file_path, handle_style_error)
    444451        elif file_type == FileType.TEXT:
    445             checker = TextChecker(file_path, handle_style_error)
     452            basename = os.path.basename(file_path)
     453            if basename == 'test_expectations.txt' or basename == 'drt_expectations.txt':
     454                checker = TestExpectationsChecker(file_path, handle_style_error)
     455            else:
     456                checker = TextChecker(file_path, handle_style_error)
    446457        else:
    447458            raise ValueError('Invalid file type "%(file_type)s": the only valid file types '
  • trunk/WebKitTools/Scripts/webkitpy/style/checkers/common.py

    r58742 r65308  
    3131categories = set([
    3232    "whitespace/carriage_return",
    33 ])
     33    "whitespace/tab"])
    3434
    3535
     
    5656
    5757        return lines
     58
     59
     60class TabChecker(object):
     61
     62    """Supports checking for and handling tabs."""
     63
     64    def __init__(self, file_path, handle_style_error):
     65        self.file_path = file_path
     66        self.handle_style_error = handle_style_error
     67
     68    def check(self, lines):
     69        # FIXME: share with cpp_style.
     70        for line_number, line in enumerate(lines):
     71            if "\t" in line:
     72                self.handle_style_error(line_number + 1,
     73                                        "whitespace/tab", 5,
     74                                        "Line contains tab character.")
  • trunk/WebKitTools/Scripts/webkitpy/style/checkers/common_unittest.py

    r58742 r65308  
    2626
    2727from common import CarriageReturnChecker
    28 
     28from common import TabChecker
    2929
    3030# FIXME: The unit tests for the cpp, text, and common checkers should
     
    9393                                    ["line1", "line2", "line3"],
    9494                                    [2, 3])
     95
     96
     97class TabCheckerTest(unittest.TestCase):
     98
     99    """Tests for TabChecker."""
     100
     101    def assert_tab(self, input_lines, error_lines):
     102        """Assert when the given lines contain tabs."""
     103        self._error_lines = []
     104
     105        def style_error_handler(line_number, category, confidence, message):
     106            self.assertEqual(category, 'whitespace/tab')
     107            self.assertEqual(confidence, 5)
     108            self.assertEqual(message, 'Line contains tab character.')
     109            self._error_lines.append(line_number)
     110
     111        checker = TabChecker('', style_error_handler)
     112        checker.check(input_lines)
     113        self.assertEquals(self._error_lines, error_lines)
     114
     115    def test_notab(self):
     116        self.assert_tab([''], [])
     117        self.assert_tab(['foo', 'bar'], [])
     118
     119    def test_tab(self):
     120        self.assert_tab(['\tfoo'], [1])
     121        self.assert_tab(['line1', '\tline2', 'line3\t'], [2, 3])
     122
     123if __name__ == '__main__':
     124    unittest.main()
  • trunk/WebKitTools/Scripts/webkitpy/style/checkers/text.py

    r58742 r65308  
    3030"""Checks WebKit style for text files."""
    3131
     32from common import TabChecker
    3233
    3334class TextChecker(object):
     
    3839        self.file_path = file_path
    3940        self.handle_style_error = handle_style_error
     41        self._tab_checker = TabChecker(file_path, handle_style_error)
    4042
    4143    def check(self, lines):
    42         lines = (["// adjust line numbers to make the first line 1."] + lines)
    43 
    44         # FIXME: share with cpp_style.
    45         for line_number, line in enumerate(lines):
    46             if "\t" in line:
    47                 self.handle_style_error(line_number,
    48                                         "whitespace/tab", 5,
    49                                         "Line contains tab character.")
     44        self._tab_checker.check(lines)
    5045
    5146
  • trunk/WebKitTools/Scripts/webkitpy/style_references.py

    r63004 r65308  
    4646from webkitpy.common.system.logutils import configure_logging
    4747from webkitpy.common.checkout.scm import detect_scm_system
     48from webkitpy.layout_tests import port
     49from webkitpy.layout_tests.layout_package import test_expectations
    4850from webkitpy.thirdparty.autoinstalled import pep8
    4951
Note: See TracChangeset for help on using the changeset viewer.