From f0f44f69a6533de2d8c97f0998699ea7cc5ee338 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 30 May 2018 11:18:43 +0200 Subject: [PATCH] test: check TTY mode reset on exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before PR 20592, closing all handles associated with the main event loop would also mean that `uv_tty_reset_mode()` can’t function properly because the corresponding FDs have already been closed. Add regression tests for this condition. Refs: https://github.com/nodejs/node/issues/21020 Refs: https://github.com/nodejs/node/pull/20592 PR-URL: https://github.com/nodejs/node/pull/21027 Reviewed-By: Anatoli Papirovski Reviewed-By: James M Snell --- .../test-set-raw-mode-reset-process-exit.js | 18 ++++++++++++++ .../test-set-raw-mode-reset-process-exit.out | 0 .../test-set-raw-mode-reset-signal.js | 24 +++++++++++++++++++ .../test-set-raw-mode-reset-signal.out | 0 test/pseudo-tty/test-set-raw-mode-reset.js | 19 +++++++++++++++ test/pseudo-tty/test-set-raw-mode-reset.out | 0 6 files changed, 61 insertions(+) create mode 100644 test/pseudo-tty/test-set-raw-mode-reset-process-exit.js create mode 100644 test/pseudo-tty/test-set-raw-mode-reset-process-exit.out create mode 100644 test/pseudo-tty/test-set-raw-mode-reset-signal.js create mode 100644 test/pseudo-tty/test-set-raw-mode-reset-signal.out create mode 100644 test/pseudo-tty/test-set-raw-mode-reset.js create mode 100644 test/pseudo-tty/test-set-raw-mode-reset.out diff --git a/test/pseudo-tty/test-set-raw-mode-reset-process-exit.js b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.js new file mode 100644 index 00000000000000..b6857eaebbdf60 --- /dev/null +++ b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.js @@ -0,0 +1,18 @@ +'use strict'; +require('../common'); +const child_process = require('child_process'); + +// Tests that exiting through process.exit() resets the TTY mode. + +child_process.spawnSync(process.execPath, [ + '-e', 'process.stdin.setRawMode(true); process.exit(0)' +], { stdio: 'inherit' }); + +const { stdout } = child_process.spawnSync('stty', { + stdio: ['inherit', 'pipe', 'inherit'], + encoding: 'utf8' +}); + +if (stdout.match(/-echo\b/)) { + console.log(stdout); +} diff --git a/test/pseudo-tty/test-set-raw-mode-reset-process-exit.out b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/pseudo-tty/test-set-raw-mode-reset-signal.js b/test/pseudo-tty/test-set-raw-mode-reset-signal.js new file mode 100644 index 00000000000000..f953a01331c050 --- /dev/null +++ b/test/pseudo-tty/test-set-raw-mode-reset-signal.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +const child_process = require('child_process'); + +// Tests that exiting through a catchable signal resets the TTY mode. + +const proc = child_process.spawn(process.execPath, [ + '-e', 'process.stdin.setRawMode(true); console.log("Y"); while(true) {}' +], { stdio: ['inherit', 'pipe', 'inherit'] }); + +proc.stdout.on('data', common.mustCall(() => { + proc.kill('SIGINT'); +})); + +proc.on('exit', common.mustCall(() => { + const { stdout } = child_process.spawnSync('stty', { + stdio: ['inherit', 'pipe', 'inherit'], + encoding: 'utf8' + }); + + if (stdout.match(/-echo\b/)) { + console.log(stdout); + } +})); diff --git a/test/pseudo-tty/test-set-raw-mode-reset-signal.out b/test/pseudo-tty/test-set-raw-mode-reset-signal.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/pseudo-tty/test-set-raw-mode-reset.js b/test/pseudo-tty/test-set-raw-mode-reset.js new file mode 100644 index 00000000000000..ab8f1125bfc602 --- /dev/null +++ b/test/pseudo-tty/test-set-raw-mode-reset.js @@ -0,0 +1,19 @@ +'use strict'; +require('../common'); +const child_process = require('child_process'); + +// Tests that exiting through normal means resets the TTY mode. +// Refs: https://github.com/nodejs/node/issues/21020 + +child_process.spawnSync(process.execPath, [ + '-e', 'process.stdin.setRawMode(true)' +], { stdio: 'inherit' }); + +const { stdout } = child_process.spawnSync('stty', { + stdio: ['inherit', 'pipe', 'inherit'], + encoding: 'utf8' +}); + +if (stdout.match(/-echo\b/)) { + console.log(stdout); +} diff --git a/test/pseudo-tty/test-set-raw-mode-reset.out b/test/pseudo-tty/test-set-raw-mode-reset.out new file mode 100644 index 00000000000000..e69de29bb2d1d6