Skip to content

Commit

Permalink
added test/all.js -- a program which runs all tests in order and sequ…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
rsms committed Jul 21, 2010
1 parent c6ef3e6 commit c04cb85
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/all.js
@@ -0,0 +1,56 @@
var sys = require('sys'),
fs = require('fs'),
spawn = require('child_process').spawn;

process.chdir(__dirname);

var stopOnFailure = true; // set to true to abort on first failure
var failcount = 0, runcount = 0;
var stderrWrite = process.binding('stdio').writeError;
var files = fs.readdirSync('.').filter(function(fn){
return fn.match(/^test-.+\.js$/)
}).sort();
var totalcount = files.length;

function done() {
sys.puts('>>> ran '+runcount+' of '+totalcount+' tests with '+
failcount+' failure(s)');
process.exit(failcount ? 1 : 0);
}

var stdoutSkipRe = /Unable to save file: (metadata|playlist)\.bnk/;

function runNext() {
fn = files.shift();
if (!fn || (stopOnFailure && failcount)) return done();
console.log('>>> run '+fn);
var nodebin = process.argv[0];
var args = [fn];
var child = spawn(nodebin, args);
child.stdin.end();
child.stdout.on('data', function (data){
if (!stdoutSkipRe.test(data))
process.stdout.write(data);
});
child.stderr.on('data', function (data) {
if (/^execvp\(\)/.test(data.asciiSlice(0,data.length))) {
console.error('>>> fail '+fn+' -- execvp('+sys.inspect(nodebin)+
', '+sys.inspect(args)+') failed: '+data);
} else {
stderrWrite(data);
}
});
child.on('exit', function (code) {
if (code !== 0) {
console.log('>>> fail '+fn+' -- status '+code);
failcount++;
} else {
console.log('>>> ok '+fn);
}
runcount++;
runNext();
});
}

console.log('>>> running '+files.length+' tests');
runNext();

0 comments on commit c04cb85

Please sign in to comment.