Exemplo n.º 1
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "readability/naming")
        assertCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'WTF', 'RefLogger.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'mac', 'WillSendSubmitEvent.mm'),
                      "readability/naming")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck(os.path.join('Source', 'WebKit', 'gtk', 'webkit', 'webkit.h'),
                      "readability/naming")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'gtk', 'DumpRenderTree.cpp'),
                      "readability/null")
        assertNoCheck(os.path.join('Source', 'WebKit2', 'UIProcess', 'API', 'efl', 'ewk_view.h'),
                      "readability/naming")
        assertNoCheck(os.path.join('Source', 'WebCore', 'css', 'CSSParser.cpp'),
                      "readability/naming")

        assertNoCheck(os.path.join('Source', 'WebCore', 'ForwardingHeaders', 'debugger', 'Debugger.h'),
                      "build/header_guard")

        assertNoCheck(os.path.join('Source', 'WebCore', 'platform', 'graphics', 'gstreamer', 'VideoSinkGStreamer.cpp'),
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = os.path.join('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'mock.py')
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")

        # Test if the exception for GDBInterface.cpp is in place.
        assertNoCheck(os.path.join('Source', 'JavaScriptCore', 'jit', 'GDBInterface.cpp'),
                      "readability/naming")

        # Javascript keywords.
        assertCheck(os.path.join('Source', 'JavaScriptCore', 'parser', 'Keywords.table'), "whitespace/carriage_return")
Exemplo n.º 2
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("Source/core/css/CSSParser-in.cpp",
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")
    def test_validate_filter_rules(self):
        all_categories = ["tabs", "whitespace", "build/include"]

        bad_rules = [
            "tabs",
            "*tabs",
            " tabs",
            " +tabs",
            "+whitespace/newline",
            "+xxx",
            ]

        good_rules = [
            "+tabs",
            "-tabs",
            "+build"
            ]

        for rule in bad_rules:
            self.assertRaises(ValueError, validate_filter_rules,
                              [rule], all_categories)

        for rule in good_rules:
            # This works: no error.
            validate_filter_rules([rule], all_categories)
Exemplo n.º 4
0
    def test_validate_filter_rules(self):
        all_categories = ["tabs", "whitespace", "build/include"]

        bad_rules = [
            "tabs",
            "*tabs",
            " tabs",
            " +tabs",
            "+whitespace/newline",
            "+xxx",
            ]

        good_rules = [
            "+tabs",
            "-tabs",
            "+build"
            ]

        for rule in bad_rules:
            self.assertRaises(ValueError, validate_filter_rules,
                              [rule], all_categories)

        for rule in good_rules:
            # This works: no error.
            validate_filter_rules([rule], all_categories)
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("Source/core/css/CSSParser-in.cpp",
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")
Exemplo n.º 6
0
    def parse(self, args):
        """Parse the command line arguments to check-webkit-style.

        Args:
          args: A list of command-line arguments as returned by sys.argv[1:].

        Returns:
          A tuple of (paths, options)

          paths: The list of paths to check.
          options: A CommandOptionValues instance.

        """
        (options, paths) = self._parser.parse_args(args=args)

        filter_value = options.filter_value
        git_commit = options.git_commit
        diff_files = options.diff_files
        is_verbose = options.is_verbose
        min_confidence = options.min_confidence
        output_format = options.output_format
        commit_queue = options.commit_queue
        git_index = options.git_index

        if filter_value is not None and not filter_value:
            # Then the user explicitly passed no filter, for
            # example "-f ''" or "--filter=".
            self._exit_with_categories()

        # Validate user-provided values.

        min_confidence = int(min_confidence)
        if (min_confidence < 1) or (min_confidence > 5):
            self._parse_error('option --min-confidence: invalid integer: '
                              '%s: value must be between 1 and 5'
                              % min_confidence)

        if filter_value:
            filter_rules = self._parse_filter_flag(filter_value)
        else:
            filter_rules = []

        try:
            validate_filter_rules(filter_rules, self._all_categories)
        except ValueError as err:
            self._parse_error(err)

        options = CommandOptionValues(filter_rules=filter_rules,
                                      git_commit=git_commit,
                                      diff_files=diff_files,
                                      is_verbose=is_verbose,
                                      min_confidence=min_confidence,
                                      output_format=output_format,
                                      commit_queue=commit_queue,
                                      git_index=git_index)

        return (paths, options)
Exemplo n.º 7
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'DumpRenderTree', 'TestNetscapePlugIn', 'main.cpp'),
                      "readability/naming")
        assertCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'WTF', 'RefLogger.cpp'),
                      "build/include")
        assertNoCheck(os.path.join('Tools', 'TestWebKitAPI', 'Tests', 'mac', 'WillSendSubmitEvent.mm'),
                      "readability/naming")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck(os.path.join('Source', 'WebKit2', 'UIProcess', 'API', 'efl', 'ewk_view.h'),
                      "readability/naming")
        assertNoCheck(os.path.join('Source', 'WebCore', 'css', 'CSSParser.cpp'),
                      "readability/naming")

        assertNoCheck(os.path.join('Source', 'WebCore', 'ForwardingHeaders', 'debugger', 'Debugger.h'),
                      "build/header_guard")

        assertNoCheck(os.path.join('Source', 'WebCore', 'platform', 'graphics', 'gstreamer', 'VideoSinkGStreamer.cpp'),
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = os.path.join('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'mock.py')
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")

        # Test if the exception for GDBInterface.cpp is in place.
        assertNoCheck(os.path.join('Source', 'JavaScriptCore', 'jit', 'GDBInterface.cpp'),
                      "readability/naming")

        # Javascript keywords.
        assertCheck(os.path.join('Source', 'JavaScriptCore', 'parser', 'Keywords.table'), "whitespace/carriage_return")
Exemplo n.º 8
0
    def parse(self, args):
        """Parse the command line arguments to check-webkit-style.

        Args:
          args: A list of command-line arguments as returned by sys.argv[1:].

        Returns:
          A tuple of (paths, options)

          paths: The list of paths to check.
          options: A CommandOptionValues instance.

        """
        (options, paths) = self._parser.parse_args(args=args)

        filter_value = options.filter_value
        git_commit = options.git_since
        is_verbose = options.is_verbose
        min_confidence = options.min_confidence
        output_format = options.output_format

        if filter_value is not None and not filter_value:
            # Then the user explicitly passed no filter, for
            # example "-f ''" or "--filter=".
            self._exit_with_categories()

        # Validate user-provided values.

        if paths and git_commit:
            self._parse_error('You cannot provide both paths and a git '
                              'commit at the same time.')

        # FIXME: Add unit tests.
        if git_commit and '..' in git_commit:
            # FIXME: If the range is a "...", the code should find the common
            #        ancestor and start there.  See git diff --help for how
            #        "..." usually works.
            self._parse_error('invalid --git-commit option: option does '
                              'not support ranges "..": %s' % git_commit)

        min_confidence = int(min_confidence)
        if (min_confidence < 1) or (min_confidence > 5):
            self._parse_error('option --min-confidence: invalid integer: '
                              '%s: value must be between 1 and 5'
                              % min_confidence)

        if filter_value:
            filter_rules = self._parse_filter_flag(filter_value)
        else:
            filter_rules = []

        try:
            validate_filter_rules(filter_rules, self._all_categories)
        except ValueError, err:
            self._parse_error(err)
Exemplo n.º 9
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck("Tools/WebKitAPITest/main.cpp",
                      "build/include")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("Source/WebKit/gtk/webkit/webkit.h",
                      "readability/naming")
        assertNoCheck("Tools/DumpRenderTree/gtk/DumpRenderTree.cpp",
                      "readability/null")
        assertNoCheck("Source/WebKit2/UIProcess/API/efl/ewk_view.h",
                      "readability/naming")
        assertNoCheck("Source/WebCore/css/CSSParser.cpp",
                      "readability/naming")

        assertNoCheck("Source/WebCore/ForwardingHeaders/debugger/Debugger.h",
                      "build/header_guard")

        assertNoCheck("Source/WebCore/platform/graphics/gstreamer/VideoSinkGStreamer.cpp",
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")

        # Test if the exception for GDBInterface.cpp is in place.
        assertNoCheck("Source/JavaScriptCore/jit/GDBInterface.cpp",
                      "readability/naming")

        # Javascript keywords.
        assertCheck("Source/JavaScriptCore/parser/Keywords.table", "whitespace/carriage_return")
Exemplo n.º 10
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck("Tools/WebKitAPITest/main.cpp",
                      "build/include")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("Source/WebKit/gtk/webkit/webkit.h",
                      "readability/naming")
        assertNoCheck("Tools/DumpRenderTree/gtk/DumpRenderTree.cpp",
                      "readability/null")
        assertNoCheck("Source/WebKit/efl/ewk/ewk_view.h",
                      "readability/naming")
        assertNoCheck("Source/WebCore/css/CSSParser.cpp",
                      "readability/naming")

        assertNoCheck("Source/WebCore/ForwardingHeaders/debugger/Debugger.h",
                      "build/header_guard")

        assertNoCheck("Source/WebCore/platform/graphics/gstreamer/VideoSinkGStreamer.cpp",
                      "readability/naming")

        # Third-party Python code: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")

        # Test if the exception for GDBInterface.cpp is in place.
        assertNoCheck("Source/JavaScriptCore/jit/GDBInterface.cpp",
                      "readability/naming")

        # Javascript keywords.
        assertCheck("Source/JavaScriptCore/parser/Keywords.table", "whitespace/carriage_return")
Exemplo n.º 11
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck("WebKitTools/WebKitAPITest/main.cpp",
                      "build/include")
        assertNoCheck("WebKit/qt/QGVLauncher/main.cpp",
                      "build/include")
        assertNoCheck("WebKit/qt/QGVLauncher/main.cpp",
                      "readability/streams")

        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("WebKit/gtk/webkit/webkit.h",
                      "readability/naming")
        assertNoCheck("WebKitTools/DumpRenderTree/gtk/DumpRenderTree.cpp",
                      "readability/null")
        assertNoCheck("WebKit/efl/ewk/ewk_view.h",
                      "readability/naming")
        assertNoCheck("WebCore/css/CSSParser.cpp",
                      "readability/naming")
        assertNoCheck("WebKit/qt/tests/qwebelement/tst_qwebelement.cpp",
                      "readability/naming")
        assertNoCheck(
            "JavaScriptCore/qt/tests/qscriptengine/tst_qscriptengine.cpp",
            "readability/naming")
        assertNoCheck("WebCore/ForwardingHeaders/debugger/Debugger.h",
                      "build/header_guard")

        # Third-party Python code: webkitpy/thirdparty
        path = "WebKitTools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")
Exemplo n.º 12
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = 'Should check category "%s" for path "%s".' % (category, path)
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = 'Should not check category "%s" for path "%s".' % (category, path)
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp", "build/include")
        assertNoCheck("Tools/WebKitAPITest/main.cpp", "build/include")
        assertCheck("random_path.cpp", "readability/naming")
        assertNoCheck("Source/WebKit/gtk/webkit/webkit.h", "readability/naming")
        assertNoCheck("Tools/DumpRenderTree/gtk/DumpRenderTree.cpp", "readability/null")
        assertNoCheck("Source/WebKit/efl/ewk/ewk_view.h", "readability/naming")
        assertNoCheck("Source/WebCore/css/CSSParser.cpp", "readability/naming")

        # Test if Qt exceptions are indeed working
        assertCheck("Source/JavaScriptCore/qt/api/qscriptengine.cpp", "readability/braces")
        assertCheck("Source/WebKit/qt/Api/qwebpage.cpp", "readability/braces")
        assertCheck("Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp", "readability/braces")
        assertCheck("Source/WebKit/qt/declarative/platformplugin/WebPlugin.cpp", "readability/braces")
        assertCheck("Source/WebKit/qt/examples/platformplugin/WebPlugin.cpp", "readability/braces")
        assertCheck("Source/WebKit/qt/symbian/platformplugin/WebPlugin.cpp", "readability/braces")
        assertNoCheck("Source/JavaScriptCore/qt/api/qscriptengine.cpp", "readability/naming")
        assertNoCheck(
            "Source/JavaScriptCore/qt/benchmarks" "/qscriptengine/tst_qscriptengine.cpp", "readability/naming"
        )
        assertNoCheck("Source/WebKit/qt/Api/qwebpage.cpp", "readability/naming")
        assertNoCheck("Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp", "readability/naming")
        assertNoCheck("Source/WebKit/qt/declarative/platformplugin/WebPlugin.cpp", "readability/naming")
        assertNoCheck("Source/WebKit/qt/examples/platformplugin/WebPlugin.cpp", "readability/naming")
        assertNoCheck("Source/WebKit/qt/symbian/platformplugin/WebPlugin.cpp", "build/header_guard")

        assertNoCheck("Tools/MiniBrowser/qt/UrlLoader.cpp", "build/include")

        assertNoCheck("Source/WebCore/ForwardingHeaders/debugger/Debugger.h", "build/header_guard")

        # Third-party Python code: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")
Exemplo n.º 13
0
    def test_path_rules_specifier(self):
        all_categories = style_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            self.assertTrue(isinstance(path_rules, tuple), "Checking: " + str(path_rules))
            validate_filter_rules(path_rules, self._all_categories())

        # Try using the path specifier (as an "end-to-end" check).
        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)
        self.assertTrue(config.should_check("xxx_any_category", "xxx_non_matching_path"))
        self.assertTrue(config.should_check("xxx_any_category", "WebKitTools/WebKitAPITest/"))
        self.assertFalse(config.should_check("build/include", "WebKitTools/WebKitAPITest/"))
        self.assertFalse(config.should_check("readability/naming", "WebKit/qt/tests/qwebelement/tst_qwebelement.cpp"))
Exemplo n.º 14
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck("WebKitTools/WebKitAPITest/main.cpp",
                      "build/include")
        assertNoCheck("WebKit/qt/QGVLauncher/main.cpp",
                      "build/include")
        assertNoCheck("WebKit/qt/QGVLauncher/main.cpp",
                      "readability/streams")

        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("WebKit/gtk/webkit/webkit.h",
                      "readability/naming")
        assertNoCheck("WebKitTools/DumpRenderTree/gtk/DumpRenderTree.cpp",
                      "readability/null")
        assertNoCheck("WebKit/efl/ewk/ewk_view.h",
                      "readability/naming")
        assertNoCheck("WebCore/css/CSSParser.cpp",
                      "readability/naming")
        assertNoCheck("WebKit/qt/tests/qwebelement/tst_qwebelement.cpp",
                      "readability/naming")
        assertNoCheck(
            "JavaScriptCore/qt/tests/qscriptengine/tst_qscriptengine.cpp",
            "readability/naming")
        assertNoCheck("WebCore/ForwardingHeaders/debugger/Debugger.h",
                      "build/header_guard")

        # Third-party Python code: webkitpy/thirdparty
        path = "WebKitTools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")
