Skip to content

Commit 1091b86

Browse files
TrottMylesBorins
authored andcommitted
test: remove common.fail()
common.fail() was added to paste over issues with assert.fail() function signature. assert.fail() has been updated to accept a single argument so common.fail() is no longer necessary. Backport-PR-URL: #15479 PR-URL: #12293 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 44cc39d commit 1091b86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+95
-89
lines changed

test/common/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ process.on('exit', function() {
385385
if (!exports.globalCheck) return;
386386
const leaked = leakedGlobals();
387387
if (leaked.length > 0) {
388-
fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
388+
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
389389
}
390390
});
391391

@@ -473,14 +473,9 @@ exports.fileExists = function(pathname) {
473473
}
474474
};
475475

476-
function fail(msg) {
477-
assert.fail(null, null, msg);
478-
}
479-
exports.fail = fail;
480-
481476
exports.mustNotCall = function(msg) {
482477
return function mustNotCall() {
483-
fail(msg || 'function should not have been called');
478+
assert.fail(msg || 'function should not have been called');
484479
};
485480
};
486481

test/inspector/inspector-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
222222
};
223223
this.sendAll_(commands, () => {
224224
timeoutId = setTimeout(() => {
225-
common.fail(`Messages without response: ${
225+
assert.fail(`Messages without response: ${
226226
Object.keys(this.messages_).join(', ')}`);
227227
}, TIMEOUT);
228228
});

test/internet/test-dgram-send-cb-quelches-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function callbackOnly(err) {
2828
}
2929

3030
function onEvent(err) {
31-
common.fail('Error should not be emitted if there is callback');
31+
assert.fail('Error should not be emitted if there is callback');
3232
}
3333

3434
function onError(err) {

test/internet/test-dns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ TEST(function test_lookup_all_mixed(done) {
449449
else if (isIPv6(ip.address))
450450
assert.strictEqual(ip.family, 6);
451451
else
452-
assert(false);
452+
assert.fail('unexpected IP address');
453453
});
454454

455455
done();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tls.connect(opts, fail).on('error', common.mustCall((err) => {
3737
}));
3838

3939
function fail() {
40-
assert(false, 'should fail to connect');
40+
assert.fail('should fail to connect');
4141
}
4242

4343
// New secure contexts have the well-known root CAs.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
3+
const assert = require('assert');
34

45
process.on('beforeExit', function() {
5-
common.fail('exit should not allow this to occur');
6+
assert.fail('exit should not allow this to occur');
67
});
78

89
process.exit();

test/parallel/test-child-process-fork-and-spawn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ switch (process.argv[2] || '') {
1515
case 'spawn':
1616
break;
1717
default:
18-
common.fail();
18+
assert.fail();
1919
}
2020

2121
function checkExit(statusCode) {

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

Lines 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+
assert.fail(`Unexpected parent stderr: ${data}`);
2625
});
2726

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

test/parallel/test-cluster-send-handle-twice.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (cluster.isMaster) {
3333
setTimeout(function() { client.end(); }, 50);
3434
}).on('error', function(e) {
3535
console.error(e);
36-
common.fail('server.listen failed');
36+
assert.fail('server.listen failed');
3737
cluster.worker.disconnect();
3838
});
3939
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,16 @@ if (process.argv[2] === 'child') {
184184
test.expectedMessages.forEach(function(expectedMessage) {
185185
if (test.messagesReceived === undefined ||
186186
test.messagesReceived.indexOf(expectedMessage) === -1)
187-
assert(false, `test ${test.fn.name} should have sent message: ${
188-
expectedMessage} but didn't`);
187+
assert.fail('test ' + test.fn.name + ' should have sent message: ' +
188+
expectedMessage + ' but didn\'t');
189189
});
190190

191191
if (test.messagesReceived) {
192192
test.messagesReceived.forEach(function(receivedMessage) {
193-
if (!test.expectedMessages.includes(receivedMessage)) {
194-
assert(false, `test ${test.fn.name} should not have sent message: ${
195-
receivedMessage} but did`);
193+
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
194+
assert.fail('test ' + test.fn.name +
195+
' should not have sent message: ' + receivedMessage +
196+
' but did');
196197
}
197198
});
198199
}

test/parallel/test-event-emitter-add-listeners.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const EventEmitter = require('events');
3232
});
3333

3434
ee.on('hello', hello);
35-
ee.once('foo', common.fail);
35+
ee.once('foo', assert.fail);
3636
assert.deepStrictEqual(['hello', 'foo'], events_new_listener_emited);
37-
assert.deepStrictEqual([hello, common.fail], listeners_new_listener_emited);
37+
assert.deepStrictEqual([hello, assert.fail], listeners_new_listener_emited);
3838

3939
ee.emit('hello', 'a', 'b');
4040
}

