Skip to content

Commit

Permalink
[lint] Check variants for reftests (web-platform-tests#42129)
Browse files Browse the repository at this point in the history
As of web-platform-tests#40352, reftests may use variants and should be linted too. All
files still lint cleanly, according to `wpt lint --all`.

Fixes https://crbug.com/1485860#c1
  • Loading branch information
jonathan-j-lee authored Sep 28, 2023
1 parent e6c3dc6 commit 44b9958
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ def check_parsed(repo_root: Text, path: Text, f: IO[bytes]) -> List[rules.Error]
if timeout_value != "long":
errors.append(rules.InvalidTimeout.error(path, (timeout_value,)))

if source_file.content_is_ref_node or source_file.content_is_testharness:
for element in source_file.variant_nodes:
if "content" not in element.attrib:
errors.append(rules.VariantMissing.error(path))
else:
variant = element.attrib["content"]
if (variant == "" or
variant[0] not in ("?", "#") or
len(variant) == 1 or
(variant[0] == "?" and variant[1] == "#")):
errors.append(rules.MalformedVariant.error(path, (path,)))

required_elements: List[Text] = []

testharnessreport_nodes: List[ElementTree.Element] = []
Expand All @@ -450,17 +462,6 @@ def check_parsed(repo_root: Text, path: Text, f: IO[bytes]) -> List[rules.Error]
if len(testharnessreport_nodes) > 1:
errors.append(rules.MultipleTestharnessReport.error(path))

for element in source_file.variant_nodes:
if "content" not in element.attrib:
errors.append(rules.VariantMissing.error(path))
else:
variant = element.attrib["content"]
if (variant == "" or
variant[0] not in ("?", "#") or
len(variant) == 1 or
(variant[0] == "?" and variant[1] == "#")):
errors.append(rules.MalformedVariant.error(path, (path,)))

required_elements.extend(key for key, value in {"testharness": True,
"testharnessreport": len(testharnessreport_nodes) > 0,
"timeout": len(source_file.timeout_nodes) > 0}.items()
Expand Down

0 comments on commit 44b9958

Please sign in to comment.