|
| 1 | +#!/usr/bin/env node |
| 2 | +/* |
| 3 | + run.js: test runner for core tests |
| 4 | +
|
| 5 | + Copyright (c) 2011 Nodejitsu |
| 6 | +
|
| 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: |
| 14 | +
|
| 15 | + The above copyright notice and this permission notice shall be |
| 16 | + included in all copies or substantial portions of the Software. |
| 17 | +
|
| 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. |
| 25 | +
|
| 26 | +*/ |
| 27 | + |
| 28 | +var path = require('path'), |
| 29 | + spawn = require('child_process').spawn, |
| 30 | + async = require('async'), |
| 31 | + colors = require('colors'); |
| 32 | + |
| 33 | +var testTimeout = 15000; |
| 34 | +var results = {}; |
| 35 | + |
| 36 | +function runTest(test, callback) { |
| 37 | + var child = spawn(path.join(__dirname, 'run-single'), [ test ]); |
| 38 | + |
| 39 | + var killTimeout = setTimeout(function () { |
| 40 | + child.kill(); |
| 41 | + console.log(test.yellow + ' timed out'.red); |
| 42 | + }, testTimeout); |
| 43 | + |
| 44 | + child.on('exit', function (exitCode) { |
| 45 | + clearTimeout(killTimeout); |
| 46 | + |
| 47 | + console.log(test.yellow + ' exited with ' + |
| 48 | + ((exitCode) ? exitCode.toString().red : exitCode.toString().green)); |
| 49 | + results[test] = { exitCode: exitCode }; |
| 50 | + callback(); |
| 51 | + // |
| 52 | + // We don't want tests to be stopped after first failure, and that's what |
| 53 | + // async does when it receives truthy value in callback. |
| 54 | + // |
| 55 | + }); |
| 56 | +}; |
| 57 | + |
| 58 | +var tests = process.argv.slice(2); |
| 59 | +async.forEachSeries(tests, runTest, function () { |
| 60 | + var failed = [], ok = []; |
| 61 | + for (var test in results) { |
| 62 | + (results[test].exitCode != 0 ? failed : ok).push(test); |
| 63 | + } |
| 64 | + |
| 65 | + console.log('\nSummary:'); |
| 66 | + console.log((' ' + failed.length + '\tfailed tests').red); |
| 67 | + console.log((' ' + ok.length + '\tpassed tests').green); |
| 68 | +}); |
| 69 | + |
| 70 | +// vim:filetype=javascript |
| 71 | + |
0 commit comments