Skip to content

Commit 8a0c5ad

Browse files
committed
Don't use process.fork since node runner may target node with different command line
1 parent 961b348 commit 8a0c5ad

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

lib/runner.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,27 @@ var errorLogRe = /^test262\/error (.*)$/;
7979
// errorMessage: message from error thrown (used for debugging purposes)
8080
// errorStack: stack trace of error thrown (used for debugging purposes)
8181
Runner.prototype.validateResult = function(test, result) {
82+
var expectingStack = false;
8283
var isNegative = test.attrs.flags.negative || test.attrs.negative;
8384
// parse result from log
8485
(result.log || []).forEach(function(log) {
8586
var errorMatch = log.match(errorLogRe);
8687
if(errorMatch) {
8788
result.errorString = errorMatch[1];
89+
expectingStack = true;
8890
return;
8991
}
9092

93+
if(expectingStack) {
94+
if(log.match(/^\s+at/)) {
95+
result.errorStack = result.errorStack || result.errorString + "\n";
96+
result.errorStack += log + "\n";
97+
return;
98+
} else {
99+
expectingStack = false;
100+
}
101+
}
102+
91103
if(log === "test262/done") {
92104
result.doneCalled = true;
93105
}

lib/runners/node.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
11
var Runner = require('../runner');
22
var ConsoleRunner = require('./console');
33
var cp = require('child_process');
4+
var _ = require('highland');
45

56
module.exports = NodeRunner;
67

78
function NodeRunner(args) {
8-
args.consoleCommand = 'dummy';
9+
args.consoleCommand = args.consoleCommand || "node.exe";
910
var runner = this;
11+
1012
ConsoleRunner.apply(this, arguments);
13+
1114
this.deps = []; // all env deps provided by nodehost.js
1215

13-
this._instance = cp.fork(__dirname + '/nodehost.js')
14-
this._instance.on('message', function(result) {
15-
runner.validateResult(runner._test, result)
16-
runner._testDone();
16+
this._instance = cp.spawn(args.consoleCommand, [__dirname + '/nodehost.js']);
17+
18+
19+
var results = { log: [] };
20+
21+
_(this._instance.stdout).flatMap(function(data) {
22+
return _(data.toString().split(/\r?\n/g));
23+
}).each(function(line) {
24+
results.log.push(line);
25+
switch(line) {
26+
case 'test262/done':
27+
runner.validateResult(runner._test, results);
28+
results = { log: [] };
29+
30+
runner._testDone();
31+
break;
32+
}
1733
})
1834
}
1935
NodeRunner.prototype = Object.create(ConsoleRunner.prototype);
2036
NodeRunner.prototype.execute = function(test, cb) {
2137
this._test = test;
2238
this._testDone = cb;
23-
this._instance.send(test.contents);
39+
this._instance.stdin.write(test.contents);
2440
}
2541

2642
NodeRunner.prototype.end = function() {
27-
this._instance.disconnect();
43+
this._instance.stdin.end();
2844
}

lib/runners/nodehost.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var vm = require('vm');
22

3-
process.on('message', function(test) {
3+
process.stdin.resume();
4+
process.stdin.on('data', function(test) {
45
var result = { log: [] }
56
var error;
67
var context = {
@@ -11,25 +12,27 @@ process.on('message', function(test) {
1112
if(err) context.$ERROR(err);
1213
if(error) {
1314
if(typeof error === 'object') {
14-
// custom thrown errors won't have a name property.
15-
result.errorName = error.name || "Test262Error";
16-
result.errorMessage = error.message;
17-
result.errorStack = error.stack
15+
if(error.hasOwnProperty('stack')) {
16+
console.log("test262/error " + error.stack);
17+
} else {
18+
console.log("test262/error " + (error.name || Test262Error) + ": " + error.message);
19+
}
1820
} else {
19-
result.errorName = error;
21+
console.log('test262/error Error: ' + error);
2022
}
2123
}
22-
result.doneCalled = true;
23-
process.send(result);
24+
console.log('test262/done');
2425
},
2526
$LOG: function(log) {
26-
result.log.push(log);
27-
}
27+
console.log(log);
28+
},
29+
require: require,
30+
console: console
2831
}
2932

3033
try {
3134
vm.runInNewContext(test, context);
3235
} catch(e) {
3336
context.$DONE(e);
3437
}
35-
})
38+
});

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "test262-harness",
33
"repository": "bterlson/test262-harness",
4-
"version": "1.1.2",
4+
"version": "1.1.4",
55
"description": "Node-based harness for test262",
66
"main": "index.js",
77
"bin": {
@@ -19,5 +19,11 @@
1919
"through": "~2.3.4"
2020
},
2121
"author": "Brian Terlson",
22-
"license": "BSD"
22+
"license": "BSD",
23+
"files": [
24+
"index.js",
25+
"bin",
26+
"lib",
27+
"test"
28+
]
2329
}

0 commit comments

Comments
 (0)