-
Notifications
You must be signed in to change notification settings - Fork 154
/
test.js
78 lines (72 loc) · 1.7 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
let fs = require('fs');
let spawn = require('child_process').spawn;
let path = require('path');
let ret = 0;
let passCount = 0, failCount = 0;
function runTest(test, cb) {
// Copy env variables
let env = {};
for (let ii in process.env) {
env[ii] = process.env[ii];
}
env.NODE_PATH = __dirname;
// Get extra args
let args = [ '--no-node-snapshot' ];
let testPath = path.join('tests', test);
let content = fs.readFileSync(testPath, 'utf8');
let match = /node-args: *(.+)/.exec(content);
if (match) {
args.push(...match[1].split(/ /g));
}
args.push(testPath);
// Launch process
let proc = spawn(process.execPath, args, { env });
proc.stdout.setEncoding('utf8');
proc.stderr.setEncoding('utf8');
let stdout = '', stderr = '';
proc.stdout.on('data', function(data) {
stdout += data;
});
proc.stderr.on('data', function(data) {
stderr += data;
});
proc.stdin.end();
// Wait for completion
process.stderr.write(`${test}: `);
proc.on('exit', function(code, signal) {
if (stdout !== 'pass\n' || stderr !== '') {
++failCount;
ret = 1;
console.error(
`*fail*\n`+
`code: ${code} signal: ${signal}\n`+
`stderr: ${stderr}\n`+
`stdout: ${stdout}`
);
} else if (code !== 0) {
++failCount;
ret = 1;
console.error(`fail (${code})`);
} else {
++passCount;
console.error(`pass`);
}
cb();
});
}
let cb = function() {
console.log('\nCompleted: '+ passCount+ ' passed, '+ failCount+ ' failed.');
process.exit(ret);
};
fs.readdirSync('./tests').sort().reverse().forEach(function(file) {
if (/\.js$/.test(file)) {
cb = new function(cb) {
return function(err) {
if (err) return cb(err);
runTest(file, cb);
};
}(cb);
}
});
cb();