From 767494dc35eb1e90cacb28261afb44c32eb3f0fa Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Fri, 12 Sep 2014 16:05:23 -0400 Subject: [PATCH] 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. --- test/run-tests.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/test/run-tests.py b/test/run-tests.py index a175355a..87976559 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -184,12 +184,14 @@ def init(): www_path = os.path.join(base_path, 'www') parser = optparse.OptionParser( - usage='%prog [options]', + usage='%prog [options] [tests to run...]', description='Run PhantomJS tests.' ) parser.add_option('--verbose', action='store_true', default=False, help='Show a verbose log') (options, args) = parser.parse_args(sys.argv[1:]) + options.to_run = args + if options.verbose: returncode, version = run_phantomjs('--version') print 'Checking PhantomJS version %s' % version @@ -245,30 +247,45 @@ def run_test(script, name): def run_tests(): setup_server() if not http_running: - return + return 1 start = time.time() if options.verbose: print 'Starting the tests...' - print result = 0 + any_executed = False for test_group in TESTS: test_group_name = os.path.dirname(test_group) test_glob = os.path.normpath(base_path + '/' + test_group) if options.verbose: - print 'Test group: %s...' % test_group_name print + print 'Test group: %s...' % test_group_name for test_script in glob.glob(test_glob): 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) if ret != 0: print 'The test %s FAILED' % tname print result = 1 + if not any_executed: + result = 1 + print + print 'ALL TESTS SKIPPED.' + if result == 0: print print 'No failure. Finished in %d seconds.' % (time.time() - start)