Skip to content

Commit

Permalink
test: use common.fail() instead of assert(false)
Browse files Browse the repository at this point in the history
PR-URL: #10899
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Italo A. Casas <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
cjihrig authored and italoacasas committed Jan 30, 2017
1 parent c0c1a4c commit b7bf43a
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 67 deletions.
20 changes: 5 additions & 15 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dns = require('dns');
const net = require('net');
Expand Down Expand Up @@ -44,19 +44,9 @@ function checkWrap(req) {


TEST(function test_reverse_bogus(done) {
let error;

try {
dns.reverse('bogus ip', function() {
assert.ok(false);
});
} catch (e) {
error = e;
}

assert.ok(error instanceof Error);
assert.strictEqual(error.errno, 'EINVAL');

assert.throws(() => {
dns.reverse('bogus ip', common.fail);
}, /^Error: getHostByAddr EINVAL$/);
done();
});

Expand Down Expand Up @@ -442,7 +432,7 @@ TEST(function test_lookup_all_mixed(done) {
else if (isIPv6(ip.address))
assert.strictEqual(ip.family, 6);
else
assert(false);
common.fail('unexpected IP address');
});

done();
Expand Down
2 changes: 1 addition & 1 deletion test/internet/test-tls-add-ca-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tls.connect(opts, fail).on('error', common.mustCall((err) => {
}));

function fail() {
assert(false, 'should fail to connect');
common.fail('should fail to connect');
}

// New secure contexts have the well-known root CAs.
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-async-wrap-throw-from-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ if (typeof process.argv[2] === 'string') {
async_wrap.setupHooks({ init, pre, post, destroy });
async_wrap.enable();

process.on('uncaughtException', () => assert.ok(0, 'UNREACHABLE'));
process.on('uncaughtException', common.fail);

const d = domain.create();
d.on('error', () => assert.ok(0, 'UNREACHABLE'));
d.on('error', common.fail);
d.run(() => {
// Using randomBytes because timers are not yet supported.
crypto.randomBytes(0, () => { });
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-child-process-stdout-flush-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ if (process.argv[2] === 'child') {

child.stderr.setEncoding('utf8');
child.stderr.on('data', function(data) {
console.log('parent stderr: ' + data);
assert.ok(false);
common.fail(`Unexpected parent stderr: ${data}`);
});

// check if we receive both 'hello' at start and 'goodbye' at end
Expand Down
12 changes: 5 additions & 7 deletions test/parallel/test-domain-uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

const common = require('../common');
const assert = require('assert');
const domain = require('domain');
const child_process = require('child_process');

Expand Down Expand Up @@ -184,17 +183,16 @@ if (process.argv[2] === 'child') {
test.expectedMessages.forEach(function(expectedMessage) {
if (test.messagesReceived === undefined ||
test.messagesReceived.indexOf(expectedMessage) === -1)
assert(false, 'test ' + test.fn.name +
' should have sent message: ' + expectedMessage +
' but didn\'t');
common.fail('test ' + test.fn.name + ' should have sent message: ' +
expectedMessage + ' but didn\'t');
});

if (test.messagesReceived) {
test.messagesReceived.forEach(function(receivedMessage) {
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
assert(false, 'test ' + test.fn.name +
' should not have sent message: ' + receivedMessage +
' but did');
common.fail('test ' + test.fn.name +
' should not have sent message: ' + receivedMessage +
' but did');
}
});
}
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-http-conn-reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ server.listen(0, options.host, common.mustCall(onListen));
// do a GET request, expect it to fail
function onListen() {
options.port = this.address().port;
const req = http.request(options, function(res) {
assert.ok(false, 'this should never run');
});
const req = http.request(options, common.fail);
req.on('error', common.mustCall(function(err) {
assert.strictEqual(err.code, 'ECONNRESET');
}));
Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-http-double-content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ const assert = require('assert');
// The callback should never be invoked because the server
// should respond with a 400 Client Error when a double
// Content-Length header is received.
const server = http.createServer((req, res) => {
assert(false, 'callback should not have been invoked');
res.end();
});
const server = http.createServer(common.fail);
server.on('clientError', common.mustCall((err, socket) => {
assert(/^Parse Error/.test(err.message));
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-http-parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

const binding = process.binding('http_parser');
Expand Down Expand Up @@ -35,9 +35,7 @@ function newParser(type) {
parser[kOnHeadersComplete] = function(info) {
};

parser[kOnBody] = function(b, start, len) {
assert.ok(false, 'Function should not be called.');
};
parser[kOnBody] = common.fail;

parser[kOnMessageComplete] = function() {
};
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-response-multi-content-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ server.listen(0, common.mustCall(() => {
http.get(
{port: server.address().port, headers: {'x-num': n}},
(res) => {
assert(false, 'client allowed multiple content-length headers.');
common.fail('client allowed multiple content-length headers.');
}
).on('error', common.mustCall((err) => {
assert(/^Parse Error/.test(err.message));
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-error-twice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const net = require('net');

Expand All @@ -20,7 +20,7 @@ const srv = net.createServer(function onConnection(conn) {
conn.on('error', function(err) {
errs.push(err);
if (errs.length > 1 && errs[0] === errs[1])
assert(false, 'We should not be emitting the same error twice');
common.fail('Should not emit the same error twice');
});
conn.on('close', function() {
srv.unref();
Expand Down
3 changes: 1 addition & 2 deletions test/parallel/test-net-reconnect-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ let disconnect_count = 0;
const c = net.createConnection(common.PORT);

c.on('connect', function() {
console.error('CLIENT connected');
assert.ok(false);
common.fail('client should not have connected');
});

c.on('error', function(e) {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-stream-writev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

const stream = require('stream');
Expand Down Expand Up @@ -39,7 +39,7 @@ function test(decode, uncork, multi, next) {

const w = new stream.Writable({ decodeStrings: decode });
w._write = function(chunk, e, cb) {
assert(false, 'Should not call _write');
common.fail('Should not call _write');
};

const expectChunks = decode ? [
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-tls-client-abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ const path = require('path');
const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'));
const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem'));

const conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() {
assert.ok(false); // callback should never be executed
});
const conn = tls.connect({cert, key, port: common.PORT}, common.fail);
conn.on('error', function() {
});
assert.doesNotThrow(function() {
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-tls-close-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const server = tls.createServer({
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
}, function(c) {
}).listen(0, common.mustCall(function() {
const c = tls.connect(this.address().port, function() {
assert(false, 'should not be called');
});
const c = tls.connect(this.address().port, common.fail);

c.on('error', common.mustCall(function(err) {}));

Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-tls-connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
common.skip('missing crypto');
Expand Down Expand Up @@ -33,9 +32,7 @@ const path = require('path');
key: key,
port: common.PORT,
ciphers: 'rick-128-roll'
}, function() {
assert.ok(false); // callback should never be executed
});
}, common.fail);

conn.on('error', common.mustCall(function() {}));
}
4 changes: 1 addition & 3 deletions test/parallel/test-tls-handshake-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const server = tls.createServer({
const c = tls.connect({
port: this.address().port,
ciphers: 'RC4'
}, function() {
assert(false, 'should not be called');
});
}, common.fail);

c.on('error', common.mustCall(function(err) {
assert.notStrictEqual(err.code, 'ECONNRESET');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-vm-syntax-error-message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const child_process = require('child_process');

Expand All @@ -12,7 +12,7 @@ const p = child_process.spawn(process.execPath, [
]);

p.stderr.on('data', function(data) {
assert(false, 'Unexpected stderr data: ' + data);
common.fail(`Unexpected stderr data: ${data}`);
});

let output = '';
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-whatwg-url-searchparams-foreach.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const url = require('url');
const URL = url.URL;
Expand Down Expand Up @@ -35,5 +35,5 @@ assert.deepStrictEqual(c[2], ['z', '3']);
a = new URL('http://a.b/c');
b = a.searchParams;
for (i of b) {
assert(false, 'should not be reached');
common.fail('should not be reached');
}
7 changes: 2 additions & 5 deletions test/pummel/test-fs-watch-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,13 @@ setTimeout(function() {

assert.doesNotThrow(
function() {
function a() {
assert.ok(0); // should not run
}
function b() {
fs.unwatchFile(filenameThree, b);
++watchSeenThree;
}
fs.watchFile(filenameThree, a);
fs.watchFile(filenameThree, common.fail);
fs.watchFile(filenameThree, b);
fs.unwatchFile(filenameThree, a);
fs.unwatchFile(filenameThree, common.fail);
}
);

Expand Down

0 comments on commit b7bf43a

Please sign in to comment.