check-webkit-style failing with "Path does not exist."
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 21:02:53 +0000 (21:02 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 21:02:53 +0000 (21:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77873

Reviewed by Ojan Vafai.

This change fixes the way the style checker determines which
Port class to use for a given test_expectations.txt path; the
previous version used a heuristic that didn't really work in the
first place.

* Scripts/webkitpy/style/checkers/test_expectations.py:
(TestExpectationsChecker._determine_port_from_expectations_path):
(TestExpectationsChecker.__init__):
* Scripts/webkitpy/style/checkers/test_expectations_unittest.py:
(TestExpectationsTestCase._expect_port_for_expectations_path):
(TestExpectationsTestCase.test_determine_port_from_expectations_path):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107124 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/style/checkers/test_expectations.py
Tools/Scripts/webkitpy/style/checkers/test_expectations_unittest.py

index 918e489..b778ed9 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-08  Dirk Pranke  <dpranke@chromium.org>
+
+        check-webkit-style failing with "Path does not exist."
+        https://bugs.webkit.org/show_bug.cgi?id=77873
+
+        Reviewed by Ojan Vafai.
+
+        This change fixes the way the style checker determines which
+        Port class to use for a given test_expectations.txt path; the
+        previous version used a heuristic that didn't really work in the
+        first place.
+
+        * Scripts/webkitpy/style/checkers/test_expectations.py:
+        (TestExpectationsChecker._determine_port_from_expectations_path):
+        (TestExpectationsChecker.__init__):
+        * Scripts/webkitpy/style/checkers/test_expectations_unittest.py:
+        (TestExpectationsTestCase._expect_port_for_expectations_path):
+        (TestExpectationsTestCase.test_determine_port_from_expectations_path):
+
 2012-02-08  FehĂ©r Zsolt  <feherzs@inf.u-szeged.hu>
 
         nrwt: make --skip-pixel-test-if-no-baseline option
index 2cabc80..ff1be9c 100644 (file)
@@ -47,17 +47,14 @@ class TestExpectationsChecker(object):
 
     categories = set(['test/expectations'])
 
-    def _determine_port_from_exepectations_path(self, host, expectations_path):
-        try:
-            port_name = expectations_path.split(host.filesystem.sep)[-2]
-            if not port_name:
-                return None
-
-            # Pass a configuration to avoid calling default_configuration() when initializing the port (takes 0.5 seconds on a Mac Pro!).
-            return host.port_factory.get(port_name, options=DummyOptions(configuration="Release"))
-        except Exception, e:
-            _log.warn("Exception while getting port for path %s" % expectations_path)
-            return None
+    def _determine_port_from_expectations_path(self, host, expectations_path):
+        # Pass a configuration to avoid calling default_configuration() when initializing the port (takes 0.5 seconds on a Mac Pro!).
+        options = DummyOptions(configuration='Release')
+        for port_name in host.port_factory.all_port_names():
+            port = host.port_factory.get(port_name, options=options)
+            if port.path_to_test_expectations_file().replace(port.path_from_webkit_base() + host.filesystem.sep, '') == expectations_path:
+                return port
+        return None
 
     def __init__(self, file_path, handle_style_error, host=None):
         self._file_path = file_path
@@ -70,15 +67,8 @@ class TestExpectationsChecker(object):
         host = host or Host()
         host._initialize_scm()
 
-        # Determining the port of this expectations.
-        self._port_obj = self._determine_port_from_exepectations_path(host, file_path)
-        # Using 'test' port when we couldn't determine the port for this
-        # expectations.
-        if not self._port_obj:
-            _log.warn("Could not determine the port for %s. "
-                      "Using 'test' port, but platform-specific expectations "
-                      "will fail the check." % self._file_path)
-            self._port_obj = host.port_factory.get('test')
+        self._port_obj = self._determine_port_from_expectations_path(host, file_path)
+
         # Suppress error messages of test_expectations module since they will be reported later.
         log = logging.getLogger("webkitpy.layout_tests.layout_package.test_expectations")
         log.setLevel(logging.CRITICAL)
@@ -112,8 +102,12 @@ class TestExpectationsChecker(object):
     def check(self, lines):
         overrides = self._port_obj.test_expectations_overrides()
         expectations = '\n'.join(lines)
-        self.check_test_expectations(expectations_str=expectations,
-                                     tests=None,
-                                     overrides=overrides)
+        if self._port_obj:
+            self.check_test_expectations(expectations_str=expectations,
+                                         tests=None,
+                                         overrides=overrides)
+        else:
+            self._handle_style_error(1, 'test/expectations', 5,
+                                     'No port uses path %s for test_expectations' % self._file_path)
         # Warn tabs in lines as well
         self.check_tabs(lines)
index 10cc7de..77bdf82 100644 (file)
@@ -63,23 +63,34 @@ class TestExpectationsTestCase(unittest.TestCase):
         self._error_collector = ErrorCollector()
         self._test_file = 'passes/text.html'
 
-    def _expect_port_for_expectations_path(self, expected_port_or_port_class, expectations_path):
+    def _expect_port_for_expectations_path(self, expected_port_implementation, expectations_path):
         host = MockHost()
         checker = TestExpectationsChecker(expectations_path, ErrorCollector(), host=host)
-        port = checker._determine_port_from_exepectations_path(host, expectations_path)
+        port = checker._determine_port_from_expectations_path(host, expectations_path)
         if port:
-            self.assertEquals(port.__class__.__name__, expected_port_or_port_class)
+            self.assertTrue(port.name().startswith(expected_port_implementation))
         else:
-            self.assertEquals(port, expected_port_or_port_class)
+            self.assertEquals(None, expected_port_implementation)
 
-    def test_determine_port_from_exepectations_path(self):
-        self._expect_port_for_expectations_path(None, "/")
-        self._expect_port_for_expectations_path("ChromiumMacPort", "/mock-checkout/LayoutTests/chromium-mac/test_expectations.txt")
+    def test_determine_port_from_expectations_path(self):
+        self._expect_port_for_expectations_path(None, '/')
+        self._expect_port_for_expectations_path(None, 'LayoutTests/chromium-mac/test_expectations.txt')
+        self._expect_port_for_expectations_path('chromium', 'LayoutTests/platform/chromium/test_expectations.txt')
+        self._expect_port_for_expectations_path(None, '/mock-checkout/LayoutTests/platform/win/test_expectations.txt')
+        self._expect_port_for_expectations_path('win', 'LayoutTests/platform/win/test_expectations.txt')
 
     def assert_lines_lint(self, lines, should_pass, expected_output=None):
         self._error_collector.reset_errors()
+
+        host = MockHost()
         checker = TestExpectationsChecker('test/test_expectations.txt',
-                                          self._error_collector, host=MockHost())
+                                          self._error_collector, host=host)
+
+        # We should have failed to find a valid port object for that path.
+        self.assertEquals(checker._port_obj, None)
+
+        # Now use a test port so we can check the lines.
+        checker._port_obj = host.port_factory.get('test-mac-leopard')
         checker.check_test_expectations(expectations_str='\n'.join(lines),
                                         tests=[self._test_file],
                                         overrides=None)