Skip to content

Commit b7bf43a

Browse files
cjihrigitaloacasas
authored andcommitted
test: use common.fail() instead of assert(false)
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]>
1 parent c0c1a4c commit b7bf43a

19 files changed

+34
-67
lines changed

test/internet/test-dns.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const dns = require('dns');
55
const net = require('net');
@@ -44,19 +44,9 @@ function checkWrap(req) {
4444

4545

4646
TEST(function test_reverse_bogus(done) {
47-
let error;
48-
49-
try {
50-
dns.reverse('bogus ip', function() {
51-
assert.ok(false);
52-
});
53-
} catch (e) {
54-
error = e;
55-
}
56-
57-
assert.ok(error instanceof Error);
58-
assert.strictEqual(error.errno, 'EINVAL');
59-
47+
assert.throws(() => {
48+
dns.reverse('bogus ip', common.fail);
49+
}, /^Error: getHostByAddr EINVAL$/);
6050
done();
6151
});
6252

@@ -442,7 +432,7 @@ TEST(function test_lookup_all_mixed(done) {
442432
else if (isIPv6(ip.address))
443433
assert.strictEqual(ip.family, 6);
444434
else
445-
assert(false);
435+
common.fail('unexpected IP address');
446436
});
447437

448438
done();

test/internet/test-tls-add-ca-cert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tls.connect(opts, fail).on('error', common.mustCall((err) => {
3838
}));
3939

4040
function fail() {
41-
assert(false, 'should fail to connect');
41+
common.fail('should fail to connect');
4242
}
4343

4444
// New secure contexts have the well-known root CAs.

test/parallel/test-async-wrap-throw-from-callback.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ if (typeof process.argv[2] === 'string') {
3737
async_wrap.setupHooks({ init, pre, post, destroy });
3838
async_wrap.enable();
3939

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

4242
const d = domain.create();
43-
d.on('error', () => assert.ok(0, 'UNREACHABLE'));
43+
d.on('error', common.fail);
4444
d.run(() => {
4545
// Using randomBytes because timers are not yet supported.
4646
crypto.randomBytes(0, () => { });

test/parallel/test-child-process-stdout-flush-exit.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ if (process.argv[2] === 'child') {
2121

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

2827
// check if we receive both 'hello' at start and 'goodbye' at end

test/parallel/test-domain-uncaught-exception.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
const common = require('../common');
12-
const assert = require('assert');
1312
const domain = require('domain');
1413
const child_process = require('child_process');
1514

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

192190
if (test.messagesReceived) {
193191
test.messagesReceived.forEach(function(receivedMessage) {
194192
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
195-
assert(false, 'test ' + test.fn.name +
196-
' should not have sent message: ' + receivedMessage +
197-
' but did');
193+
common.fail('test ' + test.fn.name +
194+
' should not have sent message: ' + receivedMessage +
195+
' but did');
198196
}
199197
});
200198
}

test/parallel/test-http-conn-reset.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ server.listen(0, options.host, common.mustCall(onListen));
1919
// do a GET request, expect it to fail
2020
function onListen() {
2121
options.port = this.address().port;
22-
const req = http.request(options, function(res) {
23-
assert.ok(false, 'this should never run');
24-
});
22+
const req = http.request(options, common.fail);
2523
req.on('error', common.mustCall(function(err) {
2624
assert.strictEqual(err.code, 'ECONNRESET');
2725
}));

test/parallel/test-http-double-content-length.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ const assert = require('assert');
77
// The callback should never be invoked because the server
88
// should respond with a 400 Client Error when a double
99
// Content-Length header is received.
10-
const server = http.createServer((req, res) => {
11-
assert(false, 'callback should not have been invoked');
12-
res.end();
13-
});
10+
const server = http.createServer(common.fail);
1411
server.on('clientError', common.mustCall((err, socket) => {
1512
assert(/^Parse Error/.test(err.message));
1613
assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH');

test/parallel/test-http-parser.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44

55
const binding = process.binding('http_parser');
@@ -35,9 +35,7 @@ function newParser(type) {
3535
parser[kOnHeadersComplete] = function(info) {
3636
};
3737

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

4240
parser[kOnMessageComplete] = function() {
4341
};

test/parallel/test-http-response-multi-content-length.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ server.listen(0, common.mustCall(() => {
3535
http.get(
3636
{port: server.address().port, headers: {'x-num': n}},
3737
(res) => {
38-
assert(false, 'client allowed multiple content-length headers.');
38+
common.fail('client allowed multiple content-length headers.');
3939
}
4040
).on('error', common.mustCall((err) => {
4141
assert(/^Parse Error/.test(err.message));

test/parallel/test-net-error-twice.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const net = require('net');
55

@@ -20,7 +20,7 @@ const srv = net.createServer(function onConnection(conn) {
2020
conn.on('error', function(err) {
2121
errs.push(err);
2222
if (errs.length > 1 && errs[0] === errs[1])
23-
assert(false, 'We should not be emitting the same error twice');
23+
common.fail('Should not emit the same error twice');
2424
});
2525
conn.on('close', function() {
2626
srv.unref();

test/parallel/test-net-reconnect-error.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ let disconnect_count = 0;
1010
const c = net.createConnection(common.PORT);
1111

1212
c.on('connect', function() {
13-
console.error('CLIENT connected');
14-
assert.ok(false);
13+
common.fail('client should not have connected');
1514
});
1615

1716
c.on('error', function(e) {

test/parallel/test-stream-writev.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44

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

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

4545
const expectChunks = decode ? [

test/parallel/test-tls-client-abort.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ const path = require('path');
1414
const cert = fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'));
1515
const key = fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem'));
1616

17-
const conn = tls.connect({cert: cert, key: key, port: common.PORT}, function() {
18-
assert.ok(false); // callback should never be executed
19-
});
17+
const conn = tls.connect({cert, key, port: common.PORT}, common.fail);
2018
conn.on('error', function() {
2119
});
2220
assert.doesNotThrow(function() {

test/parallel/test-tls-close-error.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const server = tls.createServer({
1616
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
1717
}, function(c) {
1818
}).listen(0, common.mustCall(function() {
19-
const c = tls.connect(this.address().port, function() {
20-
assert(false, 'should not be called');
21-
});
19+
const c = tls.connect(this.address().port, common.fail);
2220

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

test/parallel/test-tls-connect.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
@@ -33,9 +32,7 @@ const path = require('path');
3332
key: key,
3433
port: common.PORT,
3534
ciphers: 'rick-128-roll'
36-
}, function() {
37-
assert.ok(false); // callback should never be executed
38-
});
35+
}, common.fail);
3936

4037
conn.on('error', common.mustCall(function() {}));
4138
}

test/parallel/test-tls-handshake-error.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ const server = tls.createServer({
2020
const c = tls.connect({
2121
port: this.address().port,
2222
ciphers: 'RC4'
23-
}, function() {
24-
assert(false, 'should not be called');
25-
});
23+
}, common.fail);
2624

2725
c.on('error', common.mustCall(function(err) {
2826
assert.notStrictEqual(err.code, 'ECONNRESET');

test/parallel/test-vm-syntax-error-message.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const child_process = require('child_process');
55

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

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

1818
let output = '';

test/parallel/test-whatwg-url-searchparams-foreach.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55
const url = require('url');
66
const URL = url.URL;
@@ -35,5 +35,5 @@ assert.deepStrictEqual(c[2], ['z', '3']);
3535
a = new URL('http://a.b/c');
3636
b = a.searchParams;
3737
for (i of b) {
38-
assert(false, 'should not be reached');
38+
common.fail('should not be reached');
3939
}

test/pummel/test-fs-watch-file.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,13 @@ setTimeout(function() {
9393

9494
assert.doesNotThrow(
9595
function() {
96-
function a() {
97-
assert.ok(0); // should not run
98-
}
9996
function b() {
10097
fs.unwatchFile(filenameThree, b);
10198
++watchSeenThree;
10299
}
103-
fs.watchFile(filenameThree, a);
100+
fs.watchFile(filenameThree, common.fail);
104101
fs.watchFile(filenameThree, b);
105-
fs.unwatchFile(filenameThree, a);
102+
fs.unwatchFile(filenameThree, common.fail);
106103
}
107104
);
108105

0 commit comments

Comments
 (0)