2017-04-11 16:29:39 -06:00
|
|
|
'use strict';
|
2017-12-11 03:56:41 -02:00
|
|
|
// Flags: --expose-internals
|
|
|
|
|
2017-04-11 16:29:39 -06:00
|
|
|
const common = require('../common');
|
|
|
|
const fs = require('fs');
|
|
|
|
const tty = require('tty');
|
2017-12-11 03:56:41 -02:00
|
|
|
const { SystemError } = require('internal/errors');
|
2017-04-11 16:29:39 -06:00
|
|
|
|
2017-10-27 17:20:54 -07:00
|
|
|
common.expectsError(
|
|
|
|
() => new tty.WriteStream(-1),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_FD',
|
|
|
|
type: RangeError,
|
|
|
|
message: '"fd" must be a positive integer: -1'
|
|
|
|
}
|
2017-05-26 08:55:18 -04:00
|
|
|
);
|
2017-04-11 16:29:39 -06:00
|
|
|
|
2017-10-27 17:20:54 -07:00
|
|
|
{
|
|
|
|
const message = common.isWindows ?
|
|
|
|
'bad file descriptor: EBADF [uv_tty_init]' :
|
|
|
|
'invalid argument: EINVAL [uv_tty_init]';
|
2017-04-11 16:29:39 -06:00
|
|
|
|
2017-10-27 17:20:54 -07:00
|
|
|
common.expectsError(
|
|
|
|
() => {
|
|
|
|
let fd = 2;
|
|
|
|
// Get first known bad file descriptor.
|
|
|
|
try {
|
|
|
|
while (fs.fstatSync(++fd));
|
|
|
|
} catch (e) { }
|
|
|
|
new tty.WriteStream(fd);
|
|
|
|
}, {
|
|
|
|
code: 'ERR_SYSTEM_ERROR',
|
2017-12-11 03:56:41 -02:00
|
|
|
type: SystemError,
|
2017-10-27 17:20:54 -07:00
|
|
|
message
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
common.expectsError(
|
|
|
|
() => {
|
|
|
|
let fd = 2;
|
|
|
|
// Get first known bad file descriptor.
|
|
|
|
try {
|
|
|
|
while (fs.fstatSync(++fd));
|
|
|
|
} catch (e) { }
|
|
|
|
new tty.ReadStream(fd);
|
|
|
|
}, {
|
|
|
|
code: 'ERR_SYSTEM_ERROR',
|
2017-12-11 03:56:41 -02:00
|
|
|
type: SystemError,
|
2017-10-27 17:20:54 -07:00
|
|
|
message
|
|
|
|
});
|
|
|
|
}
|
2017-04-11 16:29:39 -06:00
|
|
|
|
2017-10-27 17:20:54 -07:00
|
|
|
common.expectsError(
|
|
|
|
() => new tty.ReadStream(-1),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_FD',
|
|
|
|
type: RangeError,
|
|
|
|
message: '"fd" must be a positive integer: -1'
|
|
|
|
}
|
|
|
|
);
|