forked from ajlopez/CobolScript
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
54 lines (47 loc) · 1.27 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
50
51
52
53
54
#!/usr/bin/env node
// Based on https://github.com/laverdet/node-fibers/blob/master/test.js
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' && stdout !== '') || stderr !== '') {
return cb(new Error(
'Test `'+ test+ '` failed.\n'+
'code: '+ code+ '\n'+
'stderr: '+ stderr+ '\n'+
'stdout: '+ stdout));
}
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) {
var stats = fs.lstatSync(path.join('./test',file));
if (!stats.isFile())
return;
cb = new function(cb, file) {
return function(err) {
if (err) return cb(err);
runTest(file, cb);
};
}(cb, file);
});
cb();