Add support for selective test execution.

If there are any positional arguments to test/run-tests.py, they are matched
(verbatim, not as regular expressions) against each test's name.  Only those
tests whose names contain at least one of the positional arguments will be
run.  Thus, for instance, you can run just the webpage tests with

    ./test/run-tests.py module/webpage

or one specific test with

    ./test/run-tests.py exact/name/of/test.js

or the basics and standards tests with

    ./test/run-tests.py basics standards

If no tests at all match, run-tests.py will print "ALL TESTS SKIPPED" and
exit unsuccessfully.

Ongoing work on issue #12439.
2.0
Zack Weinberg 2014-09-12 16:05:23 -04:00
parent 4d60e9450d
commit 767494dc35
1 changed files with 21 additions and 4 deletions

View File

@ -184,12 +184,14 @@ def init():
www_path = os.path.join(base_path, 'www') www_path = os.path.join(base_path, 'www')
parser = optparse.OptionParser( parser = optparse.OptionParser(
usage='%prog [options]', usage='%prog [options] [tests to run...]',
description='Run PhantomJS tests.' description='Run PhantomJS tests.'
) )
parser.add_option('--verbose', action='store_true', default=False, help='Show a verbose log') parser.add_option('--verbose', action='store_true', default=False, help='Show a verbose log')
(options, args) = parser.parse_args(sys.argv[1:]) (options, args) = parser.parse_args(sys.argv[1:])
options.to_run = args
if options.verbose: if options.verbose:
returncode, version = run_phantomjs('--version') returncode, version = run_phantomjs('--version')
print 'Checking PhantomJS version %s' % version print 'Checking PhantomJS version %s' % version
@ -245,30 +247,45 @@ def run_test(script, name):
def run_tests(): def run_tests():
setup_server() setup_server()
if not http_running: if not http_running:
return return 1
start = time.time() start = time.time()
if options.verbose: if options.verbose:
print 'Starting the tests...' print 'Starting the tests...'
print
result = 0 result = 0
any_executed = False
for test_group in TESTS: for test_group in TESTS:
test_group_name = os.path.dirname(test_group) test_group_name = os.path.dirname(test_group)
test_glob = os.path.normpath(base_path + '/' + test_group) test_glob = os.path.normpath(base_path + '/' + test_group)
if options.verbose: if options.verbose:
print 'Test group: %s...' % test_group_name
print print
print 'Test group: %s...' % test_group_name
for test_script in glob.glob(test_glob): for test_script in glob.glob(test_glob):
tname = test_group_name + '/' + os.path.basename(test_script) tname = test_group_name + '/' + os.path.basename(test_script)
if options.to_run:
for to_run in options.to_run:
if to_run in tname:
break
else:
if options.verbose:
print "%s: skipped" % tname
continue
any_executed = True
ret = run_test(test_script, tname) ret = run_test(test_script, tname)
if ret != 0: if ret != 0:
print 'The test %s FAILED' % tname print 'The test %s FAILED' % tname
print print
result = 1 result = 1
if not any_executed:
result = 1
print
print 'ALL TESTS SKIPPED.'
if result == 0: if result == 0:
print print
print 'No failure. Finished in %d seconds.' % (time.time() - start) print 'No failure. Finished in %d seconds.' % (time.time() - start)