Exemplo n.º 15
0
    def parse(self, args):
        """Parse the command line arguments to check-webkit-style.

        Args:
          args: A list of command-line arguments as returned by sys.argv[1:].

        Returns:
          A tuple of (paths, options)

          paths: The list of paths to check.
          options: A CommandOptionValues instance.
        """
        (options, paths) = self._parser.parse_args(args=args)

        filter_value = options.filter_value
        git_commit = options.git_commit
        diff_files = options.diff_files
        is_verbose = options.is_verbose
        min_confidence = options.min_confidence
        output_format = options.output_format

        if filter_value is not None and not filter_value:
            # Then the user explicitly passed no filter, for
            # example "-f ''" or "--filter=".
            self._exit_with_categories()

        # Validate user-provided values.

        min_confidence = int(min_confidence)
        if (min_confidence < 1) or (min_confidence > 5):
            self._parse_error('option --min-confidence: invalid integer: '
                              '%s: value must be between 1 and 5'
                              % min_confidence)

        if filter_value:
            filter_rules = self._parse_filter_flag(filter_value)
        else:
            filter_rules = []

        try:
            validate_filter_rules(filter_rules, self._all_categories)
        except ValueError as err:
            self._parse_error(err)

        options = CommandOptionValues(filter_rules=filter_rules,
                                      git_commit=git_commit,
                                      diff_files=diff_files,
                                      is_verbose=is_verbose,
                                      min_confidence=min_confidence,
                                      output_format=output_format)

        return (paths, options)
