Skip to content

Commit

Permalink
[import-w3c-tests] Preserve variant expectations on import
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=258613
rdar://problem/111770351

Reviewed by Jonathan Bedard.

This moves to actually finding the tests and their expectations
through the general logic, rather than implementing our own logic to
find relevant expectation files.

* Tools/Scripts/webkitpy/w3c/test_importer.py:
(TestImporter.__init__):
(TestImporter.remove_dangling_expectations):
* Tools/Scripts/webkitpy/w3c/test_importer_unittest.py:

Canonical link: https://commits.webkit.org/266588@main
  • Loading branch information
gsnedders committed Aug 4, 2023
1 parent b696c86 commit d8e12ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Tools/Scripts/webkitpy/w3c/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
from webkitpy.common.host import Host
from webkitpy.common.system.filesystem import FileSystem
from webkitpy.common.webkit_finder import WebKitFinder
from webkitpy.port.factory import PortFactory
from webkitpy.layout_tests.controllers.layout_test_finder_legacy import LayoutTestFinder
from webkitpy.w3c.common import TEMPLATED_TEST_HEADER, WPT_GH_URL, WPTPaths
from webkitpy.w3c.test_parser import TestParser
from webkitpy.w3c.test_converter import convert_for_webkit
Expand Down Expand Up @@ -156,6 +158,7 @@ def __init__(self, host, test_paths, options):
self.options = options
self.test_paths = test_paths if test_paths else []

self.port = PortFactory(host).get()
self.filesystem = self.host.filesystem

webkit_finder = WebKitFinder(self.filesystem)
Expand Down Expand Up @@ -280,9 +283,11 @@ def clean_destination_directory(self, filename):
def remove_dangling_expectations(self, filename):
#FIXME: Clean also the expected files stored in all platform specific folders.
directory = self.filesystem.join(self.destination_directory, filename)
tests = LayoutTestFinder(self.port, None).find_tests_by_path([directory])
baselines_for_tests = {self.port.expected_filename(test.test_path, '.txt') for test in tests}
for relative_path in self.filesystem.files_under(directory, file_filter=self._is_baseline):
path = self.filesystem.join(directory, relative_path)
if self.filesystem.glob(path.replace('-expected.txt', '*')) == [path]:
if path not in baselines_for_tests:
self.filesystem.remove(path)

def _source_root_directory_for_path(self, path):
Expand Down
17 changes: 17 additions & 0 deletions Tools/Scripts/webkitpy/w3c/test_importer_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,20 @@ def test_template_test_variant(self):
self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any.html'))
self.assertTrue('<!-- META: variant=?1-10 -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any.html'))
self.assertTrue('<!-- META: variant=?11-20 -->' in fs.read_text_file('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any.html'))

def test_template_test_variant_dangling(self):
FAKE_FILES = {
'/mock-checkout/WebKitBuild/w3c-tests/web-platform-tests/t/variant.any.js': '// META: variant=?1-10\n// META: variant=?11-20',
'/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any.js': '// META: variant=?1-10\n// META: variant=?11-20',
'/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any_1-10-expected.txt': '1',
'/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any_11-20-expected.txt': '2',
'/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any_21-30-expected.txt': '3',
}
FAKE_FILES.update(FAKE_REPOSITORY)

fs = self.import_downloaded_tests(['--no-fetch', '--import-all', '-d', 'w3c'], FAKE_FILES)

self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any.html'))
self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any_1-10-expected.txt'))
self.assertTrue(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any_11-20-expected.txt'))
self.assertFalse(fs.exists('/mock-checkout/LayoutTests/w3c/web-platform-tests/t/variant.any_21-30-expected.txt'))

0 comments on commit d8e12ca

Please sign in to comment.