Skip to content

Commit c1bb886

Browse files
orangemochatjfontaine
authored andcommitted
test: remove invalid part of stream2-stderr-sync
One test case in test-stream2-stderr-sync.js was creating a TTY object using an undocumented constructor and passing in fd 2. However, this is running in a child process and fd 2 is actually a pipe, not a TTY. The constructor fails on Windows and causes the handle type to be left uninitialized, which later causes an assert to fail. On Unix, the constructor fails to retrieve the windows size but unlike on Windows, it just leaves the size fields undefined and continues with initializing the stream type, yielding a semi-usable object. I could make the Windows version match Unix behavior, but it seems to me that the test is relying on an implementation detail of an undocumented API, and the Unix behavior is not necessarily more correct than the Windows one. Thus it makes more sense to remove this test.
1 parent a22a2d8 commit c1bb886

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

test/simple/test-stream2-stderr-sync.js

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,82 +48,42 @@ function parent() {
4848
});
4949
}
5050

51-
function child0() {
52-
// Just a very simple wrapper around TTY(2)
53-
// Essentially the same as stderr, but without all the net stuff.
54-
var Writable = require('stream').Writable;
55-
var util = require('util');
56-
57-
// a lowlevel stderr writer
58-
var TTY = process.binding('tty_wrap').TTY;
59-
var handle = new TTY(2, false);
60-
61-
util.inherits(W, Writable);
62-
63-
function W(opts) {
64-
Writable.call(this, opts);
65-
}
66-
67-
W.prototype._write = function(chunk, encoding, cb) {
68-
var req = { oncomplete: afterWrite };
69-
var err = handle.writeUtf8String(req, chunk.toString() + '\n');
70-
if (err) throw errnoException(err, 'write');
71-
// here's the problem.
72-
// it needs to tell the Writable machinery that it's ok to write
73-
// more, but that the current buffer length is handle.writeQueueSize
74-
if (req.writeQueueSize === 0)
75-
req.cb = cb;
76-
else
77-
cb();
78-
}
79-
function afterWrite(status, handle, req) {
80-
if (req.cb)
81-
req.cb();
82-
}
83-
84-
var w = new W
85-
w.write('child 0');
86-
w.write('foo');
87-
w.write('bar');
88-
w.write('baz');
89-
}
90-
9151
// using console.error
92-
function child1() {
93-
console.error('child 1');
52+
function child0() {
53+
console.error('child 0');
9454
console.error('foo');
9555
console.error('bar');
9656
console.error('baz');
9757
}
9858

9959
// using process.stderr
100-
function child2() {
101-
process.stderr.write('child 2\n');
60+
function child1() {
61+
process.stderr.write('child 1\n');
10262
process.stderr.write('foo\n');
10363
process.stderr.write('bar\n');
10464
process.stderr.write('baz\n');
10565
}
10666

10767
// using a net socket
108-
function child3() {
68+
function child2() {
10969
var net = require('net');
11070
var socket = new net.Socket({ fd: 2 });
111-
socket.write('child 3\n');
71+
socket.write('child 2\n');
11272
socket.write('foo\n');
11373
socket.write('bar\n');
11474
socket.write('baz\n');
11575
}
11676

11777

118-
function child4() {
119-
console.error('child 4\nfoo\nbar\nbaz');
78+
function child3() {
79+
console.error('child 3\nfoo\nbar\nbaz');
12080
}
12181

122-
function child5() {
123-
process.stderr.write('child 5\nfoo\nbar\nbaz\n');
82+
function child4() {
83+
process.stderr.write('child 4\nfoo\nbar\nbaz\n');
12484
}
12585

126-
var children = [ child0, child1, child2, child3, child4, child5 ];
86+
var children = [ child0, child1, child2, child3, child4 ];
12787

12888
if (!process.argv[2]) {
12989
parent();

0 commit comments

Comments
 (0)