Exemplo n.º 16
0
 def test_filter_rules(self):
     defaults = self.defaults()
     already_seen = []
     validate_filter_rules(defaults.base_filter_rules, self._all_categories())
     # Also do some additional checks.
     for rule in defaults.base_filter_rules:
         # Check no leading or trailing white space.
         self.assertEquals(rule, rule.strip())
         # All categories are on by default, so defaults should
         # begin with -.
         self.assertTrue(rule.startswith("-"))
         # Check no rule occurs twice.
         self.assertFalse(rule in already_seen)
         already_seen.append(rule)
Exemplo n.º 17
0
 def test_webkit_base_filter_rules(self):
     base_filter_rules = _BASE_FILTER_RULES
     defaults = self.defaults()
     already_seen = []
     validate_filter_rules(base_filter_rules, self._all_categories())
     # Also do some additional checks.
     for rule in base_filter_rules:
         # Check no leading or trailing white space.
         self.assertEquals(rule, rule.strip())
         # All categories are on by default, so defaults should
         # begin with -.
         self.assertTrue(rule.startswith('-'))
         # Check no rule occurs twice.
         self.assertFalse(rule in already_seen)
         already_seen.append(rule)
Exemplo n.º 18
0
 def test_webkit_base_filter_rules(self):
     base_filter_rules = _BASE_FILTER_RULES
     defaults = self.defaults()
     already_seen = []
     validate_filter_rules(base_filter_rules, self._all_categories())
     # Also do some additional checks.
     for rule in base_filter_rules:
         # Check no leading or trailing white space.
         self.assertEqual(rule, rule.strip())
         # All categories are on by default, so defaults should
         # begin with -.
         self.assertTrue(rule.startswith('-'))
         # Check no rule occurs twice.
         self.assertNotIn(rule, already_seen)
         already_seen.append(rule)