test/parallel/test-event-emitter-listeners-side-effects.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const common = require('../common');
3+
require('../common');
44
const assert = require('assert');
55

66
const EventEmitter = require('events').EventEmitter;
@@ -14,12 +14,12 @@ assert.strictEqual(fl.length, 0);
1414
assert(!(e._events instanceof Object));
1515
assert.deepStrictEqual(Object.keys(e._events), []);
1616

17-
e.on('foo', common.fail);
17+
e.on('foo', assert.fail);
1818
fl = e.listeners('foo');
19-
assert.strictEqual(e._events.foo, common.fail);
19+
assert.strictEqual(e._events.foo, assert.fail);
2020
assert(Array.isArray(fl));
2121
assert.strictEqual(fl.length, 1);
22-
assert.strictEqual(fl[0], common.fail);
22+
assert.strictEqual(fl[0], assert.fail);
2323

2424
e.listeners('bar');
2525

@@ -28,12 +28,12 @@ fl = e.listeners('foo');
2828

2929
assert(Array.isArray(e._events.foo));
3030
assert.strictEqual(e._events.foo.length, 2);
31-
assert.strictEqual(e._events.foo[0], common.fail);
31+
assert.strictEqual(e._events.foo[0], assert.fail);
3232
assert.strictEqual(e._events.foo[1], assert.ok);
3333

3434
assert(Array.isArray(fl));
3535
assert.strictEqual(fl.length, 2);
36-
assert.strictEqual(fl[0], common.fail);
36+
assert.strictEqual(fl[0], assert.fail);
3737
assert.strictEqual(fl[1], assert.ok);
3838

3939
console.log('ok');

test/parallel/test-event-emitter-once.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ e.emit('hello', 'a', 'b');
1313
e.emit('hello', 'a', 'b');
1414

1515
function remove() {
16-
common.fail('once->foo should not be emitted');
16+
assert.fail('once->foo should not be emitted');
1717
}
1818

1919
e.once('foo', remove);

test/parallel/test-event-emitter-remove-listeners.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ function listener2() {}
4949
const ee = new EventEmitter();
5050

5151
function remove1() {
52-
common.fail('remove1 should not have been called');
52+
assert.fail('remove1 should not have been called');
5353
}
5454

5555
function remove2() {
56-
common.fail('remove2 should not have been called');
56+
assert.fail('remove2 should not have been called');
5757
}
5858

