1// Flags: --expose-internals 2'use strict'; 3 4const common = require('../common'); 5const tty = require('tty'); 6const { internalBinding } = require('internal/test/binding'); 7const { 8 UV_EBADF, 9 UV_EINVAL 10} = internalBinding('uv'); 11const assert = require('assert'); 12 13assert.throws( 14 () => new tty.WriteStream(-1), 15 { 16 code: 'ERR_INVALID_FD', 17 name: 'RangeError', 18 message: '"fd" must be a positive integer: -1' 19 } 20); 21 22{ 23 const info = { 24 code: common.isWindows ? 'EBADF' : 'EINVAL', 25 message: common.isWindows ? 'bad file descriptor' : 'invalid argument', 26 errno: common.isWindows ? UV_EBADF : UV_EINVAL, 27 syscall: 'uv_tty_init' 28 }; 29 30 const suffix = common.isWindows ? 31 'EBADF (bad file descriptor)' : 'EINVAL (invalid argument)'; 32 const message = `TTY initialization failed: uv_tty_init returned ${suffix}`; 33 34 assert.throws( 35 () => { 36 common.runWithInvalidFD((fd) => { 37 new tty.WriteStream(fd); 38 }); 39 }, { 40 code: 'ERR_TTY_INIT_FAILED', 41 name: 'SystemError', 42 message, 43 info 44 } 45 ); 46 47 assert.throws( 48 () => { 49 common.runWithInvalidFD((fd) => { 50 new tty.ReadStream(fd); 51 }); 52 }, { 53 code: 'ERR_TTY_INIT_FAILED', 54 name: 'SystemError', 55 message, 56 info 57 }); 58} 59 60assert.throws( 61 () => new tty.ReadStream(-1), 62 { 63 code: 'ERR_INVALID_FD', 64 name: 'RangeError', 65 message: '"fd" must be a positive integer: -1' 66 } 67); 68