forked from laverdet/node-fibers
/
test.js
executable file
·49 lines (45 loc) · 1.02 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
var fs = require('fs');
var spawn = require('child_process').spawn;
var path = require('path');
function runTest(test, cb) {
var proc = spawn(process.execPath, [path.join('test', test)], {env: {NODE_PATH: __dirname}});
proc.stdout.setEncoding('utf8');
proc.stderr.setEncoding('utf8');
var stdout = '', stderr = '';
proc.stdout.on('data', function(data) {
stdout += data;
});
proc.stderr.on('data', function(data) {
stderr += data;
});
proc.stdin.end();
proc.on('exit', function(code) {
if (stdout !== 'pass\n' || stderr !== '') {
console.error(
'test: *fail*\n'+
'code: '+ code+ '\n'+
'stderr: '+ stderr+ '\n'+
'stdout: '+ stdout
);
} else {
console.log(test+ ': '+ 'pass');
}
cb();
});
}
var cb = function(err) {
if (err) {
console.error(String(err));
process.exit(1);
}
};
fs.readdirSync('./test').reverse().forEach(function(file) {
cb = new function(cb, file) {
return function(err) {
if (err) return cb(err);
runTest(file, cb);
};
}(cb, file);
});
cb();