test: add common.mustSucceed

PR-URL: https://github.com/nodejs/node/pull/35086
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Tobias Nießen authored and Beth Griggs committed 2020-12-08 13:42:23 +00:00
1 parent 6c4e697f56
commit 70cb70812d
140 files changed
+522 -782

No files matched your search

+5
View File
@@ -209,6 +209,11 @@ const server = http.createServer(common.mustCall((req, res) => {
```
**Note:** Many functions invoke their callback with an `err` value as the first
argument. It is not a good idea to simply pass `common.mustCall()` to those
because `common.mustCall()` will ignore the error. Use `common.mustSucceed()`
instead.
#### Countdown Module
The common [Countdown module](https://github.com/nodejs/node/tree/master/test/common#countdown-module)
+1
View File
@@ -50,6 +50,7 @@ rules:
node-core/prefer-assert-iferror: error
node-core/prefer-assert-methods: error
node-core/prefer-common-mustnotcall: error
node-core/prefer-common-mustsucceed: error
node-core/crypto-check: error
node-core/eslint-check: error
node-core/inspector-check: error
+9
View File
@@ -313,6 +313,15 @@ If `fn` is not provided, an empty function will be used.
Returns a function that triggers an `AssertionError` if it is invoked. `msg` is
used as the error message for the `AssertionError`.
### `mustSucceed([fn])`
* `fn` [&lt;Function>][] default = () => {}
* return [&lt;Function>][]
Returns a function that accepts arguments `(err, ...args)`. If `err` is not
`undefined` or `null`, it triggers an `AssertionError`. Otherwise, it calls
`fn(...args)`.
### `nodeProcessAborted(exitCode, signal)`
* `exitCode` [&lt;number>][]
+9
View File
@@ -334,6 +334,14 @@ function mustCall(fn, exact) {
return _mustCallInner(fn, exact, 'exact');
}
function mustSucceed(fn, exact) {
return mustCall(function(err, ...args) {
assert.ifError(err);
if (typeof fn === 'function')
return fn.apply(this, args);
}, exact);
}
function mustCallAtLeast(fn, minimum) {
return _mustCallInner(fn, minimum, 'minimum');
}
@@ -723,6 +731,7 @@ const common = {
mustCall,
mustCallAtLeast,
mustNotCall,
mustSucceed,
nodeProcessAborted,
PIPE,
platformTimeout,
+2 -4
View File
@@ -229,10 +229,8 @@ const testData = [
];
testData.forEach((item) => {
fs.readFile(item.file, 'utf8', common.mustCall((err, input) => {
assert.ifError(err);
toJSON(input, 'foo', common.mustCall((err, output) => {
assert.ifError(err);
fs.readFile(item.file, 'utf8', common.mustSucceed((input) => {
toJSON(input, 'foo', common.mustSucceed((output) => {
assert.deepStrictEqual(output.json, item.json);
}));
}));
+3 -6
View File
@@ -127,8 +127,7 @@ TEST(async function test_sip2sip_for_naptr(done) {
const req = dns.resolve(
'sip2sip.info',
'ANY',
common.mustCall(function(err, ret) {
assert.ifError(err);
common.mustSucceed((ret) => {
validateResult(ret);
done();
}));
@@ -147,8 +146,7 @@ TEST(async function test_google_for_cname_and_srv(done) {
const req = dns.resolve(
'_jabber._tcp.google.com',
'ANY',
common.mustCall(function(err, ret) {
assert.ifError(err);
common.mustSucceed((ret) => {
validateResult(ret);
done();
}));
@@ -167,8 +165,7 @@ TEST(async function test_ptr(done) {
const req = dns.resolve(
'8.8.8.8.in-addr.arpa',
'ANY',
common.mustCall(function(err, ret) {
assert.ifError(err);
common.mustSucceed((ret) => {
validateResult(ret);
done();
}));
+10 -20
View File
@@ -50,8 +50,7 @@ TEST(async function test_resolve4(done) {
const req = dns.resolve4(
addresses.INET4_HOST,
common.mustCall((err, ips) => {
assert.ifError(err);
common.mustSucceed((ips) => {
validateResult(ips);
done();
}));
@@ -73,8 +72,7 @@ TEST(async function test_reverse_ipv4(done) {
const req = dns.reverse(
addresses.INET4_IP,
common.mustCall((err, domains) => {
assert.ifError(err);
common.mustSucceed((domains) => {
validateResult(domains);
done();
}));
@@ -92,8 +90,7 @@ TEST(async function test_lookup_ipv4_explicit(done) {
const req = dns.lookup(
addresses.INET4_HOST, 4,
common.mustCall((err, ip, family) => {
assert.ifError(err);
common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -111,8 +108,7 @@ TEST(async function test_lookup_ipv4_implicit(done) {
const req = dns.lookup(
addresses.INET4_HOST,
common.mustCall((err, ip, family) => {
assert.ifError(err);
common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -130,8 +126,7 @@ TEST(async function test_lookup_ipv4_explicit_object(done) {
const req = dns.lookup(addresses.INET4_HOST, {
family: 4
}, common.mustCall((err, ip, family) => {
assert.ifError(err);
}, common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -151,8 +146,7 @@ TEST(async function test_lookup_ipv4_hint_addrconfig(done) {
const req = dns.lookup(addresses.INET4_HOST, {
hints: dns.ADDRCONFIG
}, common.mustCall((err, ip, family) => {
assert.ifError(err);
}, common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -169,8 +163,7 @@ TEST(async function test_lookup_ip_ipv4(done) {
validateResult(await dnsPromises.lookup('127.0.0.1'));
const req = dns.lookup('127.0.0.1',
common.mustCall((err, ip, family) => {
assert.ifError(err);
common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -187,8 +180,7 @@ TEST(async function test_lookup_localhost_ipv4(done) {
validateResult(await dnsPromises.lookup('localhost', 4));
const req = dns.lookup('localhost', 4,
common.mustCall((err, ip, family) => {
assert.ifError(err);
common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -215,8 +207,7 @@ TEST(async function test_lookup_all_ipv4(done) {
const req = dns.lookup(
addresses.INET4_HOST,
{ all: true, family: 4 },
common.mustCall((err, ips) => {
assert.ifError(err);
common.mustSucceed((ips) => {
validateResult(ips);
done();
})
@@ -236,8 +227,7 @@ TEST(async function test_lookupservice_ip_ipv4(done) {
const req = dns.lookupService(
'127.0.0.1', 80,
common.mustCall((err, hostname, service) => {
assert.ifError(err);
common.mustSucceed((hostname, service) => {
validateResult({ hostname, service });
done();
})
+6 -12
View File
@@ -52,8 +52,7 @@ TEST(async function test_resolve6(done) {
const req = dns.resolve6(
addresses.INET6_HOST,
common.mustCall((err, ips) => {
assert.ifError(err);
common.mustSucceed((ips) => {
validateResult(ips);
done();
}));
@@ -74,8 +73,7 @@ TEST(async function test_reverse_ipv6(done) {
const req = dns.reverse(
addresses.INET6_IP,
common.mustCall((err, domains) => {
assert.ifError(err);
common.mustSucceed((domains) => {
validateResult(domains);
done();
}));
@@ -94,8 +92,7 @@ TEST(async function test_lookup_ipv6_explicit(done) {
const req = dns.lookup(
addresses.INET6_HOST,
6,
common.mustCall((err, ip, family) => {
assert.ifError(err);
common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -126,8 +123,7 @@ TEST(async function test_lookup_ipv6_explicit_object(done) {
const req = dns.lookup(addresses.INET6_HOST, {
family: 6
}, common.mustCall((err, ip, family) => {
assert.ifError(err);
}, common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -173,8 +169,7 @@ TEST(async function test_lookup_ip_ipv6(done) {
const req = dns.lookup(
'::1',
common.mustCall((err, ip, family) => {
assert.ifError(err);
common.mustSucceed((ip, family) => {
validateResult({ address: ip, family });
done();
}));
@@ -202,8 +197,7 @@ TEST(async function test_lookup_all_ipv6(done) {
const req = dns.lookup(
addresses.INET6_HOST,
{ all: true, family: 6 },
common.mustCall((err, ips) => {
assert.ifError(err);
common.mustSucceed((ips) => {
validateResult(ips);
done();
})
+3 -10
View File
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
if (!common.hasCrypto)
common.skip('missing crypto');
@@ -29,9 +28,7 @@ function normalSession(cb) {
});
});
}
normalSession(common.mustCall(function(err) {
assert.ifError(err);
}));
normalSession(common.mustSucceed());
// Create a session using a socket that has not yet finished connecting
function socketNotFinished(done) {
@@ -52,9 +49,7 @@ function socketNotFinished(done) {
});
});
}
socketNotFinished(common.mustCall(function(err) {
assert.ifError(err);
}));
socketNotFinished(common.mustSucceed());
// Create a session using a socket that has finished connecting
function socketFinished(done) {
@@ -75,6 +70,4 @@ function socketFinished(done) {
});
});
}
socketFinished(common.mustCall(function(err) {
assert.ifError(err);
}));
socketFinished(common.mustSucceed());
+4 -8
View File
@@ -43,20 +43,17 @@ const dnsPromises = dns.promises;
})();
// Try resolution without hostname.
dns.lookup(null, common.mustCall((error, result, addressType) => {
assert.ifError(error);
dns.lookup(null, common.mustSucceed((result, addressType) => {
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
}));
dns.lookup('127.0.0.1', common.mustCall((error, result, addressType) => {
assert.ifError(error);
dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
dns.lookup('::1', common.mustCall((error, result, addressType) => {
assert.ifError(error);
dns.lookup('::1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
}));
@@ -86,8 +83,7 @@ dns.lookup('::1', common.mustCall((error, result, addressType) => {
// so we disable this test on Windows.
// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1
if (!common.isWindows && !common.isIBMi) {
dns.reverse('127.0.0.1', common.mustCall(function(error, domains) {
assert.ifError(error);
dns.reverse('127.0.0.1', common.mustSucceed((domains) => {
assert.ok(Array.isArray(domains));
}));
@@ -17,8 +17,8 @@ fs.mkdirSync(tmpPath);
const test = (shell) => {
cp.exec('echo foo bar', { shell: shell },
common.mustCall((error, stdout, stderror) => {
assert.ok(!error && !stderror);
common.mustSucceed((stdout, stderror) => {
assert.ok(!stderror);
assert.ok(stdout.includes('foo') && stdout.includes('bar'));
}));
};
@@ -43,12 +43,11 @@ test('CMD');
test('powershell');
testCopy('powershell.exe',
`${system32}\\WindowsPowerShell\\v1.0\\powershell.exe`);
fs.writeFile(`${tmpPath}\\test file`, 'Test', common.mustCall((err) => {
assert.ifError(err);
fs.writeFile(`${tmpPath}\\test file`, 'Test', common.mustSucceed(() => {
cp.exec(`Get-ChildItem "${tmpPath}" | Select-Object -Property Name`,
{ shell: 'PowerShell' },
common.mustCall((error, stdout, stderror) => {
assert.ok(!error && !stderror);
common.mustSucceed((stdout, stderror) => {
assert.ok(!stderror);
assert.ok(stdout.includes(
'test file'));
}));
+1 -2
View File
@@ -34,7 +34,6 @@ if (common.isWindows) {
dir = '/dev';
}
exec(pwdcommand, { cwd: dir }, common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
exec(pwdcommand, { cwd: dir }, common.mustSucceed((stdout, stderr) => {
assert(stdout.startsWith(dir));
}));
@@ -15,8 +15,7 @@ if (process.argv[2] === 'child') {
function run(options, callback) {
const cmd = `"${process.execPath}" "${__filename}" child`;
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
cp.exec(cmd, options, common.mustSucceed((stdout, stderr) => {
callback(stdout, stderr);
}));
}
@@ -27,8 +27,7 @@ function runChecks(err, stdio, streamName, expected) {
const cmd =
`${process.execPath} -e "console.log('a'.repeat(1024 * 1024 - 1))"`;
cp.exec(cmd, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, '');
}));
@@ -38,8 +37,7 @@ function runChecks(err, stdio, streamName, expected) {
const cmd = `"${process.execPath}" -e "console.log('hello world');"`;
const options = { maxBuffer: Infinity };
cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
cp.exec(cmd, options, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'hello world');
assert.strictEqual(stderr, '');
}));
@@ -80,8 +78,7 @@ function runChecks(err, stdio, streamName, expected) {
const cmd =
`"${process.execPath}" -e "console.log('a'.repeat(1024 * 1024 - 1))"`;
cp.exec(cmd, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, '');
}));
@@ -13,8 +13,7 @@ if (process.argv[2] === 'child') {
console.error(stderrData);
} else {
const cmd = `"${process.execPath}" "${__filename}" child`;
const child = cp.exec(cmd, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
const child = cp.exec(cmd, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, expectedStdout);
assert.strictEqual(stderr, expectedStderr);
}));
@@ -51,8 +51,7 @@ cp.exec(cmd, {
}));
// Test the case where a timeout is set, but not expired.
cp.exec(cmd, { timeout: 2 ** 30 }, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
cp.exec(cmd, { timeout: 2 ** 30 }, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'child stdout');
assert.strictEqual(stderr.trim(), 'child stderr');
}));
@@ -25,8 +25,7 @@ function checkFactory(streamName) {
execFile(
process.execPath,
['-e', 'console.log("a".repeat(1024 * 1024 - 1))'],
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
assert.strictEqual(stderr, '');
})
@@ -40,8 +39,7 @@ function checkFactory(streamName) {
process.execPath,
['-e', 'console.log("hello world");'],
options,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), 'hello world');
assert.strictEqual(stderr, '');
})
+1 -3
View File
@@ -43,7 +43,5 @@ const execOpts = { encoding: 'utf8', shell: true };
{
// Verify the shell option works properly
execFile(process.execPath, [fixture, 0], execOpts, common.mustCall((err) => {
assert.ifError(err);
}));
execFile(process.execPath, [fixture, 0], execOpts, common.mustSucceed());
}
@@ -97,8 +97,7 @@ if (process.argv[2] === 'child') {
child.once('message', common.mustCall((m) => {
assert.strictEqual(m.status, 'closed');
server.getConnections(common.mustCall((err, num) => {
assert.ifError(err);
server.getConnections(common.mustSucceed((num) => {
assert.strictEqual(num, count - (i + 1));
closeSockets(i + 1);
}));
@@ -32,9 +32,7 @@ if (process.argv[2] !== 'child') {
});
}));
child.send('socket', socket, { keepOpen: true }, common.mustCall((err) => {
assert.ifError(err);
}));
child.send('socket', socket, { keepOpen: true }, common.mustSucceed());
});
server.listen(0, () => {
@@ -42,8 +42,7 @@ internalCp.spawnSync = common.mustCall(function(options) {
}
{
const callback = common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
const callback = common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout.trim(), '42');
assert.strictEqual(stderr.trim(), '');
});
+16 -32
View File
@@ -40,16 +40,14 @@ if (process.argv.length > 2) {
}
// Assert that nothing is written to stdout.
child.exec(`${nodejs} --eval 42`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
child.exec(`${nodejs} --eval 42`, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
}));
// Assert that "42\n" is written to stderr.
child.exec(`${nodejs} --eval "console.error(42)"`,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '42\n');
}));
@@ -58,14 +56,12 @@ child.exec(`${nodejs} --eval "console.error(42)"`,
['--print', '-p -e', '-pe', '-p'].forEach((s) => {
const cmd = `${nodejs} ${s} `;
child.exec(`${cmd}42`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
child.exec(`${cmd}42`, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '42\n');
assert.strictEqual(stderr, '');
}));
child.exec(`${cmd} '[]'`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
child.exec(`${cmd} '[]'`, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '[]\n');
assert.strictEqual(stderr, '');
}));
@@ -88,8 +84,7 @@ child.exec(`${nodejs} --eval "console.error(42)"`,
// Check that builtin modules are pre-defined.
child.exec(`${nodejs} --print "os.platform()"`,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stderr, '');
assert.strictEqual(stdout.trim(), require('os').platform());
}));
@@ -113,22 +108,19 @@ child.exec(`${nodejs} -e`, common.mustCall((err, stdout, stderr) => {
}));
// Empty program should do nothing.
child.exec(`${nodejs} -e ""`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
child.exec(`${nodejs} -e ""`, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
}));
// "\\-42" should be interpreted as an escaped expression, not a switch.
child.exec(`${nodejs} -p "\\-42"`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
child.exec(`${nodejs} -p "\\-42"`, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '-42\n');
assert.strictEqual(stderr, '');
}));
child.exec(`${nodejs} --use-strict -p process.execArgv`,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(
stdout, "[ '--use-strict', '-p', 'process.execArgv' ]\n"
);
@@ -143,8 +135,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
}
child.exec(`${nodejs} -e 'require("child_process").fork("${emptyFile}")'`,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
}));
@@ -154,8 +145,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
child.exec(
`${nodejs} -e "process.execArgv = ['-e', 'console.log(42)', 'thirdArg'];` +
`require('child_process').fork('${emptyFile}')"`,
common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, '42\n');
assert.strictEqual(stderr, '');
}));
@@ -237,8 +227,7 @@ child.exec(`${nodejs} --use-strict -p process.execArgv`,
const execOptions = '--input-type module';
child.exec(
`${nodejs} ${execOptions} --eval "console.log(42)"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
common.mustSucceed((stdout) => {
assert.strictEqual(stdout, '42\n');
}));
@@ -263,16 +252,14 @@ child.exec(
// Assert that require is undefined in ESM support
child.exec(
`${nodejs} ${execOptions} --eval "console.log(typeof require);"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
common.mustSucceed((stdout) => {
assert.strictEqual(stdout, 'undefined\n');
}));
// Assert that import.meta is defined in ESM
child.exec(
`${nodejs} ${execOptions} --eval "console.log(typeof import.meta);"`,
common.mustCall((err, stdout) => {
assert.ifError(err);
common.mustSucceed((stdout) => {
assert.strictEqual(stdout, 'object\n');
}));
@@ -280,8 +267,7 @@ child.exec(
child.exec(
`${nodejs} ${execOptions} ` +
'--eval "import \'./test/fixtures/es-modules/mjs-file.mjs\'"',
common.mustCall((err, stdout) => {
assert.ifError(err);
common.mustSucceed((stdout) => {
assert.strictEqual(stdout, '.mjs file\n');
}));
@@ -291,8 +277,7 @@ child.exec(
`${nodejs} ${execOptions} ` +
'--eval "process.chdir(\'..\');' +
'import(\'./test/fixtures/es-modules/mjs-file.mjs\')"',
common.mustCall((err, stdout) => {
assert.ifError(err);
common.mustSucceed((stdout) => {
assert.strictEqual(stdout, '.mjs file\n');
}));
@@ -300,7 +285,6 @@ child.exec(
`${nodejs} ` +
'--eval "process.chdir(\'..\');' +
'import(\'./test/fixtures/es-modules/mjs-file.mjs\')"',
common.mustCall((err, stdout) => {
assert.ifError(err);
common.mustSucceed((stdout) => {
assert.strictEqual(stdout, '.mjs file\n');
}));
+1 -2
View File
@@ -14,8 +14,7 @@ let stdOut;
function startPrintHelpTest() {
exec(`${process.execPath} --help`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
exec(`${process.execPath} --help`, common.mustSucceed((stdout, stderr) => {
stdOut = stdout;
validateNodePrintHelp();
}));
+1 -2
View File
@@ -51,8 +51,7 @@ http.createServer(common.mustCall((req, res) => {
})).listen(common.PIPE, common.mustCall(() => {
http.get({ socketPath: common.PIPE, path: '/' }, common.mustCall((res) => {
res.resume();
res.on('end', common.mustCall((err) => {
assert.ifError(err);
res.on('end', common.mustSucceed(() => {
process.send('DONE');
process.exit();
}));
@@ -10,8 +10,7 @@ const server = http.createServer();
if (cluster.isMaster) {
let worker;
server.listen(0, common.mustCall((error) => {
assert.ifError(error);
server.listen(0, common.mustSucceed(() => {
assert(worker);
worker.send({ port: server.address().port });
+18 -52
View File
@@ -143,9 +143,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
type: 'pkcs1',
format: 'pem'
}
}, common.mustCall((err, publicKeyDER, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKeyDER, privateKey) => {
assert(Buffer.isBuffer(publicKeyDER));
assertApproximateSize(publicKeyDER, 74);
@@ -169,9 +167,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher: 'aes-256-cbc',
passphrase: 'secret'
}
}, common.mustCall((err, publicKeyDER, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKeyDER, privateKey) => {
assert(Buffer.isBuffer(publicKeyDER));
assertApproximateSize(publicKeyDER, 74);
@@ -202,9 +198,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher: 'aes-256-cbc',
passphrase: 'secret'
}
}, common.mustCall((err, publicKeyDER, privateKeyDER) => {
assert.ifError(err);
}, common.mustSucceed((publicKeyDER, privateKeyDER) => {
assert(Buffer.isBuffer(publicKeyDER));
assertApproximateSize(publicKeyDER, 74);
@@ -245,9 +239,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
type: 'pkcs8',
format: 'der'
}
}, common.mustCall((err, publicKeyDER, privateKeyDER) => {
assert.ifError(err);
}, common.mustSucceed((publicKeyDER, privateKeyDER) => {
assert(Buffer.isBuffer(publicKeyDER));
assertApproximateSize(publicKeyDER, 74);
@@ -272,9 +264,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
saltLength: 16,
hash: 'sha256',
mgf1Hash: 'sha256'
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
@@ -321,9 +311,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
passphrase: 'secret',
...privateKeyEncoding
}
}, common.mustCall((err, publicKey, privateKeyDER) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKeyDER) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
// The private key is DER-encoded.
@@ -367,9 +355,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
type: 'sec1',
format: 'pem'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.strictEqual(typeof privateKey, 'string');
@@ -391,9 +377,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
type: 'sec1',
format: 'pem'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.strictEqual(typeof privateKey, 'string');
@@ -416,9 +400,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher: 'aes-128-cbc',
passphrase: 'secret'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.strictEqual(typeof privateKey, 'string');
@@ -448,9 +430,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher: 'aes-128-cbc',
passphrase: 'secret'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.strictEqual(typeof privateKey, 'string');
@@ -483,9 +463,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher: 'aes-128-cbc',
passphrase: 'top secret'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.strictEqual(typeof privateKey, 'string');
@@ -519,9 +497,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
cipher: 'aes-128-cbc',
passphrase: 'top secret'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'string');
assert(spkiExp.test(publicKey));
assert.strictEqual(typeof privateKey, 'string');
@@ -637,9 +613,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
type: 'pkcs1',
format: 'pem'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(typeof publicKey, 'object');
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa');
@@ -658,9 +632,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
type: 'pkcs1',
format: 'pem'
}
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
// The public key should still be a string.
assert.strictEqual(typeof publicKey, 'string');
@@ -962,16 +934,14 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
namedCurve: 'P-256',
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
}));
generateKeyPair('ec', {
namedCurve: 'secp256k1',
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
}));
}
@@ -979,9 +949,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
if (!/^1\.1\.0/.test(process.versions.openssl)) {
['ed25519', 'ed448', 'x25519', 'x448'].forEach((keyType) => {
generateKeyPair(keyType, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
generateKeyPair(keyType, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, keyType);
@@ -996,9 +964,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
{
generateKeyPair('dh', {
primeLength: 1024
}, common.mustCall((err, publicKey, privateKey) => {
assert.ifError(err);
}, common.mustSucceed((publicKey, privateKey) => {
assert.strictEqual(publicKey.type, 'public');
assert.strictEqual(publicKey.asymmetricKeyType, 'dh');
+29 -17
View File
@@ -14,9 +14,10 @@ function testPBKDF2(password, salt, iterations, keylen, expected) {
crypto.pbkdf2Sync(password, salt, iterations, keylen, 'sha256');
assert.strictEqual(actual.toString('latin1'), expected);
crypto.pbkdf2(password, salt, iterations, keylen, 'sha256', (err, actual) => {
assert.strictEqual(actual.toString('latin1'), expected);
});
crypto.pbkdf2(password, salt, iterations, keylen, 'sha256',
(err, actual) => {
assert.strictEqual(actual.toString('latin1'), expected);
});
}
@@ -48,9 +49,10 @@ const expected =
const key = crypto.pbkdf2Sync('password', 'salt', 32, 32, 'sha256');
assert.strictEqual(key.toString('hex'), expected);
crypto.pbkdf2('password', 'salt', 32, 32, 'sha256', common.mustCall(ondone));
function ondone(err, key) {
assert.ifError(err);
crypto.pbkdf2('password', 'salt', 32, 32, 'sha256',
common.mustSucceed(ondone));
function ondone(key) {
assert.strictEqual(key.toString('hex'), expected);
}
@@ -115,7 +117,7 @@ for (const iterations of [-1, 0]) {
// Should not get FATAL ERROR with empty password and salt
// https://github.com/nodejs/node/issues/8571
crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustCall(assert.ifError));
crypto.pbkdf2('', '', 1, 32, 'sha256', common.mustSucceed());
assert.throws(
() => crypto.pbkdf2('password', 'salt', 8, 8, common.mustNotCall()),
@@ -205,16 +207,26 @@ assert.throws(
});
// Any TypedArray should work for password and salt
crypto.pbkdf2(new Uint8Array(10), 'salt', 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2('pass', new Uint8Array(10), 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2(new Uint16Array(10), 'salt', 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2('pass', new Uint16Array(10), 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2(new Uint32Array(10), 'salt', 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2('pass', new Uint32Array(10), 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2(new Float32Array(10), 'salt', 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2('pass', new Float32Array(10), 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2(new Float64Array(10), 'salt', 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2('pass', new Float64Array(10), 8, 8, 'sha256', common.mustCall());
crypto.pbkdf2(new Uint8Array(10), 'salt', 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2('pass', new Uint8Array(10), 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2(new Uint16Array(10), 'salt', 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2('pass', new Uint16Array(10), 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2(new Uint32Array(10), 'salt', 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2('pass', new Uint32Array(10), 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2(new Float32Array(10), 'salt', 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2('pass', new Float32Array(10), 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2(new Float64Array(10), 'salt', 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2('pass', new Float64Array(10), 8, 8, 'sha256',
common.mustSucceed());
crypto.pbkdf2Sync(new Uint8Array(10), 'salt', 8, 8, 'sha256');
crypto.pbkdf2Sync('pass', new Uint8Array(10), 8, 8, 'sha256');
+14 -22
View File
@@ -104,8 +104,7 @@ common.expectWarning('DeprecationWarning',
{
const buf = Buffer.alloc(10);
const before = buf.toString('hex');
crypto.randomFill(buf, common.mustCall((err, buf) => {
assert.ifError(err);
crypto.randomFill(buf, common.mustSucceed((buf) => {
const after = buf.toString('hex');
assert.notStrictEqual(before, after);
}));
@@ -114,8 +113,7 @@ common.expectWarning('DeprecationWarning',
{
const buf = new Uint8Array(new Array(10).fill(0));
const before = Buffer.from(buf).toString('hex');
crypto.randomFill(buf, common.mustCall((err, buf) => {
assert.ifError(err);
crypto.randomFill(buf, common.mustSucceed((buf) => {
const after = Buffer.from(buf).toString('hex');
assert.notStrictEqual(before, after);
}));
@@ -130,8 +128,7 @@ common.expectWarning('DeprecationWarning',
new DataView(new ArrayBuffer(10))
].forEach((buf) => {
const before = Buffer.from(buf.buffer).toString('hex');
crypto.randomFill(buf, common.mustCall((err, buf) => {
assert.ifError(err);
crypto.randomFill(buf, common.mustSucceed((buf) => {
const after = Buffer.from(buf.buffer).toString('hex');
assert.notStrictEqual(before, after);
}));
@@ -168,8 +165,7 @@ common.expectWarning('DeprecationWarning',
{
const buf = Buffer.alloc(10);
const before = buf.toString('hex');
crypto.randomFill(buf, 5, 5, common.mustCall((err, buf) => {
assert.ifError(err);
crypto.randomFill(buf, 5, 5, common.mustSucceed((buf) => {
const after = buf.toString('hex');
assert.notStrictEqual(before, after);
assert.deepStrictEqual(before.slice(0, 5), after.slice(0, 5));
@@ -179,8 +175,7 @@ common.expectWarning('DeprecationWarning',
{
const buf = new Uint8Array(new Array(10).fill(0));
const before = Buffer.from(buf).toString('hex');
crypto.randomFill(buf, 5, 5, common.mustCall((err, buf) => {
assert.ifError(err);
crypto.randomFill(buf, 5, 5, common.mustSucceed((buf) => {
const after = Buffer.from(buf).toString('hex');
assert.notStrictEqual(before, after);
assert.deepStrictEqual(before.slice(0, 5), after.slice(0, 5));
@@ -318,8 +313,7 @@ assert.throws(
// Asynchronous API
const randomInts = [];
for (let i = 0; i < 100; i++) {
crypto.randomInt(3, common.mustCall((err, n) => {
assert.ifError(err);
crypto.randomInt(3, common.mustSucceed((n) => {
assert.ok(n >= 0);
assert.ok(n < 3);
randomInts.push(n);
@@ -353,8 +347,7 @@ assert.throws(
// Positive range
const randomInts = [];
for (let i = 0; i < 100; i++) {
crypto.randomInt(1, 3, common.mustCall((err, n) => {
assert.ifError(err);
crypto.randomInt(1, 3, common.mustSucceed((n) => {
assert.ok(n >= 1);
assert.ok(n < 3);
randomInts.push(n);
@@ -371,8 +364,7 @@ assert.throws(
// Negative range
const randomInts = [];
for (let i = 0; i < 100; i++) {
crypto.randomInt(-10, -8, common.mustCall((err, n) => {
assert.ifError(err);
crypto.randomInt(-10, -8, common.mustSucceed((n) => {
assert.ok(n >= -10);
assert.ok(n < -8);
randomInts.push(n);
@@ -430,8 +422,8 @@ assert.throws(
const maxInt = Number.MAX_SAFE_INTEGER;
const minInt = Number.MIN_SAFE_INTEGER;
crypto.randomInt(minInt, minInt + 5, common.mustCall());
crypto.randomInt(maxInt - 5, maxInt, common.mustCall());
crypto.randomInt(minInt, minInt + 5, common.mustSucceed());
crypto.randomInt(maxInt - 5, maxInt, common.mustSucceed());
assert.throws(
() => crypto.randomInt(minInt - 1, minInt + 5, common.mustNotCall()),
@@ -453,8 +445,8 @@ assert.throws(
}
);
crypto.randomInt(1, common.mustCall());
crypto.randomInt(0, 1, common.mustCall());
crypto.randomInt(1, common.mustSucceed());
crypto.randomInt(0, 1, common.mustSucceed());
for (const arg of [[0], [1, 1], [3, 2], [-5, -5], [11, -10]]) {
assert.throws(() => crypto.randomInt(...arg, common.mustNotCall()), {
code: 'ERR_OUT_OF_RANGE',
@@ -466,8 +458,8 @@ assert.throws(
}
const MAX_RANGE = 0xFFFF_FFFF_FFFF;
crypto.randomInt(MAX_RANGE, common.mustCall());
crypto.randomInt(1, MAX_RANGE + 1, common.mustCall());
crypto.randomInt(MAX_RANGE, common.mustSucceed());
crypto.randomInt(1, MAX_RANGE + 1, common.mustSucceed());
assert.throws(
() => crypto.randomInt(1, MAX_RANGE + 2, common.mustNotCall()),
{
+4 -8
View File
@@ -149,8 +149,7 @@ for (const options of good) {
const { pass, salt, keylen, expected } = options;
const actual = crypto.scryptSync(pass, salt, keylen, options);
assert.strictEqual(actual.toString('hex'), expected);
crypto.scrypt(pass, salt, keylen, options, common.mustCall((err, actual) => {
assert.ifError(err);
crypto.scrypt(pass, salt, keylen, options, common.mustSucceed((actual) => {
assert.strictEqual(actual.toString('hex'), expected);
}));
}
@@ -184,8 +183,7 @@ for (const options of toobig) {
const expected = crypto.scryptSync('pass', 'salt', 1, defaults);
const actual = crypto.scryptSync('pass', 'salt', 1);
assert.deepStrictEqual(actual.toString('hex'), expected.toString('hex'));
crypto.scrypt('pass', 'salt', 1, common.mustCall((err, actual) => {
assert.ifError(err);
crypto.scrypt('pass', 'salt', 1, common.mustSucceed((actual) => {
assert.deepStrictEqual(actual.toString('hex'), expected.toString('hex'));
}));
}
@@ -200,8 +198,7 @@ for (const options of toobig) {
const actual = crypto.scryptSync('pass', 'salt', 1);
assert.deepStrictEqual(actual, expected.toString(testEncoding));
crypto.scrypt('pass', 'salt', 1, common.mustCall((err, actual) => {
assert.ifError(err);
crypto.scrypt('pass', 'salt', 1, common.mustSucceed((actual) => {
assert.deepStrictEqual(actual, expected.toString(testEncoding));
}));
@@ -225,8 +222,7 @@ for (const { args, expected } of badargs) {
// Values for maxmem that do not fit in 32 bits but that are still safe
// integers should be allowed.
crypto.scrypt('', '', 4, { maxmem: 2 ** 52 },
common.mustCall((err, actual) => {
assert.ifError(err);
common.mustSucceed((actual) => {
assert.strictEqual(actual.toString('hex'), 'd72c87d0');
}));
@@ -10,8 +10,7 @@ const buf = Buffer.allocUnsafe(256);
const offset = 20;
const len = buf.length - offset;
const messageSent = common.mustCall(function messageSent(err, bytes) {
assert.ifError(err);
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
@@ -8,8 +8,7 @@ const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustCall(function(err, bytes) {
assert.ifError(err);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
@@ -10,7 +10,7 @@ client.bind(0, common.mustCall(function() {
const port = this.address().port;
client.connect(port, common.mustCall(() => {
const buf = Buffer.alloc(0);
client.send(buf, 0, 0, common.mustCall());
client.send(buf, 0, 0, common.mustSucceed());
}));
client.on('message', common.mustCall((buffer) => {
@@ -6,8 +6,7 @@ const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const onMessage = common.mustCall(common.mustCall((err, bytes) => {
assert.ifError(err);
const onMessage = common.mustCall(common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf1.length + buf2.length);
}));
@@ -5,8 +5,7 @@ const dgram = require('dgram');
const buf = Buffer.from('test');
const onMessage = common.mustCall((err, bytes) => {
assert.ifError(err);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
}, 6);
@@ -8,8 +8,7 @@ const client = dgram.createSocket('udp4');
const buf = Buffer.alloc(256, 'x');
const onMessage = common.mustCall(function(err, bytes) {
assert.ifError(err);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
@@ -10,8 +10,7 @@ const buf = Buffer.alloc(256, 'x');
const offset = 20;
const len = buf.length - offset;
const onMessage = common.mustCall(function messageSent(err, bytes) {
assert.ifError(err);
const onMessage = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
@@ -31,8 +31,7 @@ const buf = Buffer.allocUnsafe(256);
const offset = 20;
const len = buf.length - offset;
const messageSent = common.mustCall(function messageSent(err, bytes) {
assert.ifError(err);
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.notStrictEqual(bytes, buf.length);
assert.strictEqual(bytes, buf.length - offset);
client.close();
@@ -8,8 +8,7 @@ const client = dgram.createSocket('udp4');
const buf = Buffer.allocUnsafe(256);
const onMessage = common.mustCall(function(err, bytes) {
assert.ifError(err);
const onMessage = common.mustSucceed((bytes) => {
assert.strictEqual(bytes, buf.length);
client.close();
});
@@ -6,8 +6,7 @@ const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const messageSent = common.mustCall(function messageSent(err, bytes) {
assert.ifError(err);
const messageSent = common.mustSucceed(function messageSent(bytes) {
assert.strictEqual(bytes, buf1.length + buf2.length);
});
+3 -6
View File
@@ -116,8 +116,7 @@ dns.lookup(false, {
hints: 0,
family: 0,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
}, common.mustSucceed((result, addressType) => {
assert.deepStrictEqual(result, []);
assert.strictEqual(addressType, undefined);
}));
@@ -126,8 +125,7 @@ dns.lookup('127.0.0.1', {
hints: 0,
family: 4,
all: true
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
}, common.mustSucceed((result, addressType) => {
assert.deepStrictEqual(result, [{
address: '127.0.0.1',
family: 4
@@ -139,8 +137,7 @@ dns.lookup('127.0.0.1', {
hints: 0,
family: 4,
all: false
}, common.mustCall((error, result, addressType) => {
assert.ifError(error);
}, common.mustSucceed((result, addressType) => {
assert.deepStrictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
+1 -2
View File
@@ -44,8 +44,7 @@ function ready() {
for (const { server: { socket, reply }, resolver } of resolvers) {
resolver.setServers([`127.0.0.1:${socket.address().port}`]);
resolver.resolve4('example.org', common.mustCall((err, res) => {
assert.ifError(err);
resolver.resolve4('example.org', common.mustSucceed((res) => {
assert.deepStrictEqual(res, [reply.address]);
socket.close();
}));
+1 -2
View File
@@ -45,8 +45,7 @@ server.bind(0, common.mustCall(async () => {
validateResults(await dnsPromises.resolveAny('example.org'));
dns.resolveAny('example.org', common.mustCall((err, res) => {
assert.ifError(err);
dns.resolveAny('example.org', common.mustSucceed((res) => {
validateResults(res);
server.close();
}));
+1 -2
View File
@@ -442,8 +442,7 @@ assert.throws(() => {
validateResults(await dnsPromises[method]('example.org', options));
dns[method]('example.org', options, common.mustCall((err, res) => {
assert.ifError(err);
dns[method]('example.org', options, common.mustSucceed((res) => {
validateResults(res);
cases.shift();
nextCase();
+3 -3
View File
@@ -35,9 +35,9 @@ global.domain = require('domain');
// Should not throw a 'TypeError: undefined is not a function' exception
crypto.randomBytes(8);
crypto.randomBytes(8, common.mustCall());
crypto.randomBytes(8, common.mustSucceed());
const buf = Buffer.alloc(8);
crypto.randomFillSync(buf);
crypto.pseudoRandomBytes(8);
crypto.pseudoRandomBytes(8, common.mustCall());
crypto.pbkdf2('password', 'salt', 8, 8, 'sha1', common.mustCall());
crypto.pseudoRandomBytes(8, common.mustSucceed());
crypto.pbkdf2('password', 'salt', 8, 8, 'sha1', common.mustSucceed());
@@ -0,0 +1,52 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
common.skipIfEslintMissing();
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
const rule = require('../../tools/eslint-rules/prefer-common-mustsucceed');
const msg1 = 'Please use common.mustSucceed instead of ' +
'common.mustCall(assert.ifError).';
const msg2 = 'Please use common.mustSucceed instead of ' +
'common.mustCall with assert.ifError.';
new RuleTester({
parserOptions: { ecmaVersion: 2015 }
}).run('prefer-common-mustsucceed', rule, {
valid: [
'foo((err) => assert.ifError(err))',
'foo(function(err) { assert.ifError(err) })',
'foo(assert.ifError)',
'common.mustCall((err) => err)'
],
invalid: [
{
code: 'common.mustCall(assert.ifError)',
errors: [{ message: msg1 }]
},
{
code: 'common.mustCall((err) => assert.ifError(err))',
errors: [{ message: msg2 }]
},
{
code: 'common.mustCall((e) => assert.ifError(e))',
errors: [{ message: msg2 }]
},
{
code: 'common.mustCall(function(e) { assert.ifError(e); })',
errors: [{ message: msg2 }]
},
{
code: 'common.mustCall(function(e) { return assert.ifError(e); })',
errors: [{ message: msg2 }]
},
{
code: 'common.mustCall(function(e) {{ assert.ifError(e); }})',
errors: [{ message: msg2 }]
}
]
});
+10 -26
View File
@@ -45,11 +45,8 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
{
const filename = join(tmpdir.path, 'append.txt');
fs.appendFile(filename, s, common.mustCall(function(e) {
assert.ifError(e);
fs.readFile(filename, common.mustCall(function(e, buffer) {
assert.ifError(e);
fs.appendFile(filename, s, common.mustSucceed(() => {
fs.readFile(filename, common.mustSucceed((buffer) => {
assert.strictEqual(Buffer.byteLength(s), buffer.length);
}));
}));
@@ -72,11 +69,8 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
const filename = join(tmpdir.path, 'append-non-empty.txt');
fs.writeFileSync(filename, currentFileData);
fs.appendFile(filename, s, common.mustCall(function(e) {
assert.ifError(e);
fs.readFile(filename, common.mustCall(function(e, buffer) {
assert.ifError(e);
fs.appendFile(filename, s, common.mustSucceed(() => {
fs.readFile(filename, common.mustSucceed((buffer) => {
assert.strictEqual(Buffer.byteLength(s) + currentFileData.length,
buffer.length);
}));
@@ -104,11 +98,8 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
const buf = Buffer.from(s, 'utf8');
fs.appendFile(filename, buf, common.mustCall((e) => {
assert.ifError(e);
fs.readFile(filename, common.mustCall((e, buffer) => {
assert.ifError(e);
fs.appendFile(filename, buf, common.mustSucceed(() => {
fs.readFile(filename, common.mustSucceed((buffer) => {
assert.strictEqual(buf.length + currentFileData.length, buffer.length);
}));
}));
@@ -166,17 +157,10 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
const filename = join(tmpdir.path, 'append-descriptors.txt');
fs.writeFileSync(filename, currentFileData);
fs.open(filename, 'a+', common.mustCall((e, fd) => {
assert.ifError(e);
fs.appendFile(fd, s, common.mustCall((e) => {
assert.ifError(e);
fs.close(fd, common.mustCall((e) => {
assert.ifError(e);
fs.readFile(filename, common.mustCall((e, buffer) => {
assert.ifError(e);
fs.open(filename, 'a+', common.mustSucceed((fd) => {
fs.appendFile(fd, s, common.mustSucceed(() => {
fs.close(fd, common.mustSucceed(() => {
fs.readFile(filename, common.mustSucceed((buffer) => {
assert.strictEqual(Buffer.byteLength(s) + currentFileData.length,
buffer.length);
}));
+5 -8
View File
@@ -9,13 +9,12 @@ const path = require('path');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
fs.access(Buffer.from(tmpdir.path), common.mustCall(assert.ifError));
fs.access(Buffer.from(tmpdir.path), common.mustSucceed());
const buf = Buffer.from(path.join(tmpdir.path, 'a.txt'));
fs.open(buf, 'w+', common.mustCall((err, fd) => {
assert.ifError(err);
fs.open(buf, 'w+', common.mustSucceed((fd) => {
assert(fd);
fs.close(fd, common.mustCall(assert.ifError));
fs.close(fd, common.mustSucceed());
}));
assert.throws(
@@ -31,10 +30,8 @@ assert.throws(
);
const dir = Buffer.from(fixtures.fixturesDir);
fs.readdir(dir, 'hex', common.mustCall((err, hexList) => {
assert.ifError(err);
fs.readdir(dir, common.mustCall((err, stringList) => {
assert.ifError(err);
fs.readdir(dir, 'hex', common.mustSucceed((hexList) => {
fs.readdir(dir, common.mustSucceed((stringList) => {
stringList.forEach((val, idx) => {
const fromHexList = Buffer.from(hexList[idx], 'hex').toString();
assert.strictEqual(
+4 -9
View File
@@ -29,8 +29,7 @@ function test(mode, asString) {
const file = path.join(tmpdir.path, `chmod-async-${suffix}.txt`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.chmod(file, input, common.mustCall((err) => {
assert.ifError(err);
fs.chmod(file, input, common.mustSucceed(() => {
assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
}));
}
@@ -46,11 +45,8 @@ function test(mode, asString) {
{
const file = path.join(tmpdir.path, `fchmod-async-${suffix}.txt`);
fs.writeFileSync(file, 'test', 'utf-8');
fs.open(file, 'w', common.mustCall((err, fd) => {
assert.ifError(err);
fs.fchmod(fd, input, common.mustCall((err) => {
assert.ifError(err);
fs.open(file, 'w', common.mustSucceed((fd) => {
fs.fchmod(fd, input, common.mustSucceed(() => {
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
fs.close(fd, assert.ifError);
}));
@@ -74,8 +70,7 @@ function test(mode, asString) {
fs.writeFileSync(file, 'test', 'utf-8');
fs.symlinkSync(file, link);
fs.lchmod(link, input, common.mustCall((err) => {
assert.ifError(err);
fs.lchmod(link, input, common.mustSucceed(() => {
assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode);
}));
}
+4 -12
View File
@@ -80,9 +80,7 @@ const file2 = path.join(tmpdir.path, 'a1.js');
// Create file1.
fs.closeSync(fs.openSync(file1, 'w'));
fs.chmod(file1, mode_async.toString(8), common.mustCall((err) => {
assert.ifError(err);
fs.chmod(file1, mode_async.toString(8), common.mustSucceed(() => {
if (common.isWindows) {
assert.ok((fs.statSync(file1).mode & 0o777) & mode_async);
} else {
@@ -97,12 +95,8 @@ fs.chmod(file1, mode_async.toString(8), common.mustCall((err) => {
}
}));
fs.open(file2, 'w', common.mustCall((err, fd) => {
assert.ifError(err);
fs.fchmod(fd, mode_async.toString(8), common.mustCall((err) => {
assert.ifError(err);
fs.open(file2, 'w', common.mustSucceed((fd) => {
fs.fchmod(fd, mode_async.toString(8), common.mustSucceed(() => {
if (common.isWindows) {
assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_async);
} else {
@@ -136,9 +130,7 @@ if (fs.lchmod) {
fs.symlinkSync(file2, link);
fs.lchmod(link, mode_async, common.mustCall((err) => {
assert.ifError(err);
fs.lchmod(link, mode_async, common.mustSucceed(() => {
assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode_async);
fs.lchmodSync(link, mode_sync);
+1 -2
View File
@@ -76,8 +76,7 @@ try {
// Copies asynchronously.
tmpdir.refresh(); // Don't use unlinkSync() since the last test may fail.
fs.copyFile(src, dest, common.mustCall((err) => {
assert.ifError(err);
fs.copyFile(src, dest, common.mustSucceed(() => {
verify(src, dest);
// Copy asynchronously with flags.
+2 -8
View File
@@ -27,10 +27,7 @@ const fixtures = require('../common/fixtures');
const emptyFile = fixtures.path('empty.txt');
fs.open(emptyFile, 'r', common.mustCall((error, fd) => {
assert.ifError(error);
fs.open(emptyFile, 'r', common.mustSucceed((fd) => {
const read = fs.createReadStream(emptyFile, { fd });
read.once('data', common.mustNotCall('data event should not emit'));
@@ -38,10 +35,7 @@ fs.open(emptyFile, 'r', common.mustCall((error, fd) => {
read.once('end', common.mustCall());
}));
fs.open(emptyFile, 'r', common.mustCall((error, fd) => {
assert.ifError(error);
fs.open(emptyFile, 'r', common.mustSucceed((fd) => {
const read = fs.createReadStream(emptyFile, { fd });
read.pause();
+1 -3
View File
@@ -31,6 +31,4 @@ for (let i = 0; i < 50; i++) {
assert(fs.existsSync(dir), 'Directory is not accessible');
// Test if file exists asynchronously
fs.access(dir, common.mustCall((err) => {
assert.ifError(err);
}));
fs.access(dir, common.mustSucceed());
+3 -7
View File
@@ -35,17 +35,13 @@ const fileTemp = path.join(tmpdir.path, 'a.js');
tmpdir.refresh();
fs.copyFileSync(fileFixture, fileTemp);
fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) {
assert.ifError(err);
fs.open(fileTemp, 'a', 0o777, common.mustSucceed((fd) => {
fs.fdatasyncSync(fd);
fs.fsyncSync(fd);
fs.fdatasync(fd, common.mustCall(function(err) {
assert.ifError(err);
fs.fsync(fd, common.mustCall(function(err) {
assert.ifError(err);
fs.fdatasync(fd, common.mustSucceed(() => {
fs.fsync(fd, common.mustSucceed(() => {
fs.closeSync(fd);
}));
}));
+1 -2
View File
@@ -58,8 +58,7 @@ if (!common.isWindows) {
tmpdir.refresh();
fs.copyFileSync(__filename, testFile);
fs.lchownSync(testFile, uid, gid);
fs.lchown(testFile, uid, gid, common.mustCall(async (err) => {
assert.ifError(err);
fs.lchown(testFile, uid, gid, common.mustSucceed(async (err) => {
await promises.lchown(testFile, uid, gid);
}));
}
+2 -7
View File
@@ -26,7 +26,6 @@ if (!common.isWindows)
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const tmpdir = require('../common/tmpdir');
@@ -42,10 +41,6 @@ console.log({
fullPathLength: fullPath.length
});
fs.writeFile(fullPath, 'ok', common.mustCall(function(err) {
assert.ifError(err);
fs.stat(fullPath, common.mustCall(function(err, stats) {
assert.ifError(err);
}));
fs.writeFile(fullPath, 'ok', common.mustSucceed(() => {
fs.stat(fullPath, common.mustSucceed());
}));
+1 -2
View File
@@ -31,8 +31,7 @@ function test(mode, asString) {
{
const dir = path.join(tmpdir.path, `mkdir-${suffix}`);
fs.mkdir(dir, input, common.mustCall((err) => {
assert.ifError(err);
fs.mkdir(dir, input, common.mustSucceed(() => {
assert.strictEqual(fs.statSync(dir).mode & 0o777, mode);
}));
}
+1 -3
View File
@@ -25,9 +25,7 @@ fs.rmdirSync(d);
assert(!fs.existsSync(d));
// Similarly test the Async version
fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.ifError(err);
fs.mkdir(d, 0o666, common.mustSucceed(() => {
fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.strictEqual(this, undefined);
assert.ok(err, 'got no error');
+1 -2
View File
@@ -89,8 +89,7 @@ if (common.isLinux || common.isOSX) {
tmpdir.refresh();
const file = path.join(tmpdir.path, 'a.js');
fs.copyFileSync(fixtures.path('a.js'), file);
fs.open(file, O_DSYNC, common.mustCall((err, fd) => {
assert.ifError(err);
fs.open(file, O_DSYNC, common.mustSucceed((fd) => {
fs.closeSync(fd);
}));
}
+1 -2
View File
@@ -29,8 +29,7 @@ function test(mode, asString) {
{
const file = path.join(tmpdir.path, `open-${suffix}.txt`);
fs.open(file, 'w+', input, common.mustCall((err, fd) => {
assert.ifError(err);
fs.open(file, 'w+', input, common.mustSucceed((fd) => {
assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
fs.closeSync(fd);
assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
+5 -15
View File
@@ -38,25 +38,15 @@ assert.strictEqual(caughtException, true);
fs.openSync(__filename);
fs.open(__filename, common.mustCall((err) => {
assert.ifError(err);
}));
fs.open(__filename, common.mustSucceed());
fs.open(__filename, 'r', common.mustCall((err) => {
assert.ifError(err);
}));
fs.open(__filename, 'r', common.mustSucceed());
fs.open(__filename, 'rs', common.mustCall((err) => {
assert.ifError(err);
}));
fs.open(__filename, 'rs', common.mustSucceed());
fs.open(__filename, 'r', 0, common.mustCall((err) => {
assert.ifError(err);
}));
fs.open(__filename, 'r', 0, common.mustSucceed());
fs.open(__filename, 'r', null, common.mustCall((err) => {
assert.ifError(err);
}));
fs.open(__filename, 'r', null, common.mustSucceed());
async function promise() {
await fs.promises.open(__filename);
+2 -5
View File
@@ -65,8 +65,7 @@ const invalidCallbackObj = {
}
// Check the opendir async version
fs.opendir(testDir, common.mustCall(function(err, dir) {
assert.ifError(err);
fs.opendir(testDir, common.mustSucceed((dir) => {
let sync = true;
dir.read(common.mustCall((err, dirent) => {
assert(!sync);
@@ -81,9 +80,7 @@ fs.opendir(testDir, common.mustCall(function(err, dir) {
assert(!syncInner);
assert.ifError(err);
dir.close(common.mustCall(function(err) {
assert.ifError(err);
}));
dir.close(common.mustSucceed());
}));
syncInner = false;
}));
+2 -4
View File
@@ -35,8 +35,7 @@ function test(bufferAsync, bufferSync, expected) {
0,
expected.length,
0,
common.mustCall((err, bytesRead) => {
assert.ifError(err);
common.mustSucceed((bytesRead) => {
assert.strictEqual(bytesRead, expected.length);
assert.deepStrictEqual(bufferAsync, expected);
}));
@@ -62,8 +61,7 @@ test(new Uint8Array(expected.length),
const nRead = fs.readSync(fd, Buffer.alloc(1), 0, 1, pos);
assert.strictEqual(nRead, 0);
fs.read(fd, Buffer.alloc(1), 0, 1, pos, common.mustCall((err, nRead) => {
assert.ifError(err);
fs.read(fd, Buffer.alloc(1), 0, 1, pos, common.mustSucceed((nRead) => {
assert.strictEqual(nRead, 0);
}));
}
+2 -4
View File
@@ -67,8 +67,7 @@ fs.readdir(__filename, {
// Check the readdir async version
fs.readdir(readdirDir, {
withFileTypes: true
}, common.mustCall((err, dirents) => {
assert.ifError(err);
}, common.mustSucceed((dirents) => {
assertDirents(dirents);
}));
@@ -104,8 +103,7 @@ binding.readdir = common.mustCall((path, encoding, types, req, ctx) => {
assertDirents(fs.readdirSync(readdirDir, { withFileTypes: true }));
fs.readdir(readdirDir, {
withFileTypes: true
}, common.mustCall((err, dirents) => {
assert.ifError(err);
}, common.mustSucceed((dirents) => {
assertDirents(dirents);
}));
+1 -2
View File
@@ -23,8 +23,7 @@ try {
throw e;
}
fs.readdir(tmpdir.path, 'ucs2', common.mustCall((err, list) => {
assert.ifError(err);
fs.readdir(tmpdir.path, 'ucs2', common.mustSucceed((list) => {
assert.strictEqual(list.length, 1);
const fn = list[0];
assert.deepStrictEqual(Buffer.from(fn, 'ucs2'), filebuff);
+1 -2
View File
@@ -21,8 +21,7 @@ files.forEach(function(currentFile) {
assert.deepStrictEqual(files, fs.readdirSync(readdirDir).sort());
// Check the readdir async version
fs.readdir(readdirDir, common.mustCall(function(err, f) {
assert.ifError(err);
fs.readdir(readdirDir, common.mustSucceed((f) => {
assert.deepStrictEqual(files, f.sort());
}));
+3 -6
View File
@@ -75,18 +75,15 @@ function tempFdSync(callback) {
{
// Tests the fs.readFile().
fs.open(filename, 'r', common.mustCall((err, fd) => {
assert.ifError(err);
fs.open(filename, 'r', common.mustSucceed((fd) => {
const buf = Buffer.alloc(5);
// Read only five bytes, so that the position moves to five.
fs.read(fd, buf, 0, 5, null, common.mustCall((err, bytes) => {
assert.ifError(err);
fs.read(fd, buf, 0, 5, null, common.mustSucceed((bytes) => {
assert.strictEqual(bytes, 5);
assert.deepStrictEqual(buf.toString(), 'Hello');
fs.readFile(fd, common.mustCall((err, data) => {
assert.ifError(err);
fs.readFile(fd, common.mustSucceed((data) => {
// readFile() should read from position five, instead of zero.
assert.deepStrictEqual(data.toString(), ' World');
+1 -2
View File
@@ -29,8 +29,7 @@ const exec = require('child_process').exec;
const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
exec(cmd, { maxBuffer: 1000000 }, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
exec(cmd, { maxBuffer: 1000000 }, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(
stdout,
dataExpected,
+2 -4
View File
@@ -31,8 +31,7 @@ const assert = require('assert');
const fs = require('fs');
if (process.argv[2] === 'child') {
fs.readFile('/dev/stdin', common.mustCall(function(er, data) {
assert.ifError(er);
fs.readFile('/dev/stdin', common.mustSucceed((data) => {
process.stdout.write(data);
}));
return;
@@ -47,8 +46,7 @@ const exec = require('child_process').exec;
const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
exec(cmd, common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
exec(cmd, common.mustSucceed((stdout, stderr) => {
assert.strictEqual(
stdout,
dataExpected,
+1 -2
View File
@@ -37,8 +37,7 @@ tmpdir.refresh();
fs.writeFileSync(fileName, buf);
fs.readFile(fileName, common.mustCall((err, data) => {
assert.ifError(err);
fs.readFile(fileName, common.mustSucceed((data) => {
assert.strictEqual(data.length, buf.length);
assert.strictEqual(buf[0], 42);
+1 -2
View File
@@ -18,8 +18,7 @@ function test(p) {
const result = fs.realpathSync(p);
assert.strictEqual(result.toLowerCase(), path.resolve(p).toLowerCase());
fs.realpath(p, common.mustCall(function(err, result) {
assert.ok(!err);
fs.realpath(p, common.mustSucceed((result) => {
assert.strictEqual(result.toLowerCase(), path.resolve(p).toLowerCase());
}));
}
@@ -29,8 +29,7 @@ const cmd = `cat ${filename} | ${node} ${f} child`;
exec(
cmd,
{ maxBuffer: 1000000 },
common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
common.mustSucceed((stdout, stderr) => {
assert.strictEqual(stdout, dataExpected);
assert.strictEqual(stderr, '');
console.log('ok');
+1 -3
View File
@@ -24,9 +24,7 @@ const allocateEmptyBuffers = (combinedLength) => {
};
const getCallback = (fd, bufferArr) => {
return common.mustCall((err, bytesRead, buffers) => {
assert.ifError(err);
return common.mustSucceed((bytesRead, buffers) => {
assert.deepStrictEqual(bufferArr, buffers);
const expectedLength = exptectedBuff.length;
assert.deepStrictEqual(bytesRead, expectedLength);
@@ -54,45 +54,37 @@ for (encoding in expected) {
fs.realpath(
string_dir,
{ encoding },
common.mustCall((err, res) => {
assert.ifError(err);
common.mustSucceed((res) => {
assert.strictEqual(res, expected_value);
})
);
fs.realpath(string_dir, encoding, common.mustCall((err, res) => {
assert.ifError(err);
fs.realpath(string_dir, encoding, common.mustSucceed((res) => {
assert.strictEqual(res, expected_value);
}));
fs.realpath(
buffer_dir,
{ encoding },
common.mustCall((err, res) => {
assert.ifError(err);
common.mustSucceed((res) => {
assert.strictEqual(res, expected_value);
})
);
fs.realpath(buffer_dir, encoding, common.mustCall((err, res) => {
assert.ifError(err);
fs.realpath(buffer_dir, encoding, common.mustSucceed((res) => {
assert.strictEqual(res, expected_value);
}));
}
fs.realpath(string_dir, { encoding: 'buffer' }, common.mustCall((err, res) => {
assert.ifError(err);
fs.realpath(string_dir, { encoding: 'buffer' }, common.mustSucceed((res) => {
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(string_dir, 'buffer', common.mustCall((err, res) => {
assert.ifError(err);
fs.realpath(string_dir, 'buffer', common.mustSucceed((res) => {
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(buffer_dir, { encoding: 'buffer' }, common.mustCall((err, res) => {
assert.ifError(err);
fs.realpath(buffer_dir, { encoding: 'buffer' }, common.mustSucceed((res) => {
assert.deepStrictEqual(res, buffer_dir);
}));
fs.realpath(buffer_dir, 'buffer', common.mustCall((err, res) => {
assert.ifError(err);
fs.realpath(buffer_dir, 'buffer', common.mustSucceed((res) => {
assert.deepStrictEqual(res, buffer_dir);
}));
+1 -2
View File
@@ -12,8 +12,7 @@ assert.strictEqual(
fs.realpath.native(
'./test/parallel/test-fs-realpath-native.js',
common.mustCall(function(err, res) {
assert.ifError(err);
common.mustSucceed(function(res) {
assert.strictEqual(res.toLowerCase(), filename);
assert.strictEqual(this, undefined);
}));
@@ -41,13 +41,11 @@ result = fs.realpathSync(filename, 'buffer');
assert(Buffer.isBuffer(result));
assert(result.equals(filenameBuffer));
fs.realpath(filename, common.mustCall(function(err, result) {
assert.ifError(err);
fs.realpath(filename, common.mustSucceed((result) => {
assert.strictEqual(result, filename);
}));
fs.realpath(filename, 'buffer', common.mustCall(function(err, result) {
assert.ifError(err);
fs.realpath(filename, 'buffer', common.mustSucceed((result) => {
assert(Buffer.isBuffer(result));
assert(result.equals(filenameBuffer));
}));
+1 -2
View File
@@ -564,8 +564,7 @@ function runNextTest(err) {
return console.log(`${numtests} subtests completed OK for fs.realpath`);
}
testsRun++;
test(fs.realpath, fs.realpathSync, common.mustCall((err) => {
assert.ifError(err);
test(fs.realpath, fs.realpathSync, common.mustSucceed(() => {
testsRun++;
test(fs.realpath.native,
fs.realpathSync.native,
+1 -2
View File
@@ -72,8 +72,7 @@ function removeAsync(dir) {
assert.strictEqual(err.syscall, 'rm');
// Recursive removal should succeed.
fs.rm(dir, { recursive: true }, common.mustCall((err) => {
assert.ifError(err);
fs.rm(dir, { recursive: true }, common.mustSucceed(() => {
// Attempted removal should fail now because the directory is gone.
fs.rm(dir, common.mustCall((err) => {
+2 -6
View File
@@ -72,13 +72,9 @@ function removeAsync(dir) {
assert.strictEqual(err.syscall, 'rmdir');
// Recursive removal should succeed.
fs.rmdir(dir, { recursive: true }, common.mustCall((err) => {
assert.ifError(err);
fs.rmdir(dir, { recursive: true }, common.mustSucceed(() => {
// No error should occur if recursive and the directory does not exist.
fs.rmdir(dir, { recursive: true }, common.mustCall((err) => {
assert.ifError(err);
fs.rmdir(dir, { recursive: true }, common.mustSucceed(() => {
// Attempted removal should fail now because the directory is gone.
fs.rmdir(dir, common.mustCall((err) => {
assert.strictEqual(err.syscall, 'rmdir');
+6 -11
View File
@@ -25,8 +25,7 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
fs.stat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
fs.stat('.', common.mustSucceed(function(stats) {
assert.ok(stats.mtime instanceof Date);
assert.ok(stats.hasOwnProperty('blksize'));
assert.ok(stats.hasOwnProperty('blocks'));
@@ -36,8 +35,7 @@ fs.stat('.', common.mustCall(function(err, stats) {
assert.strictEqual(this, undefined);
}));
fs.lstat('.', common.mustCall(function(err, stats) {
assert.ifError(err);
fs.lstat('.', common.mustSucceed(function(stats) {
assert.ok(stats.mtime instanceof Date);
// Confirm that we are not running in the context of the internal binding
// layer.
@@ -46,12 +44,10 @@ fs.lstat('.', common.mustCall(function(err, stats) {
}));
// fstat
fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
assert.ifError(err);
fs.open('.', 'r', undefined, common.mustSucceed(function(fd) {
assert.ok(fd);
fs.fstat(fd, common.mustCall(function(err, stats) {
assert.ifError(err);
fs.fstat(fd, common.mustSucceed(function(stats) {
assert.ok(stats.mtime instanceof Date);
fs.close(fd, assert.ifError);
// Confirm that we are not running in the context of the internal binding
@@ -70,11 +66,10 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
const stats = fs.fstatSync(fd);
assert.ok(stats.mtime instanceof Date);
fs.close(fd, common.mustCall(assert.ifError));
fs.close(fd, common.mustSucceed());
}));
fs.stat(__filename, common.mustCall(function(err, s) {
assert.ifError(err);
fs.stat(__filename, common.mustSucceed((s) => {
assert.strictEqual(s.isDirectory(), false);
assert.strictEqual(s.isFile(), true);
assert.strictEqual(s.isSocket(), false);
@@ -38,8 +38,7 @@ const linkData = fixtures.fixturesDir;
tmpdir.refresh();
// Test fs.symlink()
fs.symlink(linkData, linkPath1, 'junction', common.mustCall(function(err) {
assert.ifError(err);
fs.symlink(linkData, linkPath1, 'junction', common.mustSucceed(() => {
verifyLink(linkPath1);
}));
+6 -14
View File
@@ -34,19 +34,14 @@ const linkPath = path.join(tmpdir.path, 'cycles_link');
tmpdir.refresh();
fs.symlink(linkData, linkPath, 'junction', common.mustCall(function(err) {
assert.ifError(err);
fs.lstat(linkPath, common.mustCall(function(err, stats) {
assert.ifError(err);
fs.symlink(linkData, linkPath, 'junction', common.mustSucceed(() => {
fs.lstat(linkPath, common.mustSucceed((stats) => {
assert.ok(stats.isSymbolicLink());
fs.readlink(linkPath, common.mustCall(function(err, destination) {
assert.ifError(err);
fs.readlink(linkPath, common.mustSucceed((destination) => {
assert.strictEqual(destination, linkData);
fs.unlink(linkPath, common.mustCall(function(err) {
assert.ifError(err);
fs.unlink(linkPath, common.mustSucceed(() => {
assert(!fs.existsSync(linkPath));
assert(fs.existsSync(linkData));
}));
@@ -59,13 +54,10 @@ fs.symlink(linkData, linkPath, 'junction', common.mustCall(function(err) {
const linkData = fixtures.path('/not/exists/dir');
const linkPath = path.join(tmpdir.path, 'invalid_junction_link');
fs.symlink(linkData, linkPath, 'junction', common.mustCall(function(err) {
assert.ifError(err);
fs.symlink(linkData, linkPath, 'junction', common.mustSucceed(() => {
assert(!fs.existsSync(linkPath));
fs.unlink(linkPath, common.mustCall(function(err) {
assert.ifError(err);
fs.unlink(linkPath, common.mustSucceed(() => {
assert(!fs.existsSync(linkPath));
}));
}));
+2 -4
View File
@@ -31,8 +31,7 @@ function testSync(target, path) {
}
function testAsync(target, path) {
fs.symlink(target, path, common.mustCall((err) => {
assert.ifError(err);
fs.symlink(target, path, common.mustSucceed(() => {
fs.readdirSync(path);
}));
}
@@ -53,8 +52,7 @@ for (const linkTarget of linkTargets) {
}
function testAsync(target, path) {
fs.symlink(target, path, common.mustCall((err) => {
assert.ifError(err);
fs.symlink(target, path, common.mustSucceed(() => {
assert(!fs.existsSync(path));
}));
}
+2 -4
View File
@@ -15,15 +15,13 @@ fs.mkdirSync(longPath, { recursive: true });
const targetDirtectory = path.join(longPath, 'target-directory');
fs.mkdirSync(targetDirtectory);
const pathDirectory = path.join(tmpDir, 'new-directory');
fs.symlink(targetDirtectory, pathDirectory, 'dir', common.mustCall((err) => {
assert.ifError(err);
fs.symlink(targetDirtectory, pathDirectory, 'dir', common.mustSucceed(() => {
assert(fs.existsSync(pathDirectory));
}));
const targetFile = path.join(longPath, 'target-file');
fs.writeFileSync(targetFile, 'data');
const pathFile = path.join(tmpDir, 'new-file');
fs.symlink(targetFile, pathFile, common.mustCall((err) => {
assert.ifError(err);
fs.symlink(targetFile, pathFile, common.mustSucceed(() => {
assert(fs.existsSync(pathFile));
}));
+5 -12
View File
@@ -39,21 +39,16 @@ tmpdir.refresh();
const linkData = fixtures.path('/cycles/root.js');
const linkPath = path.join(tmpdir.path, 'symlink1.js');
fs.symlink(linkData, linkPath, common.mustCall(function(err) {
assert.ifError(err);
fs.lstat(linkPath, common.mustCall(function(err, stats) {
assert.ifError(err);
fs.symlink(linkData, linkPath, common.mustSucceed(() => {
fs.lstat(linkPath, common.mustSucceed((stats) => {
linkTime = stats.mtime.getTime();
}));
fs.stat(linkPath, common.mustCall(function(err, stats) {
assert.ifError(err);
fs.stat(linkPath, common.mustSucceed((stats) => {
fileTime = stats.mtime.getTime();
}));
fs.readlink(linkPath, common.mustCall(function(err, destination) {
assert.ifError(err);
fs.readlink(linkPath, common.mustSucceed((destination) => {
assert.strictEqual(destination, linkData);
}));
}));
@@ -63,9 +58,7 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) {
const linkData = fixtures.path('/not/exists/file');
const linkPath = path.join(tmpdir.path, 'symlink2.js');
fs.symlink(linkData, linkPath, common.mustCall(function(err) {
assert.ifError(err);
fs.symlink(linkData, linkPath, common.mustSucceed(() => {
assert(!fs.existsSync(linkPath));
}));
}
@@ -49,8 +49,7 @@ tmpdir.refresh();
fs.truncate(
filename,
5,
common.mustCall(function(err) {
assert.ifError(err);
common.mustSucceed(() => {
assert.strictEqual(fs.readFileSync(filename).toString(), '01234');
})
);
+1 -2
View File
@@ -16,8 +16,7 @@ const msg = 'Using fs.truncate with a file descriptor is deprecated.' +
common.expectWarning('DeprecationWarning', msg, 'DEP0081');
fs.truncate(fd, 5, common.mustCall((err) => {
assert.ok(!err);
fs.truncate(fd, 5, common.mustSucceed(() => {
assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello');
}));
+7 -13
View File
@@ -71,9 +71,8 @@ fs.truncateSync(fd);
fs.closeSync(fd);
// Async tests
testTruncate(common.mustCall(function(er) {
assert.ifError(er);
testFtruncate(common.mustCall(assert.ifError));
testTruncate(common.mustSucceed(() => {
testFtruncate(common.mustSucceed());
}));
function testTruncate(cb) {
@@ -155,8 +154,7 @@ function testFtruncate(cb) {
{
const file3 = path.resolve(tmp, 'truncate-file-3.txt');
fs.writeFileSync(file3, 'Hi');
fs.truncate(file3, 4, common.mustCall(function(err) {
assert.ifError(err);
fs.truncate(file3, 4, common.mustSucceed(() => {
assert(fs.readFileSync(file3).equals(Buffer.from('Hi\u0000\u0000')));
}));
}
@@ -166,8 +164,7 @@ function testFtruncate(cb) {
fs.writeFileSync(file4, 'Hi');
const fd = fs.openSync(file4, 'r+');
process.on('beforeExit', () => fs.closeSync(fd));
fs.ftruncate(fd, 4, common.mustCall(function(err) {
assert.ifError(err);
fs.ftruncate(fd, 4, common.mustSucceed(() => {
assert(fs.readFileSync(file4).equals(Buffer.from('Hi\u0000\u0000')));
}));
}
@@ -221,8 +218,7 @@ function testFtruncate(cb) {
);
});
fs.ftruncate(fd, undefined, common.mustCall(function(err) {
assert.ifError(err);
fs.ftruncate(fd, undefined, common.mustSucceed(() => {
assert(fs.readFileSync(file5).equals(Buffer.from('')));
}));
}
@@ -232,8 +228,7 @@ function testFtruncate(cb) {
fs.writeFileSync(file6, 'Hi');
const fd = fs.openSync(file6, 'r+');
process.on('beforeExit', () => fs.closeSync(fd));
fs.ftruncate(fd, -1, common.mustCall(function(err) {
assert.ifError(err);
fs.ftruncate(fd, -1, common.mustSucceed(() => {
assert(fs.readFileSync(file6).equals(Buffer.from('')));
}));
}
@@ -241,8 +236,7 @@ function testFtruncate(cb) {
{
const file7 = path.resolve(tmp, 'truncate-file-7.txt');
fs.writeFileSync(file7, 'Hi');
fs.truncate(file7, undefined, common.mustCall(function(err) {
assert.ifError(err);
fs.truncate(file7, undefined, common.mustSucceed(() => {
assert(fs.readFileSync(file7).equals(Buffer.from('')));
}));
}
+1 -2
View File
@@ -22,8 +22,7 @@ const url = pathToFileURL(p);
assert(url instanceof URL);
// Check that we can pass in a URL object successfully
fs.readFile(url, common.mustCall((err, data) => {
assert.ifError(err);
fs.readFile(url, common.mustSucceed((data) => {
assert(Buffer.isBuffer(data));
}));
+13 -39
View File
@@ -32,12 +32,8 @@ tmpdir.refresh();
// fs.write with all parameters provided:
{
const filename = path.join(tmpdir.path, 'write1.txt');
fs.open(filename, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const cb = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
fs.closeSync(fd);
@@ -52,12 +48,8 @@ tmpdir.refresh();
// fs.write with a buffer, without the length parameter:
{
const filename = path.join(tmpdir.path, 'write2.txt');
fs.open(filename, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const cb = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, 2);
fs.closeSync(fd);
@@ -72,12 +64,8 @@ tmpdir.refresh();
// fs.write with a buffer, without the offset and length parameters:
{
const filename = path.join(tmpdir.path, 'write3.txt');
fs.open(filename, 'w', 0o644, common.mustCall(function(err, fd) {
assert.ifError(err);
const cb = common.mustCall(function(err, written) {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
fs.closeSync(fd);
@@ -92,12 +80,8 @@ tmpdir.refresh();
// fs.write with the offset passed as undefined followed by the callback:
{
const filename = path.join(tmpdir.path, 'write4.txt');
fs.open(filename, 'w', 0o644, common.mustCall(function(err, fd) {
assert.ifError(err);
const cb = common.mustCall(function(err, written) {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
fs.closeSync(fd);
@@ -112,12 +96,8 @@ tmpdir.refresh();
// fs.write with offset and length passed as undefined followed by the callback:
{
const filename = path.join(tmpdir.path, 'write5.txt');
fs.open(filename, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const cb = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
fs.closeSync(fd);
@@ -132,12 +112,8 @@ tmpdir.refresh();
// fs.write with a Uint8Array, without the offset and length parameters:
{
const filename = path.join(tmpdir.path, 'write6.txt');
fs.open(filename, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const cb = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
const cb = common.mustSucceed((written) => {
assert.strictEqual(written, expected.length);
fs.closeSync(fd);
@@ -152,9 +128,7 @@ tmpdir.refresh();
// fs.write with invalid offset type
{
const filename = path.join(tmpdir.path, 'write7.txt');
fs.open(filename, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => {
assert.throws(() => {
fs.write(fd,
Buffer.from('abcd'),
@@ -33,11 +33,8 @@ for (const expectView of common.getArrayBufferViews(inputBuffer)) {
for (const expectView of common.getArrayBufferViews(inputBuffer)) {
console.log('Async test for ', expectView[Symbol.toStringTag]);
const file = `${filename}-${expectView[Symbol.toStringTag]}`;
fs.writeFile(file, expectView, common.mustCall((e) => {
assert.ifError(e);
fs.readFile(file, 'utf8', common.mustCall((err, data) => {
assert.ifError(err);
fs.writeFile(file, expectView, common.mustSucceed(() => {
fs.readFile(file, 'utf8', common.mustSucceed((data) => {
assert.strictEqual(data, inputBuffer.toString('utf8'));
}));
}));
+8 -23
View File
@@ -38,11 +38,8 @@ const s = '南越国是前203年至前111年存在于岭南地区的一个国家
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
fs.writeFile(filename, s, common.mustCall(function(e) {
assert.ifError(e);
fs.readFile(filename, common.mustCall(function(e, buffer) {
assert.ifError(e);
fs.writeFile(filename, s, common.mustSucceed(() => {
fs.readFile(filename, common.mustSucceed((buffer) => {
assert.strictEqual(Buffer.byteLength(s), buffer.length);
}));
}));
@@ -51,12 +48,8 @@ fs.writeFile(filename, s, common.mustCall(function(e) {
const filename2 = join(tmpdir.path, 'test2.txt');
const buf = Buffer.from(s, 'utf8');
fs.writeFile(filename2, buf, common.mustCall(function(e) {
assert.ifError(e);
fs.readFile(filename2, common.mustCall(function(e, buffer) {
assert.ifError(e);
fs.writeFile(filename2, buf, common.mustSucceed(() => {
fs.readFile(filename2, common.mustSucceed((buffer) => {
assert.strictEqual(buf.length, buffer.length);
}));
}));
@@ -64,18 +57,10 @@ fs.writeFile(filename2, buf, common.mustCall(function(e) {
// Test that writeFile accepts file descriptors.
const filename4 = join(tmpdir.path, 'test4.txt');
fs.open(filename4, 'w+', common.mustCall(function(e, fd) {
assert.ifError(e);
fs.writeFile(fd, s, common.mustCall(function(e) {
assert.ifError(e);
fs.close(fd, common.mustCall(function(e) {
assert.ifError(e);
fs.readFile(filename4, common.mustCall(function(e, buffer) {
assert.ifError(e);
fs.open(filename4, 'w+', common.mustSucceed((fd) => {
fs.writeFile(fd, s, common.mustSucceed(() => {
fs.close(fd, common.mustSucceed(() => {
fs.readFile(filename4, common.mustSucceed((buffer) => {
assert.strictEqual(Buffer.byteLength(s), buffer.length);
}));
}));
@@ -19,8 +19,7 @@ const size = 16 * 1024;
const writes = 1000;
let done = 0;
const ondone = common.mustCall((err) => {
assert.ifError(err);
const ondone = common.mustSucceed(() => {
if (++done < writes) {
if (done % 25 === 0) global.gc();
setImmediate(write);
+10 -24
View File
@@ -80,11 +80,8 @@ common.allowGlobals(externalizeString, isOneByteString, x);
}
/* eslint-enable no-undef */
fs.open(fn, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const done = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(fn, 'w', 0o644, common.mustSucceed((fd) => {
const done = common.mustSucceed((written) => {
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
const found = fs.readFileSync(fn, 'utf8');
@@ -92,8 +89,7 @@ fs.open(fn, 'w', 0o644, common.mustCall((err, fd) => {
assert.strictEqual(found, expected);
});
const written = common.mustCall((err, written) => {
assert.ifError(err);
const written = common.mustSucceed((written) => {
assert.strictEqual(written, 0);
fs.write(fd, expected, 0, 'utf8', done);
});
@@ -102,11 +98,8 @@ fs.open(fn, 'w', 0o644, common.mustCall((err, fd) => {
}));
const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const done = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(fn2, args, 0o644, common.mustSucceed((fd) => {
const done = common.mustSucceed((written) => {
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
const found = fs.readFileSync(fn2, 'utf8');
@@ -114,8 +107,7 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
assert.strictEqual(found, expected);
});
const written = common.mustCall((err, written) => {
assert.ifError(err);
const written = common.mustSucceed((written) => {
assert.strictEqual(written, 0);
fs.write(fd, expected, 0, 'utf8', done);
});
@@ -123,11 +115,8 @@ fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
fs.write(fd, '', 0, 'utf8', written);
}));
fs.open(fn3, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const done = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(fn3, 'w', 0o644, common.mustSucceed((fd) => {
const done = common.mustSucceed((written) => {
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
});
@@ -135,11 +124,8 @@ fs.open(fn3, 'w', 0o644, common.mustCall((err, fd) => {
fs.write(fd, expected, done);
}));
fs.open(fn4, 'w', 0o644, common.mustCall((err, fd) => {
assert.ifError(err);
const done = common.mustCall((err, written) => {
assert.ifError(err);
fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => {
const done = common.mustSucceed((written) => {
assert.strictEqual(written, Buffer.byteLength(expected));
fs.closeSync(fd);
});
+3 -8
View File
@@ -38,19 +38,14 @@ tmpdir.refresh();
const file = join(tmpdir.path, 'test1.txt');
/* Open the file descriptor. */
fs.open(file, 'w', common.mustCall((err, fd) => {
assert.ifError(err);
fs.open(file, 'w', common.mustSucceed((fd) => {
/* Write only five characters, so that the position moves to five. */
fs.write(fd, 'Hello', common.mustCall((err, bytes) => {
assert.ifError(err);
fs.write(fd, 'Hello', common.mustSucceed((bytes) => {
assert.strictEqual(bytes, 5);
assert.deepStrictEqual(fs.readFileSync(file).toString(), 'Hello');
/* Write some more with writeFile(). */
fs.writeFile(fd, 'World', common.mustCall((err) => {
assert.ifError(err);
fs.writeFile(fd, 'World', common.mustSucceed(() => {
/* New content should be written at position five, instead of zero. */
assert.deepStrictEqual(fs.readFileSync(file).toString(), 'HelloWorld');
+2 -6
View File
@@ -24,9 +24,7 @@ const getFileName = (i) => path.join(tmpdir.path, `writev_${i}.txt`);
const buffer = Buffer.from(expected);
const bufferArr = [buffer, buffer];
const done = common.mustCall((err, written, buffers) => {
assert.ifError(err);
const done = common.mustSucceed((written, buffers) => {
assert.deepStrictEqual(bufferArr, buffers);
const expectedLength = bufferArr.length * buffer.byteLength;
assert.deepStrictEqual(written, expectedLength);
@@ -46,9 +44,7 @@ const getFileName = (i) => path.join(tmpdir.path, `writev_${i}.txt`);
const buffer = Buffer.from(expected);
const bufferArr = [buffer, buffer];
const done = common.mustCall((err, written, buffers) => {
assert.ifError(err);
const done = common.mustSucceed((written, buffers) => {
assert.deepStrictEqual(bufferArr, buffers);
const expectedLength = bufferArr.length * buffer.byteLength;
@@ -10,8 +10,7 @@ tmpdir.refresh();
server.listen(common.PIPE, common.mustCall(() =>
asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() =>
server.getConnections(common.mustCall((err, conns) => {
assert.ifError(err);
server.getConnections(common.mustSucceed((conns) => {
assert.strictEqual(conns, 1);
server.close();
}))
+2 -2
View File
@@ -1,6 +1,6 @@
'use strict';
const { mustCall, hasCrypto, skip } = require('../common');
const { mustCall, mustSucceed, hasCrypto, skip } = require('../common');
if (!hasCrypto)
skip('missing crypto');
const assert = require('assert');
@@ -42,7 +42,7 @@ const { once } = require('events');
stream.on('data', () => {});
for (let i = 0; i < kTimes; i += 1) {
stream.write(Buffer.allocUnsafe(kBufferSize), mustCall());
stream.write(Buffer.allocUnsafe(kBufferSize), mustSucceed());
const expectedSocketBufferSize = kBufferSize * (i + 1);
assert.strictEqual(stream.bufferSize, expectedSocketBufferSize);
}
@@ -14,9 +14,7 @@ const loc = fixtures.path('person-large.jpg');
assert(fs.existsSync(loc));
fs.readFile(loc, common.mustCall((err, data) => {
assert.ifError(err);
fs.readFile(loc, common.mustSucceed((data) => {
const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
+1 -2
View File
@@ -16,8 +16,7 @@ let fileData;
assert(fs.existsSync(loc));
fs.readFile(loc, common.mustCall((err, data) => {
assert.ifError(err);
fs.readFile(loc, common.mustSucceed((data) => {
fileData = data;
const server = http2.createServer();
@@ -14,9 +14,7 @@ const loc = fixtures.path('person-large.jpg');
assert(fs.existsSync(loc));
fs.readFile(loc, common.mustCall((err, data) => {
assert.ifError(err);
fs.readFile(loc, common.mustSucceed((data) => {
const server = http2.createServer(common.mustCall((req, res) => {
setImmediate(() => {
res.writeHead(400);
Loaded 100 of 140 files, more files were not shown because too many files have changed in this diff. Show more