зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1214783 - Create a |mach web-platform-tests-create| command, r=Ms2ger
This provides a simple way of creating a web-platform-test with all the boilerplate added automatically. It also updates the manifest file with the new test and opens it in the configured editor and source build.
This commit is contained in:
Родитель
a552b9785c
Коммит
f6a1734e70
|
@ -116,6 +116,65 @@ class WebPlatformTestsReduce(WebPlatformTestsRunner):
|
|||
for item in tests:
|
||||
logger.info(item.id)
|
||||
|
||||
class WebPlatformTestsCreator(MozbuildObject):
|
||||
template_prefix = """<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
"""
|
||||
template_long_timeout = "<meta name=timeout content=long>\n"
|
||||
|
||||
template_body = """<title></title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
"""
|
||||
|
||||
def run_create(self, context, **kwargs):
|
||||
import subprocess
|
||||
|
||||
path = os.path.normpath(os.path.abspath(kwargs["path"]))
|
||||
|
||||
rel_path = os.path.relpath(path, self.topsrcdir)
|
||||
if not (rel_path.startswith("testing/web-platform/tests") or
|
||||
rel_path.startswith("testing/web-platform/mozilla/tests")):
|
||||
print("""Test path is not in wpt directories:
|
||||
testing/web-platform/tests for tests that may be shared
|
||||
testing/web-platform/mozilla/tests for Gecko only tests""")
|
||||
return 1
|
||||
|
||||
if os.path.exists(path) and not kwargs["overwrite"]:
|
||||
print("Test path already exists, pass --overwrite to replace")
|
||||
return 1
|
||||
|
||||
template = self.template_prefix
|
||||
if kwargs["long_timeout"]:
|
||||
template += self.template_long_timeout
|
||||
template += self.template_body
|
||||
with open(path, "w") as f:
|
||||
f.write(template)
|
||||
|
||||
if kwargs["no_editor"]:
|
||||
editor = None
|
||||
elif kwargs["editor"]:
|
||||
editor = kwargs["editor"]
|
||||
elif "VISUAL" in os.environ:
|
||||
editor = os.environ["VISUAL"]
|
||||
elif "EDITOR" in os.environ:
|
||||
editor = os.environ["EDITOR"]
|
||||
else:
|
||||
editor = None
|
||||
|
||||
if editor:
|
||||
proc = subprocess.Popen("%s %s" % (editor, path), shell=True)
|
||||
|
||||
if not kwargs["no_run"]:
|
||||
p = create_parser_wpt()
|
||||
wpt_kwargs = vars(p.parse_args(["--manifest-update", path]))
|
||||
context.commands.dispatch("web-platform-tests", context, **wpt_kwargs)
|
||||
|
||||
proc.wait()
|
||||
|
||||
def create_parser_wpt():
|
||||
from wptrunner import wptcommandline
|
||||
return wptcommandline.create_parser(["firefox"])
|
||||
|
@ -128,6 +187,22 @@ def create_parser_reduce():
|
|||
from wptrunner import wptcommandline
|
||||
return wptcommandline.create_parser_reduce()
|
||||
|
||||
def create_parser_create():
|
||||
import argparse
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument("--no-editor", action="store_true",
|
||||
help="Don't try to open the test in an editor")
|
||||
p.add_argument("-e", "--editor", action="store", help="Editor to use")
|
||||
p.add_argument("--no-run", action="store_true",
|
||||
help="Don't try to update the wpt manifest or open the test in a browser")
|
||||
p.add_argument("--long-timeout", action="store_true",
|
||||
help="Test should be given a long timeout (typically 60s rather than 10s, but varies depending on environment)")
|
||||
p.add_argument("--overwrite", action="store_true",
|
||||
help="Allow overwriting an existing test file")
|
||||
p.add_argument("path", action="store", help="Path to the test file")
|
||||
return p
|
||||
|
||||
|
||||
@CommandProvider
|
||||
class MachCommands(MachCommandBase):
|
||||
@Command("web-platform-tests",
|
||||
|
@ -170,3 +245,12 @@ class MachCommands(MachCommandBase):
|
|||
self.setup()
|
||||
wpt_reduce = self._spawn(WebPlatformTestsReduce)
|
||||
return wpt_reduce.run_reduce(**params)
|
||||
|
||||
@Command("web-platform-tests-create",
|
||||
category="testing",
|
||||
conditions=[conditions.is_firefox],
|
||||
parser=create_parser_create)
|
||||
def create_web_platform_test(self, **params):
|
||||
self.setup()
|
||||
wpt_creator = self._spawn(WebPlatformTestsCreator)
|
||||
wpt_creator.run_create(self._mach_context, **params)
|
||||
|
|
Загрузка…
Ссылка в новой задаче