test: use common.fail() instead of assert(false)
PR-URL: https://github.com/nodejs/node/pull/10899 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
a647d82f83
commit
aa0e4f3843
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const dns = require('dns');
|
const dns = require('dns');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
@ -44,19 +44,9 @@ function checkWrap(req) {
|
|||||||
|
|
||||||
|
|
||||||
TEST(function test_reverse_bogus(done) {
|
TEST(function test_reverse_bogus(done) {
|
||||||
let error;
|
assert.throws(() => {
|
||||||
|
dns.reverse('bogus ip', common.fail);
|
||||||
try {
|
}, /^Error: getHostByAddr EINVAL$/);
|
||||||
dns.reverse('bogus ip', function() {
|
|
||||||
assert.ok(false);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.ok(error instanceof Error);
|
|
||||||
assert.strictEqual(error.errno, 'EINVAL');
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -442,7 +432,7 @@ TEST(function test_lookup_all_mixed(done) {
|
|||||||
else if (isIPv6(ip.address))
|
else if (isIPv6(ip.address))
|
||||||
assert.strictEqual(ip.family, 6);
|
assert.strictEqual(ip.family, 6);
|
||||||
else
|
else
|
||||||
assert(false);
|
common.fail('unexpected IP address');
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
@ -38,7 +38,7 @@ tls.connect(opts, fail).on('error', common.mustCall((err) => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
function fail() {
|
function fail() {
|
||||||
assert(false, 'should fail to connect');
|
common.fail('should fail to connect');
|
||||||
}
|
}
|
||||||
|
|
||||||
// New secure contexts have the well-known root CAs.
|
// New secure contexts have the well-known root CAs.
|
||||||
|
@ -37,10 +37,10 @@ if (typeof process.argv[2] === 'string') {
|
|||||||
async_wrap.setupHooks({ init, pre, post, destroy });
|
async_wrap.setupHooks({ init, pre, post, destroy });
|
||||||
async_wrap.enable();
|
async_wrap.enable();
|
||||||
|
|
||||||
process.on('uncaughtException', () => assert.ok(0, 'UNREACHABLE'));
|
process.on('uncaughtException', common.fail);
|
||||||
|
|
||||||
const d = domain.create();
|
const d = domain.create();
|
||||||
d.on('error', () => assert.ok(0, 'UNREACHABLE'));
|
d.on('error', common.fail);
|
||||||
d.run(() => {
|
d.run(() => {
|
||||||
// Using randomBytes because timers are not yet supported.
|
// Using randomBytes because timers are not yet supported.
|
||||||
crypto.randomBytes(0, () => { });
|
crypto.randomBytes(0, () => { });
|
||||||
|
@ -21,8 +21,7 @@ if (process.argv[2] === 'child') {
|
|||||||
|
|
||||||
child.stderr.setEncoding('utf8');
|
child.stderr.setEncoding('utf8');
|
||||||
child.stderr.on('data', function(data) {
|
child.stderr.on('data', function(data) {
|
||||||
console.log('parent stderr: ' + data);
|
common.fail(`Unexpected parent stderr: ${data}`);
|
||||||
assert.ok(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// check if we receive both 'hello' at start and 'goodbye' at end
|
// check if we receive both 'hello' at start and 'goodbye' at end
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
|
||||||
const domain = require('domain');
|
const domain = require('domain');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
|
|
||||||
@ -184,17 +183,16 @@ if (process.argv[2] === 'child') {
|
|||||||
test.expectedMessages.forEach(function(expectedMessage) {
|
test.expectedMessages.forEach(function(expectedMessage) {
|
||||||
if (test.messagesReceived === undefined ||
|
if (test.messagesReceived === undefined ||
|
||||||
test.messagesReceived.indexOf(expectedMessage) === -1)
|
test.messagesReceived.indexOf(expectedMessage) === -1)
|
||||||
assert(false, 'test ' + test.fn.name +
|
common.fail('test ' + test.fn.name + ' should have sent message: ' +
|
||||||
' should have sent message: ' + expectedMessage +
|
expectedMessage + ' but didn\'t');
|
||||||
' but didn\'t');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (test.messagesReceived) {
|
if (test.messagesReceived) {
|
||||||
test.messagesReceived.forEach(function(receivedMessage) {
|
test.messagesReceived.forEach(function(receivedMessage) {
|
||||||
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
|
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
|
||||||
assert(false, 'test ' + test.fn.name +
|
common.fail('test ' + test.fn.name +
|
||||||
' should not have sent message: ' + receivedMessage +
|
' should not have sent message: ' + receivedMessage +
|
||||||
' but did');
|
' but did');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,7 @@ server.listen(0, options.host, common.mustCall(onListen));
|
|||||||
// do a GET request, expect it to fail
|
// do a GET request, expect it to fail
|
||||||
function onListen() {
|
function onListen() {
|
||||||
options.port = this.address().port;
|
options.port = this.address().port;
|
||||||
const req = http.request(options, function(res) {
|
const req = http.request(options, common.fail);
|
||||||
assert.ok(false, 'this should never run');
|
|
||||||
});
|
|
||||||
req.on('error', common.mustCall(function(err) {
|
req.on('error', common.mustCall(function(err) {
|
||||||
assert.strictEqual(err.code, 'ECONNRESET');
|
assert.strictEqual(err.code, 'ECONNRESET');
|
||||||
}));
|
}));
|
||||||
|
@ -7,10 +7,7 @@ const assert = require('assert');
|
|||||||
// The callback should never be invoked because the server
|
// The callback should never be invoked because the server
|
||||||
// should respond with a 400 Client Error when a double
|
// should respond with a 400 Client Error when a double
|
||||||
// Content-Length header is received.
|
// Content-Length header is received.
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer(common.fail);
|
||||||
assert(false, 'callback should not have been invoked');
|
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
server.on('clientError', common.mustCall((err, socket) => {
|
server.on('clientError', common.mustCall((err, socket) => {
|
||||||
assert(/^Parse Error/.test(err.message));
|
assert(/^Parse Error/.test(err.message));
|
||||||
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const binding = process.binding('http_parser');
|
const binding = process.binding('http_parser');
|
||||||
@ -35,9 +35,7 @@ function newParser(type) {
|
|||||||
parser[kOnHeadersComplete] = function(info) {
|
parser[kOnHeadersComplete] = function(info) {
|
||||||
};
|
};
|
||||||
|
|
||||||
parser[kOnBody] = function(b, start, len) {
|
parser[kOnBody] = common.fail;
|
||||||
assert.ok(false, 'Function should not be called.');
|
|
||||||
};
|
|
||||||
|
|
||||||
parser[kOnMessageComplete] = function() {
|
parser[kOnMessageComplete] = function() {
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,7 @@ server.listen(0, common.mustCall(() => {
|
|||||||
http.get(
|
http.get(
|
||||||
{port: server.address().port, headers: {'x-num': n}},
|
{port: server.address().port, headers: {'x-num': n}},
|
||||||
(res) => {
|
(res) => {
|
||||||
assert(false, 'client allowed multiple content-length headers.');
|
common.fail('client allowed multiple content-length headers.');
|
||||||
}
|
}
|
||||||
).on('error', common.mustCall((err) => {
|
).on('error', common.mustCall((err) => {
|
||||||
assert(/^Parse Error/.test(err.message));
|
assert(/^Parse Error/.test(err.message));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ const srv = net.createServer(function onConnection(conn) {
|
|||||||
conn.on('error', function(err) {
|
conn.on('error', function(err) {
|
||||||
errs.push(err);
|
errs.push(err);
|
||||||
if (errs.length > 1 && errs[0] === errs[1])
|
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() {
|
conn.on('close', function() {
|
||||||
srv.unref();
|
srv.unref();
|
||||||
|
@ -10,8 +10,7 @@ let disconnect_count = 0;
|
|||||||
const c = net.createConnection(common.PORT);
|
const c = net.createConnection(common.PORT);
|
||||||
|
|
||||||
c.on('connect', function() {
|
c.on('connect', function() {
|
||||||
console.error('CLIENT connected');
|
common.fail('client should not have connected');
|
||||||
assert.ok(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
c.on('error', function(e) {
|
c.on('error', function(e) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
@ -39,7 +39,7 @@ function test(decode, uncork, multi, next) {
|
|||||||
|
|
||||||
const w = new stream.Writable({ decodeStrings: decode });
|
const w = new stream.Writable({ decodeStrings: decode });
|
||||||
w._write = function(chunk, e, cb) {
|
w._write = function(chunk, e, cb) {
|
||||||
assert(false, 'Should not call _write');
|
common.fail('Should not call _write');
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectChunks = decode ? [
|
const expectChunks = decode ? [
|
||||||
|
@ -14,9 +14,7 @@ const path = require('path');
|
|||||||
const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'));
|
const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'));
|
||||||
const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem'));
|
const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem'));
|
||||||
|
|
||||||
const conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() {
|
const conn = tls.connect({cert, key, port: common.PORT}, common.fail);
|
||||||
assert.ok(false); // callback should never be executed
|
|
||||||
});
|
|
||||||
conn.on('error', function() {
|
conn.on('error', function() {
|
||||||
});
|
});
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
|
@ -16,9 +16,7 @@ const server = tls.createServer({
|
|||||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
||||||
}, function(c) {
|
}, function(c) {
|
||||||
}).listen(0, common.mustCall(function() {
|
}).listen(0, common.mustCall(function() {
|
||||||
const c = tls.connect(this.address().port, function() {
|
const c = tls.connect(this.address().port, common.fail);
|
||||||
assert(false, 'should not be called');
|
|
||||||
});
|
|
||||||
|
|
||||||
c.on('error', common.mustCall(function(err) {}));
|
c.on('error', common.mustCall(function(err) {}));
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
if (!common.hasCrypto) {
|
if (!common.hasCrypto) {
|
||||||
common.skip('missing crypto');
|
common.skip('missing crypto');
|
||||||
@ -33,9 +32,7 @@ const path = require('path');
|
|||||||
key: key,
|
key: key,
|
||||||
port: common.PORT,
|
port: common.PORT,
|
||||||
ciphers: 'rick-128-roll'
|
ciphers: 'rick-128-roll'
|
||||||
}, function() {
|
}, common.fail);
|
||||||
assert.ok(false); // callback should never be executed
|
|
||||||
});
|
|
||||||
|
|
||||||
conn.on('error', common.mustCall(function() {}));
|
conn.on('error', common.mustCall(function() {}));
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,7 @@ const server = tls.createServer({
|
|||||||
const c = tls.connect({
|
const c = tls.connect({
|
||||||
port: this.address().port,
|
port: this.address().port,
|
||||||
ciphers: 'RC4'
|
ciphers: 'RC4'
|
||||||
}, function() {
|
}, common.fail);
|
||||||
assert(false, 'should not be called');
|
|
||||||
});
|
|
||||||
|
|
||||||
c.on('error', common.mustCall(function(err) {
|
c.on('error', common.mustCall(function(err) {
|
||||||
assert.notStrictEqual(err.code, 'ECONNRESET');
|
assert.notStrictEqual(err.code, 'ECONNRESET');
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ const p = child_process.spawn(process.execPath, [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
p.stderr.on('data', function(data) {
|
p.stderr.on('data', function(data) {
|
||||||
assert(false, 'Unexpected stderr data: ' + data);
|
common.fail(`Unexpected stderr data: ${data}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
let output = '';
|
let output = '';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const URL = url.URL;
|
const URL = url.URL;
|
||||||
@ -35,5 +35,5 @@ assert.deepStrictEqual(c[2], ['z', '3']);
|
|||||||
a = new URL('http://a.b/c');
|
a = new URL('http://a.b/c');
|
||||||
b = a.searchParams;
|
b = a.searchParams;
|
||||||
for (i of b) {
|
for (i of b) {
|
||||||
assert(false, 'should not be reached');
|
common.fail('should not be reached');
|
||||||
}
|
}
|
||||||
|
@ -93,16 +93,13 @@ setTimeout(function() {
|
|||||||
|
|
||||||
assert.doesNotThrow(
|
assert.doesNotThrow(
|
||||||
function() {
|
function() {
|
||||||
function a() {
|
|
||||||
assert.ok(0); // should not run
|
|
||||||
}
|
|
||||||
function b() {
|
function b() {
|
||||||
fs.unwatchFile(filenameThree, b);
|
fs.unwatchFile(filenameThree, b);
|
||||||
++watchSeenThree;
|
++watchSeenThree;
|
||||||
}
|
}
|
||||||
fs.watchFile(filenameThree, a);
|
fs.watchFile(filenameThree, common.fail);
|
||||||
fs.watchFile(filenameThree, b);
|
fs.watchFile(filenameThree, b);
|
||||||
fs.unwatchFile(filenameThree, a);
|
fs.unwatchFile(filenameThree, common.fail);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user