Skip to content

Commit

Permalink
import-w3c-tests should rewrite reference file names in meta fuzzy an…
Browse files Browse the repository at this point in the history
…notations.

https://bugs.webkit.org/show_bug.cgi?id=270426
<rdar://124034791>

Reviewed by Jonathan Bedard.

* Tools/Scripts/webkitpy/w3c/test_converter.py:
(convert_for_webkit):
(_W3CTestConverter.__init__):
(_W3CTestConverter.convert_attributes_if_needed):
* Tools/Scripts/webkitpy/w3c/test_importer.py:
(TestImporter.find_importable_tests):
(TestImporter.import_tests):

Canonical link: https://commits.webkit.org/275750@main
  • Loading branch information
mattwoodrow committed Mar 6, 2024
1 parent 095152b commit 525f853
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 7 additions & 3 deletions Tools/Scripts/webkitpy/w3c/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
_log = logging.getLogger(__name__)


def convert_for_webkit(new_path, filename, reference_support_info, host=Host(), webkit_test_runner_options=''):
def convert_for_webkit(new_path, filename, reference_support_info, reference_file_renames, host=Host(), webkit_test_runner_options=''):
""" Converts a file's |contents| so it will function correctly in its |new_path| in Webkit.
Returns the list of modified properties and the modified text if the file was modifed, None otherwise."""
contents = host.filesystem.read_text_file(filename)

converter = _W3CTestConverter(new_path, filename, reference_support_info, host, webkit_test_runner_options)
converter = _W3CTestConverter(new_path, filename, reference_support_info, reference_file_renames, host, webkit_test_runner_options)
if filename.endswith('.css'):
return converter.add_webkit_prefix_to_unprefixed_properties_and_values(contents)
elif filename.endswith('.js'):
Expand All @@ -60,7 +60,7 @@ def convert_for_webkit(new_path, filename, reference_support_info, host=Host(),


class _W3CTestConverter(HTMLParser):
def __init__(self, new_path, filename, reference_support_info, host=Host(), webkit_test_runner_options=''):
def __init__(self, new_path, filename, reference_support_info, reference_file_renames=[], host=Host(), webkit_test_runner_options=''):
if sys.version_info > (3, 0):
HTMLParser.__init__(self, convert_charrefs=False)
else:
Expand All @@ -77,6 +77,7 @@ def __init__(self, new_path, filename, reference_support_info, host=Host(), webk
self.style_data = []
self.filename = filename
self.reference_support_info = reference_support_info
self.reference_file_renames = reference_file_renames
self.webkit_test_runner_options = webkit_test_runner_options
self.has_started = False

Expand Down Expand Up @@ -202,6 +203,9 @@ def convert_attributes_if_needed(self, tag, attrs):
if attr[0] == 'style':
new_style = self.convert_style_data(attr[1])
converted = re.sub(re.escape(attr[1]), new_style, converted)
if attr[0] == 'name' and attr[1] == 'fuzzy' and tag == 'meta':
for rename in self.reference_file_renames:
converted = re.sub(rename['src'], rename['dest'], converted)

# Convert relative paths
src_tags = ('script', 'style', 'img', 'frame', 'iframe', 'input', 'layer', 'textarea', 'video', 'audio')
Expand Down
13 changes: 11 additions & 2 deletions Tools/Scripts/webkitpy/w3c/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ def find_importable_tests(self, directory):
total_tests += 1
test_basename = self.filesystem.basename(test_info['test'])

ref_files = []

# Add the ref file, following WebKit style.
# FIXME: Ideally we'd support reading the metadata
# directly rather than relying on a naming convention.
Expand All @@ -402,13 +404,15 @@ def find_importable_tests(self, directory):
ref_file = self.filesystem.splitext(test_basename)[0] + '-expected'
ref_file += self.filesystem.splitext(test_info['match_reference'])[1]
copy_list.append({'src': test_info['match_reference'], 'dest': ref_file, 'reference_support_info': test_info['match_reference_support_info']})
ref_files.append({'src': self.filesystem.split(test_info['match_reference'])[1], 'dest': self.filesystem.split(ref_file)[1]})

if 'mismatch_reference' in test_info.keys():
ref_file = self.filesystem.splitext(test_basename)[0] + '-expected-mismatch'
ref_file += self.filesystem.splitext(test_info['mismatch_reference'])[1]
copy_list.append({'src': test_info['mismatch_reference'], 'dest': ref_file, 'reference_support_info': test_info['mismatch_reference_support_info']})
ref_files.append({'src': self.filesystem.split(test_info['mismatch_reference'])[1], 'dest': self.filesystem.split(ref_file)[1]})

copy_list.append({'src': test_info['test'], 'dest': filename})
copy_list.append({'src': test_info['test'], 'dest': filename, 'reference_file_renames': ref_files})

elif 'jstest' in test_info.keys():
jstests += 1
Expand Down Expand Up @@ -566,6 +570,11 @@ def import_tests(self):
else:
reference_support_info = None

if 'reference_file_renames' in file_to_copy.keys() and file_to_copy['reference_file_renames'] != {}:
reference_file_renames = file_to_copy['reference_file_renames']
else:
reference_file_renames = []

if not(self.filesystem.exists(self.filesystem.dirname(new_filepath))):
self.filesystem.maybe_make_directory(self.filesystem.dirname(new_filepath))

Expand All @@ -585,7 +594,7 @@ def import_tests(self):
and ('html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or 'css' in str(mimetype[0]) or 'javascript' in str(mimetype[0])):
_log.info("Rewriting: %s" % new_filepath)
try:
converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info, host=self.host, webkit_test_runner_options=self._webkit_test_runner_options(new_filepath))
converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info, reference_file_renames=reference_file_renames, host=self.host, webkit_test_runner_options=self._webkit_test_runner_options(new_filepath))
except:
_log.warn('Failed converting %s', orig_filepath)
failed_conversion_files.append(orig_filepath)
Expand Down

0 comments on commit 525f853

Please sign in to comment.