Exemplo n.º 19
0
    def test_path_rules_specifier(self):
        all_categories = style_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            self.assertTrue(isinstance(path_rules, tuple),
                            "Checking: " + str(path_rules))
            validate_filter_rules(path_rules, self._all_categories())

        # Try using the path specifier (as an "end-to-end" check).
        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)
        self.assertTrue(
            config.should_check("xxx_any_category", "xxx_non_matching_path"))
        self.assertTrue(
            config.should_check("xxx_any_category",
                                "WebKitTools/WebKitAPITest/"))
        self.assertFalse(
            config.should_check("build/include", "WebKitTools/WebKitAPITest/"))
        self.assertFalse(
            config.should_check(
                "readability/naming",
                "WebKit/qt/tests/qwebelement/tst_qwebelement.cpp"))
Exemplo n.º 20
0
    def test_path_rules_specifier(self):
        all_categories = self._all_categories()
        for (sub_paths, path_rules) in PATH_RULES_SPECIFIER:
            validate_filter_rules(path_rules, self._all_categories())

        config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER)

        def assertCheck(path, category):
            """Assert that the given category should be checked."""
            message = ('Should check category "%s" for path "%s".'
                       % (category, path))
            self.assertTrue(config.should_check(category, path))

        def assertNoCheck(path, category):
            """Assert that the given category should not be checked."""
            message = ('Should not check category "%s" for path "%s".'
                       % (category, path))
            self.assertFalse(config.should_check(category, path), message)

        assertCheck("random_path.cpp",
                    "build/include")
        assertNoCheck("Tools/WebKitAPITest/main.cpp",
                      "build/include")
        assertCheck("random_path.cpp",
                    "readability/naming")
        assertNoCheck("Source/WebKit/gtk/webkit/webkit.h",
                      "readability/naming")
        assertNoCheck("Tools/DumpRenderTree/gtk/DumpRenderTree.cpp",
                      "readability/null")
        assertNoCheck("Source/WebKit/efl/ewk/ewk_view.h",
                      "readability/naming")
        assertNoCheck("Source/WebCore/css/CSSParser.cpp",
                      "readability/naming")

        # Test if Qt exceptions are indeed working
        assertCheck("Source/JavaScriptCore/qt/api/qscriptengine.cpp",
                    "readability/braces")
        assertCheck("Source/WebKit/qt/Api/qwebpage.cpp",
                    "readability/braces")
        assertCheck("Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp",
                    "readability/braces")
        assertCheck("Source/WebKit/qt/declarative/platformplugin/WebPlugin.cpp",
                    "readability/braces")
        assertCheck("Source/WebKit/qt/examples/platformplugin/WebPlugin.cpp",
                    "readability/braces")
        assertCheck("Source/WebKit/qt/symbian/platformplugin/WebPlugin.cpp",
                    "readability/braces")
        assertNoCheck("Source/JavaScriptCore/qt/api/qscriptengine.cpp",
                      "readability/naming")
        assertNoCheck("Source/JavaScriptCore/qt/benchmarks"
                      "/qscriptengine/tst_qscriptengine.cpp",
                      "readability/naming")
        assertNoCheck("Source/WebKit/qt/Api/qwebpage.cpp",
                      "readability/naming")
        assertNoCheck("Source/WebKit/qt/tests/qwebelement/tst_qwebelement.cpp",
                      "readability/naming")
        assertNoCheck("Source/WebKit/qt/declarative/platformplugin/WebPlugin.cpp",
                      "readability/naming")
        assertNoCheck("Source/WebKit/qt/examples/platformplugin/WebPlugin.cpp",
                      "readability/naming")
        assertNoCheck("Source/WebKit/qt/symbian/platformplugin/WebPlugin.cpp",
                      "build/header_guard")

        assertNoCheck("Tools/MiniBrowser/qt/UrlLoader.cpp",
                    "build/include")

        assertNoCheck("Source/WebKit2/UIProcess/API/qt",
                    "readability/parameter_name")

        assertNoCheck("Source/WebCore/ForwardingHeaders/debugger/Debugger.h",
                      "build/header_guard")

        # Third-party Python code: webkitpy/thirdparty
        path = "Tools/Scripts/webkitpy/thirdparty/mock.py"
        assertNoCheck(path, "build/include")
        assertNoCheck(path, "pep8/E401")  # A random pep8 category.
        assertCheck(path, "pep8/W191")
        assertCheck(path, "pep8/W291")
        assertCheck(path, "whitespace/carriage_return")
