Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / http-proxy / test / core / run
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 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');
34
35 optimist.argv.color && (colors.mode = optimist.argv.color);
36
37 var testTimeout = 15000;
38 var results = {};
39
40 function runTest(test, callback) {
41   var child = spawn(path.join(__dirname, 'run-single'), [ test ]);
42
43   var killTimeout = setTimeout(function () {
44     child.kill();
45     console.log('  ' + path.basename(test).yellow + ' timed out'.red);
46   }, testTimeout);
47
48   child.on('exit', function (exitCode) {
49     clearTimeout(killTimeout);
50
51     console.log('  ' + ((exitCode) ? '✘'.red : '✔'.green) + ' ' +
52                 path.basename(test) +
53                 (exitCode ? (' (exit code: ' + exitCode + ')') : ''));
54     results[test] = { exitCode: exitCode };
55     callback();
56     //
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.
59     //
60   });
61 };
62
63 var tests = process.argv.slice(2).filter(function (test) {
64   return test.substr(0, 2) != '--';
65 });
66
67 if (!tests.length) {
68   var pathPrefix = path.join(__dirname, 'simple');
69   tests = fs.readdirSync(pathPrefix).map(function (test) {
70     return path.join(pathPrefix, test);
71   });
72   //
73   // We only run simple tests by default.
74   //
75 }
76
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);
82   }
83
84   console.log('\nSummary:'.bold);
85   console.log(('  ' + ok.length + '\tpassed tests').green);
86   console.log(('  ' + failed.length + '\tfailed tests').red);
87 });
88
89 // vim:filetype=javascript
90