aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-05-30 11:18:43 +0200
committerAnna Henningsen <anna@addaleax.net>2018-06-01 10:52:06 +0200
commit7c8eec0648d1d53dd8ade9d69c4dbbbf2d025a8f (patch)
tree94dcd91a5aacebda7192d24781d377f0aba1dd63
parent48a2568f411cf09999b7e82992d15142ce9a45b0 (diff)
downloadandroid-node-v8-7c8eec0648d1d53dd8ade9d69c4dbbbf2d025a8f.tar.gz
android-node-v8-7c8eec0648d1d53dd8ade9d69c4dbbbf2d025a8f.tar.bz2
android-node-v8-7c8eec0648d1d53dd8ade9d69c4dbbbf2d025a8f.zip
test: check TTY mode reset on exit
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 <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--test/pseudo-tty/test-set-raw-mode-reset-process-exit.js18
-rw-r--r--test/pseudo-tty/test-set-raw-mode-reset-process-exit.out0
-rw-r--r--test/pseudo-tty/test-set-raw-mode-reset-signal.js24
-rw-r--r--test/pseudo-tty/test-set-raw-mode-reset-signal.out0
-rw-r--r--test/pseudo-tty/test-set-raw-mode-reset.js19
-rw-r--r--test/pseudo-tty/test-set-raw-mode-reset.out0
6 files changed, 61 insertions, 0 deletions
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 0000000000..b6857eaebb
--- /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 0000000000..e69de29bb2
--- /dev/null
+++ b/test/pseudo-tty/test-set-raw-mode-reset-process-exit.out
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 0000000000..f953a01331
--- /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 0000000000..e69de29bb2
--- /dev/null
+++ b/test/pseudo-tty/test-set-raw-mode-reset-signal.out
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 0000000000..ab8f1125bf
--- /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 0000000000..e69de29bb2
--- /dev/null
+++ b/test/pseudo-tty/test-set-raw-mode-reset.out