Exemplo n.º 21
0
    def parse(self, args, extra_flags=None):
        """Parse the command line arguments to check-webkit-style.

        Args:
          args: A list of command-line arguments as returned by sys.argv[1:].
          extra_flags: A list of flags whose values we want to extract, but
                       are not supported by the ProcessorOptions class.
                       An example flag "new_flag=". This defaults to the
                       empty list.

        Returns:
          A tuple of (filenames, options)

          filenames: The list of filenames to check.
          options: A ProcessorOptions instance.

        """
        if extra_flags is None:
            extra_flags = []

        output_format = self.defaults.output_format
        verbosity = self.defaults.verbosity
        base_rules = self.defaults.base_filter_rules

        # The flags already supported by the ProcessorOptions class.
        flags = ['help', 'output=', 'verbose=', 'filter=', 'git-commit=']

        for extra_flag in extra_flags:
            if extra_flag in flags:
                raise ValueError('Flag \'%(extra_flag)s is duplicated '
                                 'or already supported.' %
                                 {'extra_flag': extra_flag})
            flags.append(extra_flag)

        try:
            (opts, filenames) = getopt.getopt(args, '', flags)
        except getopt.GetoptError:
            # FIXME: Settle on an error handling approach: come up
            #        with a consistent guideline as to when and whether
            #        a ValueError should be raised versus calling
            #        sys.exit when needing to interrupt execution.
            self._exit_with_usage('Invalid arguments.')

        extra_flag_values = {}
        git_commit = None
        user_rules = []

        for (opt, val) in opts:
            if opt == '--help':
                self._exit_with_usage()
            elif opt == '--output':
                output_format = val
            elif opt == '--verbose':
                verbosity = val
            elif opt == '--git-commit':
                git_commit = val
            elif opt == '--filter':
                if not val:
                    self._exit_with_categories()
                # Prepend the defaults.
                user_rules = self._parse_filter_flag(val)
            else:
                extra_flag_values[opt] = val

        # Check validity of resulting values.
        if filenames and (git_commit != None):
            self._exit_with_usage('It is not possible to check files and a '
                                  'specific commit at the same time.')

        if output_format not in ('emacs', 'vs7'):
            raise ValueError('Invalid --output value "%s": The only '
                             'allowed output formats are emacs and vs7.' %
                             output_format)

        all_categories = style_categories()
        validate_filter_rules(user_rules, all_categories)

        verbosity = int(verbosity)
        if (verbosity < 1) or (verbosity > 5):
            raise ValueError('Invalid --verbose value %s: value must '
                             'be between 1-5.' % verbosity)

        filter_configuration = FilterConfiguration(
            base_rules=base_rules,
            path_specific=_PATH_RULES_SPECIFIER,
            user_rules=user_rules)

        options = ProcessorOptions(
            extra_flag_values=extra_flag_values,
            filter_configuration=filter_configuration,
            git_commit=git_commit,
            max_reports_per_category=MAX_REPORTS_PER_CATEGORY,
            output_format=output_format,
            verbosity=verbosity)

        return (filenames, options)
