test: stdin is not always a net.Socket
authorJeremiah Senkpiel <fishrock123@rocketmail.com>
Mon, 28 Mar 2016 15:24:34 +0000 (11:24 -0400)
committerMyles Borins <mborins@us.ibm.com>
Mon, 11 Apr 2016 15:49:08 +0000 (11:49 -0400)
`<`-ing a file into stdin actually results in a `fs.ReadStream`, rather
than a `tty.ReadStream`, and as such does not inherit from net.Socket,
unlike the other possible stdin options.

Refs: https://github.com/nodejs/node/pull/5916
PR-URL: https://github.com/nodejs/node/pull/5935
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
test/known_issues/test-stdin-is-always-net.socket.js [new file with mode: 0644]

diff --git a/test/known_issues/test-stdin-is-always-net.socket.js b/test/known_issues/test-stdin-is-always-net.socket.js
new file mode 100644 (file)
index 0000000..a0c5c63
--- /dev/null
@@ -0,0 +1,19 @@
+'use strict';
+// Refs: https://github.com/nodejs/node/pull/5916
+
+const common = require('../common');
+const assert = require('assert');
+const spawn = require('child_process').spawn;
+const net = require('net');
+
+if (process.argv[2] === 'child') {
+  assert(process.stdin instanceof net.Socket);
+  return;
+}
+
+const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'ignore' });
+// To double-check this test, set stdio to 'pipe' and uncomment the line below.
+// proc.stderr.pipe(process.stderr);
+proc.on('exit', common.mustCall(function(exitCode) {
+  process.exitCode = exitCode;
+}));