Title: [219669] trunk/Tools
Revision
219669
Author
[email protected]
Date
2017-07-19 17:17:40 -0700 (Wed, 19 Jul 2017)

Log Message

lint-test-expectations should be run during style checking
https://bugs.webkit.org/show_bug.cgi?id=173559
<rdar://problem/32854941>

Reviewed by Daniel Bates.

Follow up fix addressing style and a few minor bugs.

* Scripts/webkitpy/layout_tests/models/test_expectations.py:
(TestExpectationParser.__init__): Use lambda x: x instead of str
(TestExpectationsModel.__init__): Make lambda x: x the default argument.
(TestExpectationsModel._already_seen_better_match): Use a temporary variable to
reduce the calls of _shorten_filename, fix minor bug in appending the current
expectation's line number instead of the previous ones, clarify treatment of None
in file-to-line-number mapping.
(TestExpectations._report_warnings): Collapse call.
* Scripts/webkitpy/style/checkers/test_expectations.py:
(TestExpectationsChecker.lint_test_expectations):
* Scripts/webkitpy/style/filereader.py: Re-write comment.
(TextFileReader.process_file): Add comment explaining treatment of None in
file-to-line-number mapping.
(TextFileReader.delete_file): Collapse call.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (219668 => 219669)


--- trunk/Tools/ChangeLog	2017-07-20 00:15:08 UTC (rev 219668)
+++ trunk/Tools/ChangeLog	2017-07-20 00:17:40 UTC (rev 219669)
@@ -1,3 +1,28 @@
+2017-07-19  Jonathan Bedard  <[email protected]>
+
+        lint-test-expectations should be run during style checking
+        https://bugs.webkit.org/show_bug.cgi?id=173559
+        <rdar://problem/32854941>
+
+        Reviewed by Daniel Bates.
+
+        Follow up fix addressing style and a few minor bugs.
+
+        * Scripts/webkitpy/layout_tests/models/test_expectations.py:
+        (TestExpectationParser.__init__): Use lambda x: x instead of str
+        (TestExpectationsModel.__init__): Make lambda x: x the default argument.
+        (TestExpectationsModel._already_seen_better_match): Use a temporary variable to
+        reduce the calls of _shorten_filename, fix minor bug in appending the current
+        expectation's line number instead of the previous ones, clarify treatment of None
+        in file-to-line-number mapping.
+        (TestExpectations._report_warnings): Collapse call.
+        * Scripts/webkitpy/style/checkers/test_expectations.py:
+        (TestExpectationsChecker.lint_test_expectations):
+        * Scripts/webkitpy/style/filereader.py: Re-write comment.
+        (TextFileReader.process_file): Add comment explaining treatment of None in
+        file-to-line-number mapping.
+        (TextFileReader.delete_file): Collapse call.
+
 2017-07-19  Chris Dumez  <[email protected]>
 
         Unreviewed attempt to fix API test failure after r219663.

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py (219668 => 219669)


--- trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py	2017-07-20 00:15:08 UTC (rev 219668)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py	2017-07-20 00:17:40 UTC (rev 219669)
@@ -92,7 +92,7 @@
 
     MISSING_BUG_WARNING = 'Test lacks BUG modifier.'
 
-    def __init__(self, port, full_test_list, allow_rebaseline_modifier, shorten_filename=str):
+    def __init__(self, port, full_test_list, allow_rebaseline_modifier, shorten_filename=lambda x: x):
         self._port = port
         self._test_configuration_converter = TestConfigurationConverter(set(port.all_test_configurations()), port.configuration_specifier_macros())
         if full_test_list is None:
@@ -512,7 +512,7 @@
 class TestExpectationsModel(object):
     """Represents relational store of all expectations and provides CRUD semantics to manage it."""
 
-    def __init__(self, shorten_filename=None):
+    def __init__(self, shorten_filename=lambda x: x):
         # Maps a test to its list of expectations.
         self._test_to_expectations = {}
 
@@ -527,7 +527,7 @@
         self._timeline_to_tests = self._dict_of_sets(TestExpectations.TIMELINES)
         self._result_type_to_tests = self._dict_of_sets(TestExpectations.RESULT_TYPES)
 
