diff options
author | Rich Trott <rtrott@gmail.com> | 2017-12-20 06:19:10 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-12-21 10:11:46 -0800 |
commit | 1af82f3d0e13a175c424017565189fffb2f49e83 (patch) | |
tree | 5d390bf56b8fa3ef59b64fb16772fe925f1a6ccb /test | |
parent | 40bab30067aaa464a03150529f652b853f58b024 (diff) | |
download | node-new-1af82f3d0e13a175c424017565189fffb2f49e83.tar.gz |
test: fix buggy getTTYfd() implementation
PR-URL: https://github.com/nodejs/node/pull/17781
Ref: https://github.com/nodejs/node/pull/17781#discussion_r158030728
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/sequential/test-async-wrap-getasyncid.js | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 2963992c7c..f85861c9d5 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -249,28 +249,25 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check // Do our best to grab a tty fd. function getTTYfd() { const tty = require('tty'); - let tty_fd = 0; - if (!tty.isatty(tty_fd)) tty_fd++; - else if (!tty.isatty(tty_fd)) tty_fd++; - else if (!tty.isatty(tty_fd)) tty_fd++; - else { + let ttyFd = [0, 1, 2].find(tty.isatty); + if (ttyFd === undefined) { try { - tty_fd = fs.openSync('/dev/tty'); + ttyFd = fs.openSync('/dev/tty'); } catch (e) { // There aren't any tty fd's available to use. return -1; } } - return tty_fd; + return ttyFd; } - const tty_fd = getTTYfd(); - if (tty_fd >= 0) { + const ttyFd = getTTYfd(); + if (ttyFd >= 0) { const tty_wrap = process.binding('tty_wrap'); // fd may still be invalid, so guard against it. const handle = (() => { try { - return new tty_wrap.TTY(tty_fd, false); + return new tty_wrap.TTY(ttyFd, false); } catch (e) { return null; } |