Exemplo n.º 22
0
    def parse(self, args, extra_flags=None):
        """Parse the command line arguments to check-webkit-style.

        Args:
          args: A list of command-line arguments as returned by sys.argv[1:].
          extra_flags: A list of flags whose values we want to extract, but
                       are not supported by the ProcessorOptions class.
                       An example flag "new_flag=". This defaults to the
                       empty list.

        Returns:
          A tuple of (filenames, options)

          filenames: The list of filenames to check.
          options: A ProcessorOptions instance.

        """
        if extra_flags is None:
            extra_flags = []

        output_format = self.defaults.output_format
        verbosity = self.defaults.verbosity
        base_rules = self.defaults.base_filter_rules

        # The flags already supported by the ProcessorOptions class.
        flags = ['help', 'output=', 'verbose=', 'filter=', 'git-commit=']

        for extra_flag in extra_flags:
            if extra_flag in flags:
                raise ValueError('Flag \'%(extra_flag)s is duplicated '
                                 'or already supported.' %
                                 {'extra_flag': extra_flag})
            flags.append(extra_flag)

        try:
            (opts, filenames) = getopt.getopt(args, '', flags)
        except getopt.GetoptError:
            # FIXME: Settle on an error handling approach: come up
            #        with a consistent guideline as to when and whether
            #        a ValueError should be raised versus calling
            #        sys.exit when needing to interrupt execution.
            self._exit_with_usage('Invalid arguments.')

        extra_flag_values = {}
        git_commit = None
        user_rules = []

        for (opt, val) in opts:
            if opt == '--help':
                self._exit_with_usage()
            elif opt == '--output':
                output_format = val
            elif opt == '--verbose':
                verbosity = val
            elif opt == '--git-commit':
                git_commit = val
            elif opt == '--filter':
                if not val:
                    self._exit_with_categories()
                # Prepend the defaults.
                user_rules = self._parse_filter_flag(val)
            else:
                extra_flag_values[opt] = val

        # Check validity of resulting values.
        if filenames and (git_commit != None):
            self._exit_with_usage('It is not possible to check files and a '
                                  'specific commit at the same time.')

        if output_format not in ('emacs', 'vs7'):
            raise ValueError('Invalid --output value "%s": The only '
                             'allowed output formats are emacs and vs7.' %
                             output_format)

        all_categories = style_categories()
        validate_filter_rules(user_rules, all_categories)

        verbosity = int(verbosity)
        if (verbosity < 1) or (verbosity > 5):
            raise ValueError('Invalid --verbose value %s: value must '
                             'be between 1-5.' % verbosity)

        filter_configuration = FilterConfiguration(base_rules=base_rules,
                                   path_specific=_PATH_RULES_SPECIFIER,
                                   user_rules=user_rules)

        options = ProcessorOptions(extra_flag_values=extra_flag_values,
                      filter_configuration=filter_configuration,
                      git_commit=git_commit,
                      max_reports_per_category=MAX_REPORTS_PER_CATEGORY,
                      output_format=output_format,
                      verbosity=verbosity)

        return (filenames, options)