-        self._shorten_filename = shorten_filename or (lambda x: x)
+        self._shorten_filename = shorten_filename
 
     def _dict_of_sets(self, strings_to_constants):
         """Takes a dict of strings->constants and returns a dict mapping
@@ -714,39 +714,40 @@
         #
         # To use the "more modifiers wins" policy, change the errors for overrides
         # to be warnings and return False".
+        shortened_expectation_filename = self._shorten_filename(expectation_line.filename)
+        shortened_previous_expectation_filename = self._shorten_filename(prev_expectation_line.filename)
 
         if prev_expectation_line.matching_configurations == expectation_line.matching_configurations:
             expectation_line.warnings.append('Duplicate or ambiguous entry lines %s:%d and %s:%d.' % (
-                self._shorten_filename(prev_expectation_line.filename), prev_expectation_line.line_number,
-                self._shorten_filename(expectation_line.filename), expectation_line.line_number))
+                shortened_previous_expectation_filename, prev_expectation_line.line_number,
+                shortened_expectation_filename, expectation_line.line_number))
 
         elif prev_expectation_line.matching_configurations >= expectation_line.matching_configurations:
             expectation_line.warnings.append('More specific entry for %s on line %s:%d overrides line %s:%d.' % (expectation_line.name,
-                self._shorten_filename(prev_expectation_line.filename), prev_expectation_line.line_number,
-                self._shorten_filename(expectation_line.filename), expectation_line.line_number))
+                shortened_previous_expectation_filename, prev_expectation_line.line_number,
+                shortened_expectation_filename, expectation_line.line_number))
             # FIXME: return False if we want more specific to win.
 
         elif prev_expectation_line.matching_configurations <= expectation_line.matching_configurations:
             expectation_line.warnings.append('More specific entry for %s on line %s:%d overrides line %s:%d.' % (expectation_line.name,
-                self._shorten_filename(expectation_line.filename), expectation_line.line_number,
-                self._shorten_filename(prev_expectation_line.filename), prev_expectation_line.line_number))
+                shortened_expectation_filename, expectation_line.line_number,
+                shortened_previous_expectation_filename, prev_expectation_line.line_number))
 
         elif prev_expectation_line.matching_configurations & expectation_line.matching_configurations:
             expectation_line.warnings.append('Entries for %s on lines %s:%d and %s:%d match overlapping sets of configurations.' % (expectation_line.name,
-                self._shorten_filename(prev_expectation_line.filename), prev_expectation_line.line_number,
-                self._shorten_filename(expectation_line.filename), expectation_line.line_number))
+                shortened_previous_expectation_filename, prev_expectation_line.line_number,
+                shortened_expectation_filename, expectation_line.line_number))
 
         else:
             # Configuration sets are disjoint.
             return False
 
-        if expectation_line.related_files.get(self._shorten_filename(prev_expectation_line.filename), None) is None:
-            expectation_line.related_files[self._shorten_filename(prev_expectation_line.filename)] = []
-        expectation_line.related_files[self._shorten_filename(prev_expectation_line.filename)].append(prev_expectation_line.line_number)
+        # Missing files will be 'None'. It should be impossible to have a missing file which also has a line associated with it.
+        assert shortened_previous_expectation_filename not in expectation_line.related_files or expectation_line.related_files[shortened_previous_expectation_filename] is not None
+        expectation_line.related_files[shortened_previous_expectation_filename] = expectation_line.related_files.get(shortened_previous_expectation_filename, []).append(prev_expectation_line.line_number)
 
-        if prev_expectation_line.related_files.get(self._shorten_filename(expectation_line.filename), None) is None:
-            prev_expectation_line.related_files[self._shorten_filename(expectation_line.filename)] = []
-        prev_expectation_line.related_files[self._shorten_filename(expectation_line.filename)].append(prev_expectation_line.line_number)
+        assert shortened_expectation_filename not in prev_expectation_line.related_files or prev_expectation_line.related_files[shortened_expectation_filename] is not None
+        prev_expectation_line.related_files[shortened_expectation_filename] = prev_expectation_line.related_files.get(shortened_expectation_filename, []).append(expectation_line.line_number)
 
         return True
 
@@ -964,11 +965,8 @@
         for expectation in self._expectations:
             for warning in expectation.warnings:
                 warning = TestExpectationWarning(
-                    self._shorten_filename(expectation.filename),
-                    expectation.line_number,
-                    expectation.original_string,
-                    warning,
-                    expectation.name if expectation.expectations else None)
+                    self._shorten_filename(expectation.filename), expectation.line_number,
+                    expectation.original_string, warning, expectation.name if expectation.expectations else None)
                 warning.related_files = expectation.related_files
                 warnings.append(warning)
 

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/test_expectations.py (219668 => 219669)


--- trunk/Tools/Scripts/webkitpy/style/checkers/test_expectations.py	2017-07-20 00:15:08 UTC (rev 219668)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/test_expectations.py	2017-07-20 00:17:40 UTC (rev 219669)
@@ -126,11 +126,7 @@
         ports_to_lint = [host.port_factory.get(name) for name in host.port_factory.all_port_names()]
         for port in ports_to_lint:
             for expectations_file in port.expectations_dict().keys():
-                style_error_handler = DefaultStyleErrorHandler(
-                    expectations_file,
-                    configuration,
-                    increment_error_count,
-                    line_numbers)
+                style_error_handler = DefaultStyleErrorHandler(expectations_file, configuration, increment_error_count, line_numbers)
 
                 try:
                     if expectations_file in files_linted:

Modified: trunk/Tools/Scripts/webkitpy/style/filereader.py (219668 => 219669)


--- trunk/Tools/Scripts/webkitpy/style/filereader.py	2017-07-20 00:15:08 UTC (rev 219668)
+++ trunk/Tools/Scripts/webkitpy/style/filereader.py	2017-07-20 00:17:40 UTC (rev 219669)
@@ -113,6 +113,7 @@
         if abs_file_path not in self._files:
             self._files[abs_file_path] = None
         if 'line_numbers' in kwargs:
+            # Deleted files will be 'None', but if a file has modified lines, this information should override the 'None'
             if self._files[abs_file_path] is None:
                 self._files[abs_file_path] = []
             self._files[abs_file_path] = self._files[abs_file_path] + kwargs['line_numbers']
@@ -151,11 +152,10 @@
         self._processor.do_association_check(self._files, cwd, host=host)
 
     def delete_file(self, file_path=None):
-        """Count up files that contains only deleted lines.
+        """Keep track of deleted files.
 
         Files which has no modified or newly-added lines don't need
-        to check style, but should be treated as checked. For that
-        purpose, we just count up the number of such files.
+        to check style, but they may effect the association check.
         """
         if file_path:
             self._files[self.filesystem.abspath(file_path)] = None
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to