Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7bf43a

Browse filesBrowse files
cjihrigItalo A. Casas
authored andcommitted
test: use common.fail() instead of assert(false)
PR-URL: #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>
1 parent c0c1a4c commit b7bf43a
Copy full SHA for b7bf43a
Expand file treeCollapse file tree

19 files changed

+34
-67
lines changed
Open diff view settings
Collapse file

‎test/internet/test-dns.js‎

Copy file name to clipboardExpand all lines: test/internet/test-dns.js
+5-15Lines changed: 5 additions & 15 deletions
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();
Collapse file

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

Copy file name to clipboardExpand all lines: test/internet/test-tls-add-ca-cert.js
+1-1Lines changed: 1 addition & 1 deletion
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.
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-async-wrap-throw-from-callback.js
+2-2Lines changed: 2 additions & 2 deletions
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, () => { });
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-stdout-flush-exit.js
+1-2Lines changed: 1 addition & 2 deletions
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
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-domain-uncaught-exception.js
+5-7Lines changed: 5 additions & 7 deletions
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
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-conn-reset.js
+1-3Lines changed: 1 addition & 3 deletions
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
}));
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-double-content-length.js
+1-4Lines changed: 1 addition & 4 deletions
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');
Collapse file

‎test/parallel/test-http-parser.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-parser.js
+2-4Lines changed: 2 additions & 4 deletions
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
};
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-response-multi-content-length.js
+1-1Lines changed: 1 addition & 1 deletion
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));
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-net-error-twice.js
+2-2Lines changed: 2 additions & 2 deletions
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();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.