dom/bindings/parser/runtests.py

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import os, sys
michael@0 6 import glob
michael@0 7 import optparse
michael@0 8 import traceback
michael@0 9 import WebIDL
michael@0 10
michael@0 11 class TestHarness(object):
michael@0 12 def __init__(self, test, verbose):
michael@0 13 self.test = test
michael@0 14 self.verbose = verbose
michael@0 15 self.printed_intro = False
michael@0 16
michael@0 17 def start(self):
michael@0 18 if self.verbose:
michael@0 19 self.maybe_print_intro()
michael@0 20
michael@0 21 def finish(self):
michael@0 22 if self.verbose or self.printed_intro:
michael@0 23 print "Finished test %s" % self.test
michael@0 24
michael@0 25 def maybe_print_intro(self):
michael@0 26 if not self.printed_intro:
michael@0 27 print "Starting test %s" % self.test
michael@0 28 self.printed_intro = True
michael@0 29
michael@0 30 def test_pass(self, msg):
michael@0 31 if self.verbose:
michael@0 32 print "TEST-PASS | %s" % msg
michael@0 33
michael@0 34 def test_fail(self, msg):
michael@0 35 self.maybe_print_intro()
michael@0 36 print "TEST-UNEXPECTED-FAIL | %s" % msg
michael@0 37
michael@0 38 def ok(self, condition, msg):
michael@0 39 if condition:
michael@0 40 self.test_pass(msg)
michael@0 41 else:
michael@0 42 self.test_fail(msg)
michael@0 43
michael@0 44 def check(self, a, b, msg):
michael@0 45 if a == b:
michael@0 46 self.test_pass(msg)
michael@0 47 else:
michael@0 48 self.test_fail(msg)
michael@0 49 print "\tGot %s expected %s" % (a, b)
michael@0 50
michael@0 51 def run_tests(tests, verbose):
michael@0 52 testdir = os.path.join(os.path.dirname(__file__), 'tests')
michael@0 53 if not tests:
michael@0 54 tests = glob.iglob(os.path.join(testdir, "*.py"))
michael@0 55 sys.path.append(testdir)
michael@0 56
michael@0 57 for test in tests:
michael@0 58 (testpath, ext) = os.path.splitext(os.path.basename(test))
michael@0 59 _test = __import__(testpath, globals(), locals(), ['WebIDLTest'])
michael@0 60
michael@0 61 harness = TestHarness(test, verbose)
michael@0 62 harness.start()
michael@0 63 try:
michael@0 64 _test.WebIDLTest.__call__(WebIDL.Parser(), harness)
michael@0 65 except Exception, ex:
michael@0 66 print "TEST-UNEXPECTED-FAIL | Unhandled exception in test %s: %s" % (testpath, ex)
michael@0 67 traceback.print_exc()
michael@0 68 finally:
michael@0 69 harness.finish()
michael@0 70
michael@0 71 if __name__ == '__main__':
michael@0 72 usage = """%prog [OPTIONS] [TESTS]
michael@0 73 Where TESTS are relative to the tests directory."""
michael@0 74 parser = optparse.OptionParser(usage=usage)
michael@0 75 parser.add_option('-q', '--quiet', action='store_false', dest='verbose', default=True,
michael@0 76 help="Don't print passing tests.")
michael@0 77 options, tests = parser.parse_args()
michael@0 78
michael@0 79 run_tests(tests, verbose=options.verbose)

mercurial