1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 class TestHarness(object):
12 def __init__(self
, test
, verbose
):
14 self
.verbose
= verbose
15 self
.printed_intro
= False
19 self
.maybe_print_intro()
22 if self
.verbose
or self
.printed_intro
:
23 print "Finished test %s" % self
.test
25 def maybe_print_intro(self
):
26 if not self
.printed_intro
:
27 print "Starting test %s" % self
.test
28 self
.printed_intro
= True
30 def test_pass(self
, msg
):
32 print "TEST-PASS | %s" % msg
34 def test_fail(self
, msg
):
35 self
.maybe_print_intro()
36 print "TEST-UNEXPECTED-FAIL | %s" % msg
38 def ok(self
, condition
, msg
):
44 def check(self
, a
, b
, msg
):
49 print "\tGot %s expected %s" % (a
, b
)
51 def run_tests(tests
, verbose
):
52 testdir
= os
.path
.join(os
.path
.dirname(__file__
), 'tests')
54 tests
= glob
.iglob(os
.path
.join(testdir
, "*.py"))
55 sys
.path
.append(testdir
)
58 (testpath
, ext
) = os
.path
.splitext(os
.path
.basename(test
))
59 _test
= __import__(testpath
, globals(), locals(), ['WebIDLTest'])
61 harness
= TestHarness(test
, verbose
)
64 _test
.WebIDLTest
.__call
__(WebIDL
.Parser(), harness
)
66 print "TEST-UNEXPECTED-FAIL | Unhandled exception in test %s: %s" % (testpath
, ex
)
71 if __name__
== '__main__':
72 usage
= """%prog [OPTIONS] [TESTS]
73 Where TESTS are relative to the tests directory."""
74 parser
= optparse
.OptionParser(usage
=usage
)
75 parser
.add_option('-q', '--quiet', action
='store_false', dest
='verbose', default
=True,
76 help="Don't print passing tests.")
77 options
, tests
= parser
.parse_args()
79 run_tests(tests
, verbose
=options
.verbose
)