def test_path_rules_specifier(self): for _, path_rules in PATH_RULES_SPECIFIER: validate_filter_rules(path_rules, self._all_categories()) config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER) def assert_check(path, category): """Assert that the given category should be checked.""" self.assertTrue(config.should_check(category, path)) def assert_no_check(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) assert_check("random_path.cpp", "build/include") assert_check("random_path.cpp", "readability/naming") assert_no_check("Source/core/css/CSSParser-in.cpp", "readability/naming") # Third-party Python code: webkitpy/thirdparty path = "Tools/Scripts/webkitpy/thirdparty/mock.py" assert_no_check(path, "build/include") assert_no_check(path, "pep8/E401") # A random pep8 category. assert_check(path, "pep8/W191") assert_check(path, "pep8/W291") assert_check(path, "whitespace/carriage_return")
def test_path_rules_specifier(self): for _, path_rules in PATH_RULES_SPECIFIER: validate_filter_rules(path_rules, self._all_categories()) config = FilterConfiguration(path_specific=PATH_RULES_SPECIFIER) def assert_check(path, category): """Assert that the given category should be checked.""" self.assertTrue(config.should_check(category, path)) def assert_no_check(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) assert_check("random_path.cpp", "build/include") assert_check("random_path.cpp", "readability/naming") # Third-party Python code: webkitpy/thirdparty path = "Tools/Scripts/webkitpy/thirdparty/mock.py" assert_no_check(path, "build/include") assert_no_check(path, "pep8/E401") # A random pep8 category. assert_check(path, "pep8/W191") assert_check(path, "pep8/W291") assert_check(path, "whitespace/carriage_return")
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)
def test_webkit_base_filter_rules(self): base_filter_rules = _BASE_FILTER_RULES 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)
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") 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', '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") # Test if the exception for DataDetectorsCoreSPI.h is in place. assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi', 'cocoa', 'DataDetectorsCoreSPI.h'), "runtime/enum_bitfields") # Test if the exception for PassKitSPI.h is in place. assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi', 'cocoa', 'PassKitSPI.h'), "build/include") # Test if the exception for pal/spi is in place. assertNoCheck(os.path.join('Source', 'WebCore', 'PAL', 'pal', 'spi'), "readability/naming/underscores")