test: check fs.read and fs.readsync input
Added tests to extend the code coverage. PR-URL: https://github.com/nodejs/node/pull/17910 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
93f1d9e10b
commit
080a72c349
@ -7,6 +7,7 @@ const filepath = fixtures.path('x.txt');
|
|||||||
const fd = fs.openSync(filepath, 'r');
|
const fd = fs.openSync(filepath, 'r');
|
||||||
const expected = 'xyz\n';
|
const expected = 'xyz\n';
|
||||||
|
|
||||||
|
|
||||||
// Error must be thrown with string
|
// Error must be thrown with string
|
||||||
common.expectsError(
|
common.expectsError(
|
||||||
() => fs.read(fd, expected.length, 0, 'utf-8', common.mustNotCall()),
|
() => fs.read(fd, expected.length, 0, 'utf-8', common.mustNotCall()),
|
||||||
@ -17,6 +18,39 @@ common.expectsError(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
[true, null, undefined, () => {}, {}].forEach((value) => {
|
||||||
|
common.expectsError(() => {
|
||||||
|
fs.read(value,
|
||||||
|
Buffer.allocUnsafe(expected.length),
|
||||||
|
0,
|
||||||
|
expected.length,
|
||||||
|
0,
|
||||||
|
common.mustNotCall());
|
||||||
|
}, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError,
|
||||||
|
message: 'The "fd" argument must be of type integer' });
|
||||||
|
});
|
||||||
|
|
||||||
|
common.expectsError(() => {
|
||||||
|
fs.read(fd,
|
||||||
|
Buffer.allocUnsafe(expected.length),
|
||||||
|
-1,
|
||||||
|
expected.length,
|
||||||
|
0,
|
||||||
|
common.mustNotCall());
|
||||||
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
||||||
|
message: 'The value of "offset" is out of range.' });
|
||||||
|
|
||||||
|
common.expectsError(() => {
|
||||||
|
fs.read(fd,
|
||||||
|
Buffer.allocUnsafe(expected.length),
|
||||||
|
0,
|
||||||
|
-1,
|
||||||
|
0,
|
||||||
|
common.mustNotCall());
|
||||||
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
||||||
|
message: 'The value of "length" is out of range.' });
|
||||||
|
|
||||||
|
|
||||||
common.expectsError(
|
common.expectsError(
|
||||||
() => fs.readSync(fd, expected.length, 0, 'utf-8'),
|
() => fs.readSync(fd, expected.length, 0, 'utf-8'),
|
||||||
{
|
{
|
||||||
@ -25,3 +59,32 @@ common.expectsError(
|
|||||||
message: 'The "buffer" argument must be one of type Buffer or Uint8Array'
|
message: 'The "buffer" argument must be one of type Buffer or Uint8Array'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
[true, null, undefined, () => {}, {}].forEach((value) => {
|
||||||
|
common.expectsError(() => {
|
||||||
|
fs.readSync(value,
|
||||||
|
Buffer.allocUnsafe(expected.length),
|
||||||
|
0,
|
||||||
|
expected.length,
|
||||||
|
0);
|
||||||
|
}, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError,
|
||||||
|
message: 'The "fd" argument must be of type integer' });
|
||||||
|
});
|
||||||
|
|
||||||
|
common.expectsError(() => {
|
||||||
|
fs.readSync(fd,
|
||||||
|
Buffer.allocUnsafe(expected.length),
|
||||||
|
-1,
|
||||||
|
expected.length,
|
||||||
|
0);
|
||||||
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
||||||
|
message: 'The value of "offset" is out of range.' });
|
||||||
|
|
||||||
|
common.expectsError(() => {
|
||||||
|
fs.readSync(fd,
|
||||||
|
Buffer.allocUnsafe(expected.length),
|
||||||
|
0,
|
||||||
|
-1,
|
||||||
|
0);
|
||||||
|
}, { code: 'ERR_OUT_OF_RANGE', type: RangeError,
|
||||||
|
message: 'The value of "length" is out of range.' });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user