Skip to content

Commit

Permalink
update fs read tests cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bacriom committed Jan 17, 2018
1 parent 14e1660 commit f4e9a87
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 77 deletions.
40 changes: 0 additions & 40 deletions test/parallel/test-fs-read-parameters-errors.js

This file was deleted.

37 changes: 0 additions & 37 deletions test/parallel/test-fs-read-sync-parameters-errors.js

This file was deleted.

63 changes: 63 additions & 0 deletions test/parallel/test-fs-read-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const filepath = fixtures.path('x.txt');
const fd = fs.openSync(filepath, 'r');
const expected = 'xyz\n';


// Error must be thrown with string
common.expectsError(
() => fs.read(fd, expected.length, 0, 'utf-8', common.mustNotCall()),
Expand All @@ -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(
() => fs.readSync(fd, expected.length, 0, 'utf-8'),
{
Expand All @@ -25,3 +59,32 @@ common.expectsError(
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.' });

0 comments on commit f4e9a87

Please sign in to comment.