Auto merge of #9459 - shinglyu:testwebidl, r=Wafflespeanut

Add mach test-webidl command

I updated the `WebIDL.py` from latest mozilla-central. And add a `./mach test-webidl` command. For #9397

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9459)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-01-30 21:21:53 +05:30
commit 0ada7f9c8e
6 changed files with 53 additions and 10 deletions

View file

@ -501,6 +501,10 @@ class IDLExposureMixins():
def isExposedInWindow(self): def isExposedInWindow(self):
return 'Window' in self.exposureSet return 'Window' in self.exposureSet
def isExposedOnMainThread(self):
return (self.isExposedInWindow() or
self.isExposedInSystemGlobals())
def isExposedInAnyWorker(self): def isExposedInAnyWorker(self):
return len(self.getWorkerExposureSet()) > 0 return len(self.getWorkerExposureSet()) > 0
@ -564,6 +568,9 @@ class IDLExternalInterface(IDLObjectWithIdentifier, IDLExposureMixins):
def isJSImplemented(self): def isJSImplemented(self):
return False return False
def isProbablyShortLivingObject(self):
return False
def getNavigatorProperty(self): def getNavigatorProperty(self):
return None return None
@ -1409,6 +1416,7 @@ class IDLInterface(IDLObjectWithScope, IDLExposureMixins):
identifier == "Unforgeable" or identifier == "Unforgeable" or
identifier == "UnsafeInPrerendering" or identifier == "UnsafeInPrerendering" or
identifier == "LegacyEventInit" or identifier == "LegacyEventInit" or
identifier == "ProbablyShortLivingObject" or
identifier == "Abstract"): identifier == "Abstract"):
# Known extended attributes that do not take values # Known extended attributes that do not take values
if not attr.noArguments(): if not attr.noArguments():
@ -1523,6 +1531,14 @@ class IDLInterface(IDLObjectWithScope, IDLExposureMixins):
def isJSImplemented(self): def isJSImplemented(self):
return bool(self.getJSImplementation()) return bool(self.getJSImplementation())
def isProbablyShortLivingObject(self):
current = self
while current:
if current.getExtendedAttribute("ProbablyShortLivingObject"):
return True
current = current.parent
return False
def getNavigatorProperty(self): def getNavigatorProperty(self):
naviProp = self.getExtendedAttribute("NavigatorProperty") naviProp = self.getExtendedAttribute("NavigatorProperty")
if not naviProp: if not naviProp:

View file

@ -1,11 +1,11 @@
--- WebIDL.py --- WebIDL.py
+++ WebIDL.py +++ WebIDL.py
@@ -1357,7 +1357,8 @@ class IDLInterface(IDLObjectWithScope, IDLExposureMixins): @@ -1416,7 +1416,8 @@
identifier == "ChromeOnly" or
identifier == "Unforgeable" or identifier == "Unforgeable" or
identifier == "UnsafeInPrerendering" or identifier == "UnsafeInPrerendering" or
- identifier == "LegacyEventInit"): identifier == "LegacyEventInit" or
+ identifier == "LegacyEventInit" or - identifier == "ProbablyShortLivingObject"):
+ identifier == "ProbablyShortLivingObject" or
+ identifier == "Abstract"): + identifier == "Abstract"):
# Known extended attributes that do not take values # Known extended attributes that do not take values
if not attr.noArguments(): if not attr.noArguments():

View file

@ -20,20 +20,20 @@ class TestHarness(object):
def finish(self): def finish(self):
if self.verbose or self.printed_intro: if self.verbose or self.printed_intro:
print "Finished test %s" % self.test print("Finished test %s" % self.test)
def maybe_print_intro(self): def maybe_print_intro(self):
if not self.printed_intro: if not self.printed_intro:
print "Starting test %s" % self.test print("Starting test %s" % self.test)
self.printed_intro = True self.printed_intro = True
def test_pass(self, msg): def test_pass(self, msg):
if self.verbose: if self.verbose:
print "TEST-PASS | %s" % msg print("TEST-PASS | %s" % msg)
def test_fail(self, msg): def test_fail(self, msg):
self.maybe_print_intro() self.maybe_print_intro()
print "TEST-UNEXPECTED-FAIL | %s" % msg print("TEST-UNEXPECTED-FAIL | %s" % msg)
def ok(self, condition, msg): def ok(self, condition, msg):
if condition: if condition:
@ -46,7 +46,7 @@ class TestHarness(object):
self.test_pass(msg) self.test_pass(msg)
else: else:
self.test_fail(msg) self.test_fail(msg)
print "\tGot %s expected %s" % (a, b) print("\tGot %s expected %s" % (a, b))
def run_tests(tests, verbose): def run_tests(tests, verbose):
testdir = os.path.join(os.path.dirname(__file__), 'tests') testdir = os.path.join(os.path.dirname(__file__), 'tests')
@ -63,7 +63,7 @@ def run_tests(tests, verbose):
try: try:
_test.WebIDLTest.__call__(WebIDL.Parser(), harness) _test.WebIDLTest.__call__(WebIDL.Parser(), harness)
except Exception, ex: except Exception, ex:
print "TEST-UNEXPECTED-FAIL | Unhandled exception in test %s: %s" % (testpath, ex) print("TEST-UNEXPECTED-FAIL | Unhandled exception in test %s: %s" % (testpath, ex))
traceback.print_exc() traceback.print_exc()
finally: finally:
harness.finish() harness.finish()

View file

@ -1,2 +1,4 @@
wget https://mxr.mozilla.org/mozilla-central/source/dom/bindings/parser/WebIDL.py?raw=1 -O WebIDL.py wget https://mxr.mozilla.org/mozilla-central/source/dom/bindings/parser/WebIDL.py?raw=1 -O WebIDL.py
patch < abstract.patch patch < abstract.patch
# TODO: update test files from https://dxr.mozilla.org/mozilla-central/source/dom/bindings/parser/tests

View file

@ -10,3 +10,6 @@ toml == 0.9.1
flake8 == 2.4.1 flake8 == 2.4.1
pep8 == 1.5.7 pep8 == 1.5.7
pyflakes == 0.8.0 pyflakes == 0.8.0
# For test-webidl
ply == 3.8

View file

@ -232,6 +232,28 @@ class MachCommands(CommandBase):
def test_tidy(self, faster): def test_tidy(self, faster):
return tidy.scan(faster) return tidy.scan(faster)
@Command('test-webidl',
description='Run the WebIDL parser tests',
category='testing')
@CommandArgument('--quiet', '-q', default=False, action="store_true",
help="Don't print passing tests.")
@CommandArgument('tests', default=None, nargs="...",
help="Specific tests to run, relative to the tests directory")
def test_webidl(self, quiet, tests):
self.ensure_bootstrapped()
test_file_dir = path.abspath(path.join(PROJECT_TOPLEVEL_PATH, "components", "script",
"dom", "bindings", "codegen", "parser"))
# For the `import WebIDL` in runtests.py
sys.path.insert(0, test_file_dir)
run_file = path.abspath(path.join(test_file_dir, "runtests.py"))
run_globals = {"__file__": run_file}
execfile(run_file, run_globals)
verbose = not quiet
return run_globals["run_tests"](tests, verbose)
@Command('test-wpt-failure', @Command('test-wpt-failure',
description='Run the web platform tests', description='Run the web platform tests',
category='testing') category='testing')