3 run.js: test runner for core tests
5 Copyright (c) 2011 Nodejitsu
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 var fs = require('fs'),
29 path = require('path'),
30 spawn = require('child_process').spawn,
31 async = require('async'),
32 colors = require('colors'),
33 optimist = require('optimist');
35 optimist.argv.color && (colors.mode = optimist.argv.color);
37 var testTimeout = 15000;
40 function runTest(test, callback) {
41 var child = spawn(path.join(__dirname, 'run-single'), [ test ]);
43 var killTimeout = setTimeout(function () {
45 console.log(' ' + path.basename(test).yellow + ' timed out'.red);
48 child.on('exit', function (exitCode) {
49 clearTimeout(killTimeout);
51 console.log(' ' + ((exitCode) ? '✘'.red : '✔'.green) + ' ' +
53 (exitCode ? (' (exit code: ' + exitCode + ')') : ''));
54 results[test] = { exitCode: exitCode };
57 // We don't want tests to be stopped after first failure, and that's what
58 // async does when it receives truthy value in callback.
63 var tests = process.argv.slice(2).filter(function (test) {
64 return test.substr(0, 2) != '--';
68 var pathPrefix = path.join(__dirname, 'simple');
69 tests = fs.readdirSync(pathPrefix).map(function (test) {
70 return path.join(pathPrefix, test);
73 // We only run simple tests by default.
77 console.log('Running tests:'.bold);
78 async.forEachSeries(tests, runTest, function () {
79 var failed = [], ok = [];
80 for (var test in results) {
81 (results[test].exitCode != 0 ? failed : ok).push(test);
84 console.log('\nSummary:'.bold);
85 console.log((' ' + ok.length + '\tpassed tests').green);
86 console.log((' ' + failed.length + '\tfailed tests').red);
89 // vim:filetype=javascript