test: improve fs error message test
- Reuse error validators for sync and async tests - Validate properties of the errors PR-URL: https://github.com/nodejs/node/pull/18277 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d09d87821d
commit
63f78f5ddc
@ -24,276 +24,434 @@ const common = require('../common');
|
|||||||
const fixtures = require('../common/fixtures');
|
const fixtures = require('../common/fixtures');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const fn = fixtures.path('non-existent');
|
const nonexistentFile = fixtures.path('non-existent');
|
||||||
const existingFile = fixtures.path('exit.js');
|
const existingFile = fixtures.path('exit.js');
|
||||||
const existingFile2 = fixtures.path('create-file.js');
|
const existingFile2 = fixtures.path('create-file.js');
|
||||||
const existingDir = fixtures.path('empty');
|
const existingDir = fixtures.path('empty');
|
||||||
const existingDir2 = fixtures.path('keys');
|
const existingDir2 = fixtures.path('keys');
|
||||||
const uv = process.binding('uv');
|
const uv = process.binding('uv');
|
||||||
|
|
||||||
// ASYNC_CALL
|
// Template tag function for escaping special characters in strings so that:
|
||||||
|
// new RegExp(re`${str}`).test(str) === true
|
||||||
fs.stat(fn, common.mustCall((err) => {
|
function re(literals, ...values) {
|
||||||
assert.strictEqual(fn, err.path);
|
const escapeRE = /[\\^$.*+?()[\]{}|=!<>:-]/g;
|
||||||
assert.strictEqual(
|
let result = literals[0].replace(escapeRE, '\\$&');
|
||||||
err.message,
|
for (const [i, value] of values.entries()) {
|
||||||
`ENOENT: no such file or directory, stat '${fn}'`);
|
result += value.replace(escapeRE, '\\$&');
|
||||||
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
result += literals[i + 1].replace(escapeRE, '\\$&');
|
||||||
assert.strictEqual(err.code, 'ENOENT');
|
}
|
||||||
assert.strictEqual(err.syscall, 'stat');
|
return result;
|
||||||
}));
|
}
|
||||||
|
|
||||||
fs.lstat(fn, common.mustCall((err) => {
|
|
||||||
assert.strictEqual(fn, err.path);
|
|
||||||
assert.strictEqual(
|
|
||||||
err.message,
|
|
||||||
`ENOENT: no such file or directory, lstat '${fn}'`);
|
|
||||||
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
||||||
assert.strictEqual(err.code, 'ENOENT');
|
|
||||||
assert.strictEqual(err.syscall, 'lstat');
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
// stat
|
||||||
{
|
{
|
||||||
const fd = fs.openSync(existingFile, 'r');
|
const validateError = (err) => {
|
||||||
fs.closeSync(fd);
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
fs.fstat(fd, common.mustCall((err) => {
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, stat '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'stat');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.stat(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.statSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lstat
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, lstat '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'lstat');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.lstat(nonexistentFile, common.mustCall(validateError));
|
||||||
|
assert.throws(
|
||||||
|
() => fs.lstatSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fstat
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat');
|
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat');
|
||||||
assert.strictEqual(err.errno, uv.UV_EBADF);
|
assert.strictEqual(err.errno, uv.UV_EBADF);
|
||||||
assert.strictEqual(err.code, 'EBADF');
|
assert.strictEqual(err.code, 'EBADF');
|
||||||
assert.strictEqual(err.syscall, 'fstat');
|
assert.strictEqual(err.syscall, 'fstat');
|
||||||
}));
|
return true;
|
||||||
}
|
};
|
||||||
|
|
||||||
fs.realpath(fn, common.mustCall((err) => {
|
|
||||||
assert.strictEqual(fn, err.path);
|
|
||||||
assert.strictEqual(
|
|
||||||
err.message,
|
|
||||||
`ENOENT: no such file or directory, lstat '${fn}'`);
|
|
||||||
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
||||||
assert.strictEqual(err.code, 'ENOENT');
|
|
||||||
assert.strictEqual(err.syscall, 'lstat');
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.readlink(fn, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.link(fn, 'foo', common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.link(existingFile, existingFile2, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(existingFile));
|
|
||||||
assert.ok(err.message.includes(existingFile2));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.symlink(existingFile, existingFile2, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(existingFile));
|
|
||||||
assert.ok(err.message.includes(existingFile2));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.unlink(fn, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.rename(fn, 'foo', common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.rename(existingDir, existingDir2, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(existingDir));
|
|
||||||
assert.ok(err.message.includes(existingDir2));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.rmdir(fn, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.mkdir(existingFile, 0o666, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(existingFile));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.rmdir(existingFile, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(existingFile));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.chmod(fn, 0o666, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.open(fn, 'r', 0o666, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
fs.readFile(fn, common.mustCall((err) => {
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Sync
|
|
||||||
|
|
||||||
const errors = [];
|
|
||||||
let expected = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
++expected;
|
|
||||||
fs.statSync(fn);
|
|
||||||
} catch (err) {
|
|
||||||
errors.push('stat');
|
|
||||||
assert.strictEqual(fn, err.path);
|
|
||||||
assert.strictEqual(
|
|
||||||
err.message,
|
|
||||||
`ENOENT: no such file or directory, stat '${fn}'`);
|
|
||||||
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
||||||
assert.strictEqual(err.code, 'ENOENT');
|
|
||||||
assert.strictEqual(err.syscall, 'stat');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
++expected;
|
|
||||||
fs.mkdirSync(existingFile, 0o666);
|
|
||||||
} catch (err) {
|
|
||||||
errors.push('mkdir');
|
|
||||||
assert.ok(err.message.includes(existingFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
++expected;
|
|
||||||
fs.chmodSync(fn, 0o666);
|
|
||||||
} catch (err) {
|
|
||||||
errors.push('chmod');
|
|
||||||
assert.ok(err.message.includes(fn));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
++expected;
|
|
||||||
fs.lstatSync(fn);
|
|
||||||
} catch (err) {
|
|
||||||
errors.push('lstat');
|
|
||||||
assert.strictEqual(fn, err.path);
|
|
||||||
assert.strictEqual(
|
|
||||||
err.message,
|
|
||||||
`ENOENT: no such file or directory, lstat '${fn}'`);
|
|
||||||
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
|
||||||
assert.strictEqual(err.code, 'ENOENT');
|
|
||||||
assert.strictEqual(err.syscall, 'lstat');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
++expected;
|
|
||||||
const fd = fs.openSync(existingFile, 'r');
|
const fd = fs.openSync(existingFile, 'r');
|
||||||
fs.closeSync(fd);
|
fs.closeSync(fd);
|
||||||
fs.fstatSync(fd);
|
|
||||||
} catch (err) {
|
fs.fstat(fd, common.mustCall(validateError));
|
||||||
errors.push('fstat');
|
|
||||||
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fstat');
|
assert.throws(
|
||||||
assert.strictEqual(err.errno, uv.UV_EBADF);
|
() => fs.fstatSync(fd),
|
||||||
assert.strictEqual(err.code, 'EBADF');
|
validateError
|
||||||
assert.strictEqual(err.syscall, 'fstat');
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// realpath
|
||||||
++expected;
|
{
|
||||||
fs.realpathSync(fn);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('realpath');
|
assert.strictEqual(
|
||||||
assert.strictEqual(fn, err.path);
|
err.message,
|
||||||
assert.strictEqual(
|
`ENOENT: no such file or directory, lstat '${nonexistentFile}'`);
|
||||||
err.message,
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
`ENOENT: no such file or directory, lstat '${fn}'`);
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
assert.strictEqual(err.syscall, 'lstat');
|
||||||
assert.strictEqual(err.code, 'ENOENT');
|
return true;
|
||||||
assert.strictEqual(err.syscall, 'lstat');
|
};
|
||||||
|
|
||||||
|
fs.realpath(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.realpathSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// readlink
|
||||||
++expected;
|
{
|
||||||
fs.readlinkSync(fn);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('readlink');
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(fn));
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, readlink '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'readlink');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.readlink(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.readlinkSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// link nonexistent file
|
||||||
++expected;
|
{
|
||||||
fs.linkSync(fn, 'foo');
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('link');
|
// Could be resolved to an absolute path
|
||||||
assert.ok(err.message.includes(fn));
|
assert.ok(err.dest.endsWith('foo'),
|
||||||
|
`expect ${err.dest} to end with 'foo'`);
|
||||||
|
const regexp = new RegExp('^ENOENT: no such file or directory, link ' +
|
||||||
|
re`'${nonexistentFile}' -> ` + '\'.*foo\'');
|
||||||
|
assert.ok(regexp.test(err.message),
|
||||||
|
`Expect ${err.message} to match ${regexp}`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'link');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.link(nonexistentFile, 'foo', common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.linkSync(nonexistentFile, 'foo'),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// link existing file
|
||||||
++expected;
|
{
|
||||||
fs.linkSync(existingFile, existingFile2);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(existingFile, err.path);
|
||||||
errors.push('link');
|
assert.strictEqual(existingFile2, err.dest);
|
||||||
assert.ok(err.message.includes(existingFile));
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(existingFile2));
|
err.message,
|
||||||
|
`EEXIST: file already exists, link '${existingFile}' -> ` +
|
||||||
|
`'${existingFile2}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EEXIST);
|
||||||
|
assert.strictEqual(err.code, 'EEXIST');
|
||||||
|
assert.strictEqual(err.syscall, 'link');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.link(existingFile, existingFile2, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.linkSync(existingFile, existingFile2),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// symlink
|
||||||
++expected;
|
{
|
||||||
fs.symlinkSync(existingFile, existingFile2);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(existingFile, err.path);
|
||||||
errors.push('symlink');
|
assert.strictEqual(existingFile2, err.dest);
|
||||||
assert.ok(err.message.includes(existingFile));
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(existingFile2));
|
err.message,
|
||||||
|
`EEXIST: file already exists, symlink '${existingFile}' -> ` +
|
||||||
|
`'${existingFile2}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EEXIST);
|
||||||
|
assert.strictEqual(err.code, 'EEXIST');
|
||||||
|
assert.strictEqual(err.syscall, 'symlink');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.symlink(existingFile, existingFile2, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.symlinkSync(existingFile, existingFile2),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// unlink
|
||||||
++expected;
|
{
|
||||||
fs.unlinkSync(fn);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('unlink');
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(fn));
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, unlink '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'unlink');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.unlink(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.unlinkSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// rename
|
||||||
++expected;
|
{
|
||||||
fs.rmdirSync(fn);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('rmdir');
|
// Could be resolved to an absolute path
|
||||||
assert.ok(err.message.includes(fn));
|
assert.ok(err.dest.endsWith('foo'),
|
||||||
|
`expect ${err.dest} to end with 'foo'`);
|
||||||
|
const regexp = new RegExp('ENOENT: no such file or directory, rename ' +
|
||||||
|
re`'${nonexistentFile}' -> ` + '\'.*foo\'');
|
||||||
|
assert.ok(regexp.test(err.message),
|
||||||
|
`Expect ${err.message} to match ${regexp}`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'rename');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.rename(nonexistentFile, 'foo', common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.renameSync(nonexistentFile, 'foo'),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// rename non-empty directory
|
||||||
++expected;
|
{
|
||||||
fs.rmdirSync(existingFile);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(existingDir, err.path);
|
||||||
errors.push('rmdir');
|
assert.strictEqual(existingDir2, err.dest);
|
||||||
assert.ok(err.message.includes(existingFile));
|
assert.strictEqual(err.syscall, 'rename');
|
||||||
|
// Could be ENOTEMPTY, EEXIST, or EPERM, depending on the platform
|
||||||
|
if (err.code === 'ENOTEMPTY') {
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOTEMPTY: directory not empty, rename '${existingDir}' -> ` +
|
||||||
|
`'${existingDir2}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOTEMPTY);
|
||||||
|
} else if (err.code === 'EEXIST') { // smartos and aix
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`EEXIST: file already exists, rename '${existingDir}' -> ` +
|
||||||
|
`'${existingDir2}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EEXIST);
|
||||||
|
} else { // windows
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`EPERM: operation not permitted, rename '${existingDir}' -> ` +
|
||||||
|
`'${existingDir2}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EPERM);
|
||||||
|
assert.strictEqual(err.code, 'EPERM');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.rename(existingDir, existingDir2, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.renameSync(existingDir, existingDir2),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// rmdir
|
||||||
++expected;
|
{
|
||||||
fs.openSync(fn, 'r');
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('opens');
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(fn));
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, rmdir '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'rmdir');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.rmdir(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.rmdirSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// rmdir a file
|
||||||
++expected;
|
{
|
||||||
fs.renameSync(fn, 'foo');
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(existingFile, err.path);
|
||||||
errors.push('rename');
|
assert.strictEqual(err.syscall, 'rmdir');
|
||||||
assert.ok(err.message.includes(fn));
|
if (err.code === 'ENOTDIR') {
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOTDIR: not a directory, rmdir '${existingFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOTDIR);
|
||||||
|
} else { // windows
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, rmdir '${existingFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.rmdir(existingFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.rmdirSync(existingFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// mkdir
|
||||||
++expected;
|
{
|
||||||
fs.renameSync(existingDir, existingDir2);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(existingFile, err.path);
|
||||||
errors.push('rename');
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(existingDir));
|
err.message,
|
||||||
assert.ok(err.message.includes(existingDir2));
|
`EEXIST: file already exists, mkdir '${existingFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EEXIST);
|
||||||
|
assert.strictEqual(err.code, 'EEXIST');
|
||||||
|
assert.strictEqual(err.syscall, 'mkdir');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.mkdir(existingFile, 0o666, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.mkdirSync(existingFile, 0o666),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// chmod
|
||||||
++expected;
|
{
|
||||||
fs.readdirSync(fn);
|
const validateError = (err) => {
|
||||||
} catch (err) {
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
errors.push('readdir');
|
assert.strictEqual(
|
||||||
assert.ok(err.message.includes(fn));
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, chmod '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'chmod');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.chmod(nonexistentFile, 0o666, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.chmodSync(nonexistentFile, 0o666),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.strictEqual(expected, errors.length);
|
// open
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, open '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'open');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.open(nonexistentFile, 'r', 0o666, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.openSync(nonexistentFile, 'r', 0o666),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// readFile
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, open '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'open');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.readFile(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.readFileSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// readdir
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(nonexistentFile, err.path);
|
||||||
|
assert.strictEqual(
|
||||||
|
err.message,
|
||||||
|
`ENOENT: no such file or directory, scandir '${nonexistentFile}'`);
|
||||||
|
assert.strictEqual(err.errno, uv.UV_ENOENT);
|
||||||
|
assert.strictEqual(err.code, 'ENOENT');
|
||||||
|
assert.strictEqual(err.syscall, 'scandir');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.readdir(nonexistentFile, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.readdirSync(nonexistentFile),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user