node/test/parallel/test-fs-read-empty-buffer.js
shisama 097896bafe test: error when empty buffer is passed to fs.read()
Added tests to occur error when empty buffer is passed to fs.read()
to increase coverage.

PR-URL: https://github.com/nodejs/node/pull/23141
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-10-03 08:32:07 +02:00

29 lines
728 B
JavaScript

'use strict';
require('../common');
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const fs = require('fs');
const filepath = fixtures.path('x.txt');
const fd = fs.openSync(filepath, 'r');
const buffer = new Uint8Array();
assert.throws(
() => fs.readSync(fd, buffer, 0, 10, 0),
{
code: 'ERR_INVALID_ARG_VALUE',
message: 'The argument \'buffer\' is empty and cannot be written. ' +
'Received Uint8Array []'
}
);
assert.throws(
() => fs.read(fd, buffer, 0, 1, 0, common.mustNotCall()),
{
code: 'ERR_INVALID_ARG_VALUE',
message: 'The argument \'buffer\' is empty and cannot be written. ' +
'Received Uint8Array []'
}
);