Permalink
Browse files

added regex based test name filtering argument

  • Loading branch information...
1 parent 80d624d commit e38a86a3a550bd7a0765c57f377dfd0d6b3d9364 @einaros einaros committed Oct 2, 2011
Showing with 58 additions and 1 deletion.
  1. +23 −1 bin/expresso
  2. +25 −0 test/match.test.js
  3. +10 −0 test/match/test.js
View
@@ -67,6 +67,12 @@ var testcount = 0;
var only = [];
/**
+ * Regex expression filtering tests to run.
+ */
+
+var match = '';
+
+/**
* Boring output.
*/
@@ -123,6 +129,7 @@ var usage = ''
+ '\n -t, --timeout MS Timeout in milliseconds, defaults to 2000'
+ '\n -r, --require PATH Require the given module path'
+ '\n -o, --only TESTS Execute only the comma sperated TESTS (can be set several times)'
+ + '\n -m, --match EXP Execute only tests matching a given regular expression (can be set several times)'
+ '\n -I, --include PATH Unshift the given path to require.paths'
+ '\n -p, --port NUM Port number for test servers, starts at 5555'
+ '\n -s, --serial Execute tests serially'
@@ -166,6 +173,14 @@ while (args.length) {
throw new Error('--only requires comma-separated test names');
}
break;
+ case '-m':
+ case '--match':
+ if (arg = args.shift()) {
+ match += (match.length > 0 ? '|' : '') + arg;
+ } else {
+ throw new Error('--match requires argument');
+ }
+ break;
case '-p':
case '--port':
if (arg = args.shift()) {
@@ -828,7 +843,10 @@ function runSuite(title, tests, callback) {
var keys = only.length
? only.slice(0)
: Object.keys(tests);
-
+
+ // Regular expression test filter
+ var filter = new RegExp('(?:' + (match.length == 0 ? '.' : match) + ')');
+
// Setup
var setup = tests.setup || function(fn, assert) { fn(); };
var teardown = tests.teardown || function(fn, assert) { fn(); };
@@ -840,6 +858,10 @@ function runSuite(title, tests, callback) {
if (keys.length) {
var key,
fn = tests[key = keys.shift()];
+
+ // Filter
+ if (filter.test(key) === false) return next();
+
// Non-tests
if (key === 'setup' || key === 'teardown') return next();
View
@@ -0,0 +1,25 @@
+var assert = require('assert');
+var spawn = require('child_process').spawn;
+
+module.exports = {
+ 'will run only matched tests': function() {
+ var proc = spawn('bin/expresso', ['-m', 'p..s', 'test/match/test.js']);
+ proc.on('exit', function(code) {
+ completed = true;
+ assert.equal(0, code, 'failing test was not filtered out');
+ });
+ setTimeout(function() {
+ proc.kill('SIGINT');
+ }, 1000);
+ },
+ 'will run tests matched in a subsequent expression': function() {
+ var proc = spawn('bin/expresso', ['-m', 'nothing', '--match', 'p..s', 'test/match/test.js']);
+ proc.on('exit', function(code) {
+ completed = true;
+ assert.equal(0, code, 'failing test was not filtered out');
+ });
+ setTimeout(function() {
+ proc.kill('SIGINT');
+ }, 1000);
+ },
+};
View
@@ -0,0 +1,10 @@
+var assert = require('assert');
+
+module.exports = {
+ 'this test will pass': function() {
+ assert.ok(true);
+ },
+ 'this test will fail': function() {
+ assert.ok(false);
+ },
+}

0 comments on commit e38a86a

Please sign in to comment.