From b524d53d36912dd3250f3a399bfc9f8008d148a8 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Wed, 14 May 2014 16:48:56 -0400 Subject: [PATCH] Add ability to run tests selectively. * Anything on the command line after "run-tests.sh" will be understood as a regular expression (if there is more than one argument, they are concatenated, with spaces in between) and only the tests whose "full names" match that regexp will be run. The full name of a test is the "describe" string plus a space plus the "it" string. Note well that, unlike the test-runner output, there is no colon in there. * run-tests.sh and run-tests.js now correctly handle being invoked from an arbitrary directory; the cwd does not have to be the project root. * Shell portability fixes for run-tests.sh. #12230 (Test suite improvements). --- test/run-tests.js | 21 +++++++++++++++------ test/run-tests.sh | 8 ++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/test/run-tests.js b/test/run-tests.js index 03b7aabf..d9127d1d 100644 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -28,6 +28,11 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +// Set the working directory to the "/test" directory if it's not +// already there. +var fs = require('fs'); +fs.changeWorkingDirectory(phantom.libraryPath); + // Load Jasmine and the HTML reporter phantom.injectJs("./lib/jasmine.js"); phantom.injectJs("./lib/jasmine-console.js"); @@ -56,10 +61,6 @@ function expectHasPropertyString(o, name) { }); } -// Set the working directory to the "/test" directory -var fs = require('fs'); -fs.changeWorkingDirectory(phantom.libraryPath); - // Load specs phantom.injectJs("./phantom-spec.js"); phantom.injectJs("./webserver-spec.js"); @@ -75,12 +76,20 @@ require("./module_spec.js"); require("./require/require_spec.js"); require("./cjk-text-codecs.js"); -// Launch tests +// Environment configuration var jasmineEnv = jasmine.getEnv(); +// If there are any command line arguments, filter tests based on them. +var sys = require('system'); +if (sys.args.length > 1) { + var specFilterRe = new RegExp(sys.args.slice(1).join(" ")); + jasmineEnv.specFilter = function (spec) { + return specFilterRe.test(spec.getFullName()); + }; +} + // Add a ConsoleReporter to 1) print with colors on the console // 2) exit when finished -var sys = require('system'); jasmineEnv.addReporter(new jasmine.ConsoleReporter( // Print messages straight to the console, and don't mess with the newlines sys.stdout.write.bind(sys.stdout), diff --git a/test/run-tests.sh b/test/run-tests.sh index c0255884..2188761e 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -1,6 +1,2 @@ -#!/usr/bin/env bash - -# Run tests -bin/phantomjs test/run-tests.js - -exit $? +#!/bin/sh +exec "${0%/*}/../bin/phantomjs" "${0%/*}/run-tests.js" "$@"