5959
ee.on('removeListener', common.mustCall(function(name, cb) {

test/parallel/test-exception-handler2.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common');
3+
const assert = require('assert');
34

45
process.on('uncaughtException', function(err) {
56
console.log(`Caught exception: ${err}`);
@@ -11,4 +12,4 @@ setTimeout(common.mustCall(function() {
1112

1213
// Intentionally cause an exception, but don't catch it.
1314
nonexistentFunc(); // eslint-disable-line no-undef
14-
common.fail('This will not run.');
15+
assert.fail('This will not run.');

test/parallel/test-fs-stat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
4141
try {
4242
stats = fs.fstatSync(fd);
4343
} catch (err) {
44-
common.fail(err);
44+
assert.fail(err);
4545
}
4646
if (stats) {
4747
console.dir(stats);

test/parallel/test-fs-write-stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ common.refreshTmpDir();
2323
const stream = fs.createWriteStream(file);
2424

2525
stream.on('drain', function() {
26-
common.fail('\'drain\' event must not be emitted before ' +
26+
assert.fail('\'drain\' event must not be emitted before ' +
2727
'stream.write() has been called at least once.');
2828
});
2929
stream.destroy();

test/parallel/test-global-console-exists.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
'use strict';
66

7-
const common = require('../common');
7+
require('../common');
88
const assert = require('assert');
99
const EventEmitter = require('events');
1010
const leak_warning = /EventEmitter memory leak detected\. 2 hello listeners/;
@@ -26,7 +26,7 @@ process.stderr.write = (data) => {
2626
if (write_calls === 0)
2727
assert.ok(leak_warning.test(data));
2828
else
29-
common.fail('stderr.write should be called only once');
29+
assert.fail('stderr.write should be called only once');
3030

3131
write_calls++;
3232
};

test/parallel/test-http-createConnection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
2121
res.resume();
2222
fn = common.mustCall(createConnectionError);
2323
http.get({ createConnection: fn }, function(res) {
24-
common.fail('Unexpected response callback');
24+
assert.fail('Unexpected response callback');
2525
}).on('error', common.mustCall(function(err) {
2626
assert.strictEqual(err.message, 'Could not create socket');
2727
server.close();

test/parallel/test-http-invalid-path-chars.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44
const http = require('http');
55

@@ -8,7 +8,7 @@ const theExperimentallyDeterminedNumber = 39;
88

99
function fail(path) {
1010
assert.throws(() => {
11-
http.request({ path }, common.fail);
11+
http.request({ path }, assert.fail);
1212
}, expectedError);
1313
}
1414

test/parallel/test-http-localaddress-bind-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common');
3+
const assert = require('assert');
34
const http = require('http');
45

56
const invalidLocalAddress = '1.2.3.4';
@@ -22,7 +23,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
2223
method: 'GET',
2324
localAddress: invalidLocalAddress
2425
}, function(res) {
25-
common.fail('unexpectedly got response from server');
26+
assert.fail('unexpectedly got response from server');
2627
}).on('error', common.mustCall(function(e) {
2728
console.log(`client got error: ${e.message}`);
2829
server.close();

test/parallel/test-http-mutable-headers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const s = http.createServer(function(req, res) {
6363
res.setHeader('x-foo', 'keyboard cat');
6464
res.writeHead(200, { 'x-foo': 'bar', 'x-bar': 'baz' });
6565
break;
66+
default:
67+
assert.fail('Unknown test');
6668
}
6769

6870
res.statusCode = 201;
@@ -120,7 +122,7 @@ function nextTest() {
120122
break;
121123

122124
default:
123-
throw new Error('?');
125+
assert.fail('Unknown test');
124126
}
125127

126128
response.setEncoding('utf8');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const server = http.createServer((req, res) => {
1919
res.writeHead(200, {'content-length': [1, 2]});
2020
break;
2121
default:
22-
common.fail('should never get here');
22+
assert.fail('should never get here');
2323
}
2424
res.end('ok');
2525
});
@@ -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+
assert.fail('client allowed multiple content-length headers.');
3939
}
4040
).on('error', common.mustCall((err) => {
4141
assert(/^Parse Error/.test(err.message));

test/parallel/test-http-response-splitting.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const common = require('../common');
3+
require('../common');
44
const http = require('http');
55
const net = require('net');
66
const url = require('url');
@@ -38,7 +38,7 @@ const server = http.createServer((req, res) => {
3838
test(res, 200, {'foo': y});
3939
break;
4040
default:
41-
common.fail('should not get to here.');
41+
assert.fail('should not get to here.');
4242
}
4343
if (count === 3)
4444
server.close();

test/parallel/test-http-response-status-message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ testCases.findByPath = function(path) {
2323
return testCase.path === path;
2424
});
2525
if (matching.length === 0) {
26-
throw 'failed to find test case with path ' + path;
26+
assert.fail(`failed to find test case with path ${path}`);
2727
}
2828
return matching[0];
2929
};

test/parallel/test-http-server-reject-chunked-with-content-length.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ server.listen(0, () => {
2323
client.on('data', (data) => {
2424
// Should not get to this point because the server should simply
2525
// close the connection without returning any data.
26-
common.fail('no data should be returned by the server');
26+
assert.fail('no data should be returned by the server');
2727
});
2828
client.on('end', common.mustCall(() => {}));
2929
});

test/parallel/test-http-unix-socket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ server.listen(common.PIPE, common.mustCall(function() {
4545
}));
4646

4747
req.on('error', function(e) {
48-
common.fail(e.stack);
48+
assert.fail(e.stack);
4949
});
5050

5151
req.end();

test/parallel/test-https-localaddress-bind-error.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
66

7+
const assert = require('assert');
78
const fs = require('fs');
89
const https = require('https');
910

@@ -32,7 +33,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
3233
method: 'GET',
3334
localAddress: invalidLocalAddress
3435
}, function(res) {
35-
common.fail('unexpectedly got response from server');
36+
assert.fail('unexpectedly got response from server');
3637
}).on('error', common.mustCall(function(e) {
3738
console.log(`client got error: ${e.message}`);
3839
server.close();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
assert.fail('Should not emit the same error twice');
2424
});
2525
conn.on('close', function() {
2626
srv.unref();

0 commit comments

Comments
 (0)