Skip to content

Commit

Permalink
test: add test case for fs.ftruncate
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-yu committed Apr 10, 2018
1 parent 4523d85 commit 0ba1b37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function validateLen(len) {
err = new ERR_OUT_OF_RANGE('len', 'an integer', len);
} else {
// 2 ** 31 === 2147483648
err = new ERR_OUT_OF_RANGE('len', '>= -2147483648 && < 2147483648', len);
err = new ERR_OUT_OF_RANGE('len', '> -2147483649 && < 2147483648', len);
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-fs-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ function testFtruncate(cb) {
);
});

// 2 ** 31 = 2147483648
[2147483648, -2147483649].forEach((input) => {
assert.throws(
() => fs.ftruncate(fd, input),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
message: 'The value of "len" is out of range. It must be ' +
`> -2147483649 && < 2147483648. Received ${input}`
}
);
});

fs.ftruncate(fd, undefined, common.mustCall(function(err) {
assert.ifError(err);
assert(fs.readFileSync(file5).equals(Buffer.from('')));
Expand Down

0 comments on commit 0ba1b37

Please sign in to comment.