mirror of
https://github.com/servo/servo.git
synced 2025-08-18 03:45:33 +01:00
Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326
This commit is contained in:
parent
462c272380
commit
1f531f66ea
5377 changed files with 174916 additions and 84369 deletions
3
tests/wpt/web-platform-tests/tools/lint/commands.json
Normal file
3
tests/wpt/web-platform-tests/tools/lint/commands.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{"lint":
|
||||
{"path": "lint.py", "script": "main", "parser": "create_parser", "help": "Run the lint",
|
||||
"virtualenv": false}}
|
|
@ -15,8 +15,9 @@ from collections import defaultdict
|
|||
from . import fnmatch
|
||||
from .. import localpaths
|
||||
from ..gitignore.gitignore import PathFilter
|
||||
from ..wpt import testfiles
|
||||
|
||||
from manifest.sourcefile import SourceFile, js_meta_re, python_meta_re
|
||||
from manifest.sourcefile import SourceFile, js_meta_re, python_meta_re, space_chars
|
||||
from six import binary_type, iteritems, itervalues
|
||||
from six.moves import range
|
||||
from six.moves.urllib.parse import urlsplit, urljoin
|
||||
|
@ -126,6 +127,13 @@ def check_worker_collision(repo_root, path, css_mode):
|
|||
return []
|
||||
|
||||
|
||||
def check_ahem_copy(repo_root, path, css_mode):
|
||||
lpath = path.lower()
|
||||
if "ahem" in lpath and lpath.endswith(".ttf"):
|
||||
return [("AHEM COPY", "Don't add extra copies of Ahem, use /fonts/Ahem.ttf", path, None)]
|
||||
return []
|
||||
|
||||
|
||||
drafts_csswg_re = re.compile(r"https?\:\/\/drafts\.csswg\.org\/([^/?#]+)")
|
||||
w3c_tr_re = re.compile(r"https?\:\/\/www\.w3c?\.org\/TR\/([^/?#]+)")
|
||||
w3c_dev_re = re.compile(r"https?\:\/\/dev\.w3c?\.org\/[^/?#]+\/([^/?#]+)")
|
||||
|
@ -335,12 +343,24 @@ class ConsoleRegexp(Regexp):
|
|||
file_extensions = [".html", ".htm", ".js", ".xht", ".xhtml", ".svg"]
|
||||
description = "Console logging API used"
|
||||
|
||||
class GenerateTestsRegexp(Regexp):
|
||||
pattern = b"generate_tests\s*\("
|
||||
error = "GENERATE_TESTS"
|
||||
file_extensions = [".html", ".htm", ".js", ".xht", ".xhtml", ".svg"]
|
||||
description = "generate_tests used"
|
||||
|
||||
class PrintRegexp(Regexp):
|
||||
pattern = b"print(?:\s|\s*\()"
|
||||
error = "PRINT STATEMENT"
|
||||
file_extensions = [".py"]
|
||||
description = "Print function used"
|
||||
|
||||
class LayoutTestsRegexp(Regexp):
|
||||
pattern = b"eventSender|testRunner|window\.internals"
|
||||
error = "LAYOUTTESTS APIS"
|
||||
file_extensions = [".html", ".htm", ".js", ".xht", ".xhtml", ".svg"]
|
||||
description = "eventSender/testRunner/window.internals used; these are LayoutTests-specific APIs (WebKit/Blink)"
|
||||
|
||||
regexps = [item() for item in
|
||||
[TrailingWhitespaceRegexp,
|
||||
TabsRegexp,
|
||||
|
@ -349,7 +369,9 @@ regexps = [item() for item in
|
|||
W3CTestOrgRegexp,
|
||||
Webidl2Regexp,
|
||||
ConsoleRegexp,
|
||||
PrintRegexp]]
|
||||
GenerateTestsRegexp,
|
||||
PrintRegexp,
|
||||
LayoutTestsRegexp]]
|
||||
|
||||
def check_regexp_line(repo_root, path, f, css_mode):
|
||||
errors = []
|
||||
|
@ -395,7 +417,7 @@ def check_parsed(repo_root, path, f, css_mode):
|
|||
return [("CONTENT-VISUAL", "Visual test whose filename doesn't end in '-visual'", path, None)]
|
||||
|
||||
for reftest_node in source_file.reftest_nodes:
|
||||
href = reftest_node.attrib.get("href", "")
|
||||
href = reftest_node.attrib.get("href", "").strip(space_chars)
|
||||
parts = urlsplit(href)
|
||||
if parts.scheme or parts.netloc:
|
||||
errors.append(("ABSOLUTE-URL-REF",
|
||||
|
@ -636,6 +658,7 @@ def output_errors_text(errors):
|
|||
pos_string += ":%s" % line_number
|
||||
logger.error("%s: %s (%s)" % (pos_string, description, error_type))
|
||||
|
||||
|
||||
def output_errors_markdown(errors):
|
||||
if not errors:
|
||||
return
|
||||
|
@ -651,6 +674,7 @@ def output_errors_markdown(errors):
|
|||
pos_string += ":%s" % line_number
|
||||
logger.error("%s | %s | %s |" % (error_type, pos_string, description))
|
||||
|
||||
|
||||
def output_errors_json(errors):
|
||||
for error_type, error, path, line_number in errors:
|
||||
print(json.dumps({"path": path, "lineno": line_number,
|
||||
|
@ -669,7 +693,34 @@ def output_error_count(error_count):
|
|||
else:
|
||||
logger.info("There were %d errors (%s)" % (count, by_type))
|
||||
|
||||
def parse_args():
|
||||
|
||||
def changed_files(wpt_root):
|
||||
revish = testfiles.get_revish(revish=None)
|
||||
changed, _ = testfiles.files_changed(revish, set(), include_uncommitted=True, include_new=True)
|
||||
return [os.path.relpath(item, wpt_root) for item in changed]
|
||||
|
||||
|
||||
def lint_paths(kwargs, wpt_root):
|
||||
if kwargs.get("paths"):
|
||||
paths = kwargs["paths"]
|
||||
elif kwargs["all"]:
|
||||
paths = list(all_filesystem_paths(wpt_root))
|
||||
else:
|
||||
changed_paths = changed_files(wpt_root)
|
||||
force_all = False
|
||||
# If we changed the lint itself ensure that we retest everything
|
||||
for path in changed_paths:
|
||||
path = path.replace(os.path.sep, "/")
|
||||
if path == "lint.whitelist" or path.startswith("tools/lint/"):
|
||||
force_all = True
|
||||
break
|
||||
paths = (list(changed_paths) if not force_all
|
||||
else list(all_filesystem_paths(wpt_root)))
|
||||
|
||||
return paths
|
||||
|
||||
|
||||
def create_parser():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("paths", nargs="*",
|
||||
help="List of paths to lint")
|
||||
|
@ -681,7 +732,9 @@ def parse_args():
|
|||
help="Run CSS testsuite specific lints")
|
||||
parser.add_argument("--repo-root", help="The WPT directory. Use this"
|
||||
"option if the lint script exists outside the repository")
|
||||
return parser.parse_args()
|
||||
parser.add_argument("--all", action="store_true", help="If no paths are passed, try to lint the whole "
|
||||
"working directory, not just files that changed")
|
||||
return parser
|
||||
|
||||
|
||||
def main(**kwargs):
|
||||
|
@ -695,9 +748,11 @@ def main(**kwargs):
|
|||
(False, False): "normal"}[(kwargs.get("json", False),
|
||||
kwargs.get("markdown", False))]
|
||||
|
||||
paths = list(kwargs.get("paths") if kwargs.get("paths") else all_filesystem_paths(repo_root))
|
||||
if output_format == "markdown":
|
||||
setup_logging(True)
|
||||
|
||||
paths = lint_paths(kwargs, repo_root)
|
||||
|
||||
return lint(repo_root, paths, output_format, kwargs.get("css_mode", False))
|
||||
|
||||
|
||||
|
@ -760,12 +815,12 @@ def lint(repo_root, paths, output_format, css_mode):
|
|||
logger.info(line)
|
||||
return sum(itervalues(error_count))
|
||||
|
||||
path_lints = [check_path_length, check_worker_collision]
|
||||
path_lints = [check_path_length, check_worker_collision, check_ahem_copy]
|
||||
all_paths_lints = [check_css_globally_unique]
|
||||
file_lints = [check_regexp_line, check_parsed, check_python_ast, check_script_metadata]
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_args()
|
||||
args = create_parser().parse_args()
|
||||
error_count = main(**vars(args))
|
||||
if error_count > 0:
|
||||
sys.exit(1)
|
||||
|
|
|
@ -145,6 +145,51 @@ def test_setTimeout():
|
|||
1)]
|
||||
|
||||
|
||||
def test_eventSender():
|
||||
error_map = check_with_files(b"<script>eventSender.mouseDown()</script>")
|
||||
|
||||
for (filename, (errors, kind)) in error_map.items():
|
||||
check_errors(errors)
|
||||
|
||||
if kind == "python":
|
||||
assert errors == [("PARSE-FAILED", "Unable to parse file", filename, 1)]
|
||||
else:
|
||||
assert errors == [('LAYOUTTESTS APIS',
|
||||
'eventSender/testRunner/window.internals used; these are LayoutTests-specific APIs (WebKit/Blink)',
|
||||
filename,
|
||||
1)]
|
||||
|
||||
|
||||
def test_testRunner():
|
||||
error_map = check_with_files(b"<script>if (window.testRunner) { testRunner.waitUntilDone(); }</script>")
|
||||
|
||||
for (filename, (errors, kind)) in error_map.items():
|
||||
check_errors(errors)
|
||||
|
||||
if kind == "python":
|
||||
assert errors == [("PARSE-FAILED", "Unable to parse file", filename, 1)]
|
||||
else:
|
||||
assert errors == [('LAYOUTTESTS APIS',
|
||||
'eventSender/testRunner/window.internals used; these are LayoutTests-specific APIs (WebKit/Blink)',
|
||||
filename,
|
||||
1)]
|
||||
|
||||
|
||||
def test_windowDotInternals():
|
||||
error_map = check_with_files(b"<script>if (window.internals) { internals.doAThing(); }</script>")
|
||||
|
||||
for (filename, (errors, kind)) in error_map.items():
|
||||
check_errors(errors)
|
||||
|
||||
if kind == "python":
|
||||
assert errors == [("PARSE-FAILED", "Unable to parse file", filename, 1)]
|
||||
else:
|
||||
assert errors == [('LAYOUTTESTS APIS',
|
||||
'eventSender/testRunner/window.internals used; these are LayoutTests-specific APIs (WebKit/Blink)',
|
||||
filename,
|
||||
1)]
|
||||
|
||||
|
||||
def test_meta_timeout():
|
||||
code = b"""
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
|
|
|
@ -9,7 +9,7 @@ import six
|
|||
|
||||
from ...localpaths import repo_root
|
||||
from .. import lint as lint_mod
|
||||
from ..lint import filter_whitelist_errors, parse_whitelist, lint, parse_args
|
||||
from ..lint import filter_whitelist_errors, parse_whitelist, lint, create_parser
|
||||
|
||||
_dummy_repo = os.path.join(os.path.dirname(__file__), "dummy")
|
||||
|
||||
|
@ -389,7 +389,7 @@ def test_main_with_args():
|
|||
try:
|
||||
sys.argv = ['./lint', 'a', 'b', 'c']
|
||||
with _mock_lint('lint', return_value=True) as m:
|
||||
lint_mod.main(**vars(parse_args()))
|
||||
lint_mod.main(**vars(create_parser().parse_args()))
|
||||
m.assert_called_once_with(repo_root, ['a', 'b', 'c'], "normal", False)
|
||||
finally:
|
||||
sys.argv = orig_argv
|
||||
|
@ -400,8 +400,20 @@ def test_main_no_args():
|
|||
try:
|
||||
sys.argv = ['./lint']
|
||||
with _mock_lint('lint', return_value=True) as m:
|
||||
with _mock_lint('all_filesystem_paths', return_value=['foo', 'bar']) as m2:
|
||||
lint_mod.main(**vars(parse_args()))
|
||||
with _mock_lint('changed_files', return_value=['foo', 'bar']) as m2:
|
||||
lint_mod.main(**vars(create_parser().parse_args()))
|
||||
m.assert_called_once_with(repo_root, ['foo', 'bar'], "normal", False)
|
||||
finally:
|
||||
sys.argv = orig_argv
|
||||
|
||||
|
||||
def test_main_all():
|
||||
orig_argv = sys.argv
|
||||
try:
|
||||
sys.argv = ['./lint', '--all']
|
||||
with _mock_lint('lint', return_value=True) as m:
|
||||
with _mock_lint('all_filesystem_paths', return_value=['foo', 'bar']) as m2:
|
||||
lint_mod.main(**vars(create_parser().parse_args()))
|
||||
m.assert_called_once_with(repo_root, ['foo', 'bar'], "normal", False)
|
||||
finally:
|
||||
sys.argv = orig_argv
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue