Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase usage of assert.ifError() #10543

Merged
merged 1 commit into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/disabled/test-dgram-send-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function onMessage(message, info) {
}

function afterSend(err) {
if (err) throw err;
assert.ifError(err);
packetsSent++;
}

Expand Down
2 changes: 1 addition & 1 deletion test/gc/node_modules/nan/tools/1to2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/internet/test-dgram-broadcast-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ if (process.argv[2] !== 'child') {
common.PORT,
LOCAL_BROADCAST_HOST,
function(err) {
if (err) throw err;
assert.ifError(err);
console.error('[PARENT] sent %s to %s:%s',
util.inspect(buf.toString()),
LOCAL_BROADCAST_HOST, common.PORT);
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-dgram-multicast-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ if (process.argv[2] !== 'child') {
common.PORT,
LOCAL_BROADCAST_HOST,
function(err) {
if (err) throw err;
assert.ifError(err);
console.error('[PARENT] sent "%s" to %s:%s',
buf.toString(),
LOCAL_BROADCAST_HOST, common.PORT);
Expand Down
4 changes: 2 additions & 2 deletions test/internet/test-dns-ipv6.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST(function test_lookup_ipv6_explicit(done) {
/* This ends up just being too problematic to test
TEST(function test_lookup_ipv6_implicit(done) {
var req = dns.lookup('ipv6.google.com', function(err, ip, family) {
if (err) throw err;
assert.ifError(err);
assert.ok(net.isIPv6(ip));
assert.strictEqual(family, 6);

Expand Down Expand Up @@ -196,7 +196,7 @@ TEST(function test_lookupservice_ip_ipv6(done) {
/* Disabled because it appears to be not working on linux. */
/* TEST(function test_lookup_localhost_ipv6(done) {
var req = dns.lookup('localhost', 6, function(err, ip, family) {
if (err) throw err;
assert.ifError(err);
assert.ok(net.isIPv6(ip));
assert.strictEqual(family, 6);

Expand Down
31 changes: 12 additions & 19 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ TEST(function test_resolve6_ttl(done) {

TEST(function test_resolveMx(done) {
var req = dns.resolveMx('gmail.com', function(err, result) {
if (err) throw err;

assert.ifError(err);
assert.ok(result.length > 0);

for (var i = 0; i < result.length; i++) {
Expand Down Expand Up @@ -140,8 +139,7 @@ TEST(function test_resolveMx_failure(done) {

TEST(function test_resolveNs(done) {
var req = dns.resolveNs('rackspace.com', function(err, names) {
if (err) throw err;

assert.ifError(err);
assert.ok(names.length > 0);

for (var i = 0; i < names.length; i++) {
Expand Down Expand Up @@ -171,8 +169,7 @@ TEST(function test_resolveNs_failure(done) {

TEST(function test_resolveSrv(done) {
var req = dns.resolveSrv('_jabber._tcp.google.com', function(err, result) {
if (err) throw err;

assert.ifError(err);
assert.ok(result.length > 0);

for (var i = 0; i < result.length; i++) {
Expand Down Expand Up @@ -209,8 +206,7 @@ TEST(function test_resolveSrv_failure(done) {

TEST(function test_resolvePtr(done) {
var req = dns.resolvePtr('8.8.8.8.in-addr.arpa', function(err, result) {
if (err) throw err;

assert.ifError(err);
assert.ok(result.length > 0);

for (var i = 0; i < result.length; i++) {
Expand Down Expand Up @@ -240,8 +236,7 @@ TEST(function test_resolvePtr_failure(done) {

TEST(function test_resolveNaptr(done) {
var req = dns.resolveNaptr('sip2sip.info', function(err, result) {
if (err) throw err;

assert.ifError(err);
assert.ok(result.length > 0);

for (var i = 0; i < result.length; i++) {
Expand Down Expand Up @@ -278,8 +273,7 @@ TEST(function test_resolveNaptr_failure(done) {

TEST(function test_resolveSoa(done) {
var req = dns.resolveSoa('nodejs.org', function(err, result) {
if (err) throw err;

assert.ifError(err);
assert.ok(result);
assert.strictEqual(typeof result, 'object');

Expand Down Expand Up @@ -325,8 +319,7 @@ TEST(function test_resolveSoa_failure(done) {

TEST(function test_resolveCname(done) {
var req = dns.resolveCname('www.microsoft.com', function(err, names) {
if (err) throw err;

assert.ifError(err);
assert.ok(names.length > 0);

for (var i = 0; i < names.length; i++) {
Expand Down Expand Up @@ -357,7 +350,7 @@ TEST(function test_resolveCname_failure(done) {

TEST(function test_resolveTxt(done) {
var req = dns.resolveTxt('google.com', function(err, records) {
if (err) throw err;
assert.ifError(err);
assert.strictEqual(records.length, 1);
assert.ok(util.isArray(records[0]));
assert.strictEqual(records[0][0].indexOf('v=spf1'), 0);
Expand Down Expand Up @@ -398,7 +391,7 @@ TEST(function test_lookup_failure(done) {

TEST(function test_lookup_null(done) {
var req = dns.lookup(null, function(err, ip, family) {
if (err) throw err;
assert.ifError(err);
assert.strictEqual(ip, null);
assert.strictEqual(family, 4);

Expand All @@ -411,7 +404,7 @@ TEST(function test_lookup_null(done) {

TEST(function test_lookup_ip_all(done) {
var req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) {
if (err) throw err;
assert.ifError(err);
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);
assert.strictEqual(ips[0].address, '127.0.0.1');
Expand All @@ -426,7 +419,7 @@ TEST(function test_lookup_ip_all(done) {

TEST(function test_lookup_null_all(done) {
var req = dns.lookup(null, {all: true}, function(err, ips, family) {
if (err) throw err;
assert.ifError(err);
assert.ok(Array.isArray(ips));
assert.strictEqual(ips.length, 0);

Expand All @@ -439,7 +432,7 @@ TEST(function test_lookup_null_all(done) {

TEST(function test_lookup_all_mixed(done) {
var req = dns.lookup('www.google.com', {all: true}, function(err, ips) {
if (err) throw err;
assert.ifError(err);
assert.ok(Array.isArray(ips));
assert.ok(ips.length > 0);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-fork-dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (process.argv[2] === 'child') {
serverPort,
'127.0.0.1',
function(err) {
if (err) throw err;
assert.ifError(err);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-domain-implicit-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ d.run(function() {
var fs = require('fs');
fs.readdir(__dirname, function() {
fs.open('this file does not exist', 'r', function(er) {
if (er) throw er;
assert.ifError(er);
throw new Error('should not get here!');
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-fs-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ common.refreshTmpDir();

assert.doesNotThrow(() => {
fs.access(Buffer.from(common.tmpDir), common.mustCall((err) => {
if (err) throw err;
assert.ifError(err);
}));
});

assert.doesNotThrow(() => {
const buf = Buffer.from(path.join(common.tmpDir, 'a.txt'));
fs.open(buf, 'w+', common.mustCall((err, fd) => {
if (err) throw err;
assert.ifError(err);
assert(fd);
fs.close(fd, common.mustCall(() => {
fs.unlinkSync(buf);
Expand All @@ -30,12 +30,12 @@ assert.throws(() => {

const dir = Buffer.from(common.fixturesDir);
fs.readdir(dir, 'hex', common.mustCall((err, list) => {
if (err) throw err;
assert.ifError(err);
list = list.map((i) => {
return Buffer.from(i, 'hex').toString();
});
fs.readdir(dir, common.mustCall((err, list2) => {
if (err) throw err;
assert.ifError(err);
assert.deepStrictEqual(list, list2);
}));
}));
2 changes: 1 addition & 1 deletion test/parallel/test-fs-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const dstPath = path.join(common.tmpDir, 'link1.js');
fs.writeFileSync(srcPath, 'hello world');

const callback = function(err) {
if (err) throw err;
assert.ifError(err);
const dstContent = fs.readFileSync(dstPath, 'utf8');
assert.strictEqual('hello world', dstContent);
};
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-readdir-ucs2.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const fullpath = Buffer.concat([root, filebuff]);
fs.closeSync(fs.openSync(fullpath, 'w+'));

fs.readdir(common.tmpDir, 'ucs2', (err, list) => {
if (err) throw err;
assert.ifError(err);
assert.equal(1, list.length);
const fn = list[0];
assert.deepStrictEqual(filebuff, Buffer.from(fn, 'ucs2'));
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-fs-readfile-fd.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ tempFdSync(function(fd) {

function tempFd(callback) {
fs.open(fn, 'r', function(err, fd) {
if (err) throw err;

assert.ifError(err);
callback(fd, function() {
fs.close(fd, function(err) {
if (err) throw err;
assert.ifError(err);
});
});
});
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-fs-readfile-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fs = require('fs');

if (process.argv[2] === 'child') {
fs.readFile('/dev/stdin', function(er, data) {
if (er) throw er;
assert.ifError(er);
process.stdout.write(data);
});
return;
Expand All @@ -30,8 +30,7 @@ const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
if (err) console.error(err);
assert(!err, 'it exits normally');
assert.ifError(err);
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
assert.strictEqual(stderr, '', 'it does not write to stderr');
console.log('ok');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readfile-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${f} | ${node} ${f} child`;
exec(cmd, function(err, stdout, stderr) {
if (err) console.error(err);
assert(!err, 'it exits normally');
assert.ifError(err);
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
assert.strictEqual(stderr, '', 'it does not write to stderr');
console.log('ok');
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-fs-readfilesync-pipe-large.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const f = JSON.stringify(__filename);
const node = JSON.stringify(process.execPath);
const cmd = `cat ${filename} | ${node} ${f} child`;
exec(cmd, { maxBuffer: 1000000 }, function(err, stdout, stderr) {
if (err) console.error(err);
assert(!err, 'it exits normally');
assert.ifError(err);
assert.strictEqual(stdout, dataExpected, 'it reads the file and outputs it');
assert.strictEqual(stderr, '', 'it does not write to stderr');
console.log('ok');
Expand Down
16 changes: 8 additions & 8 deletions test/parallel/test-fs-realpath-buffer-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,39 @@ for (encoding in expected) {
const expected_value = expected[encoding];

fs.realpath(string_dir, {encoding: encoding}, common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(string_dir, encoding, common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(buffer_dir, {encoding: encoding}, common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
fs.realpath(buffer_dir, encoding, common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.strictEqual(res, expected_value);
}));
}

fs.realpath(string_dir, {encoding: 'buffer'}, common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));

fs.realpath(string_dir, 'buffer', common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));

fs.realpath(buffer_dir, {encoding: 'buffer'}, common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));

fs.realpath(buffer_dir, 'buffer', common.mustCall((err, res) => {
assert(!err);
assert.ifError(err);
assert.deepStrictEqual(res, buffer_dir);
}));
4 changes: 2 additions & 2 deletions test/parallel/test-fs-realpath-on-substed-drive.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ assert(Buffer.isBuffer(result));
assert(result.equals(filenameBuffer));

fs.realpath(filename, common.mustCall(function(err, result) {
assert(!err);
assert.ifError(err);
assert.strictEqual(result, filename);
}));

fs.realpath(filename, 'buffer', common.mustCall(function(err, result) {
assert(!err);
assert.ifError(err);
assert(Buffer.isBuffer(result));
assert(result.equals(filenameBuffer));
}));
6 changes: 3 additions & 3 deletions test/parallel/test-fs-realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ function test_up_multiple(cb) {
assertEqualPath(fs.realpathSync(abedabeda), abedabeda_real);
assertEqualPath(fs.realpathSync(abedabed), abedabed_real);
fs.realpath(abedabeda, function(er, real) {
if (er) throw er;
assert.ifError(er);
assertEqualPath(abedabeda_real, real);
fs.realpath(abedabed, function(er, real) {
if (er) throw er;
assert.ifError(er);
assertEqualPath(abedabed_real, real);
cb();
cleanup();
Expand Down Expand Up @@ -476,7 +476,7 @@ const tests = [
const numtests = tests.length;
var testsRun = 0;
function runNextTest(err) {
if (err) throw err;
assert.ifError(err);
const test = tests.shift();
if (!test) {
return console.log(numtests +
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ fs.closeSync(fd);

// async tests
testTruncate(common.mustCall(function(er) {
if (er) throw er;
assert.ifError(er);
testFtruncate(common.mustCall(function(er) {
if (er) throw er;
assert.ifError(er);
}));
}));

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-write-stream-autoclose-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function next() {
function next2() {
// This will test if after reusing the fd data is written properly
fs.readFile(file, function(err, data) {
assert(!err);
assert.ifError(err);
assert.strictEqual(data.toString(), 'Test2');
process.nextTick(common.mustCall(next3));
});
Expand Down
Loading