Skip to content

Commit

Permalink
test: check TTY mode reset on exit
Browse files Browse the repository at this point in the history
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: nodejs#21020
Refs: nodejs#20592
  • Loading branch information
addaleax committed May 31, 2018
1 parent c2c9c0c commit 40823a1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/pseudo-tty/test-set-raw-mode-reset-process-exit.js
Original file line number Diff line number Diff line change
@@ -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);
}
Empty file.
24 changes: 24 additions & 0 deletions test/pseudo-tty/test-set-raw-mode-reset-signal.js
Original file line number Diff line number Diff line change
@@ -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);
}
}));
Empty file.
19 changes: 19 additions & 0 deletions test/pseudo-tty/test-set-raw-mode-reset.js
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions test/pseudo-tty/test-set-raw-mode-reset.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 40823a1

Please sign in to comment.