Skip to content

Commit 06c29a6

Browse files
committed
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. PR-URL: #12293 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 6f202ef commit 06c29a6

File tree

51 files changed

+101
-106
lines changed

Some content is hidden

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

51 files changed

+101
-106
lines changed

test/README.md

-6
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@ Checks whether `IPv6` is supported on this platform.
246246

247247
Checks if there are multiple localhosts available.
248248

249-
### fail(msg)
250-
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
251-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
252-
253-
Throws an `AssertionError` with `msg`
254-
255249
### fileExists(pathname)
256250
* pathname [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
257251
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)

test/common.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ process.on('exit', function() {
404404
if (!exports.globalCheck) return;
405405
const leaked = leakedGlobals();
406406
if (leaked.length > 0) {
407-
fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
407+
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
408408
}
409409
});
410410

@@ -507,14 +507,9 @@ exports.canCreateSymLink = function() {
507507
return true;
508508
};
509509

510-
function fail(msg) {
511-
assert.fail(null, null, msg);
512-
}
513-
exports.fail = fail;
514-
515510
exports.mustNotCall = function(msg) {
516511
return function mustNotCall() {
517-
fail(msg || 'function should not have been called');
512+
assert.fail(msg || 'function should not have been called');
518513
};
519514
};
520515

@@ -627,7 +622,7 @@ exports.WPT = {
627622
},
628623
assert_array_equals: assert.deepStrictEqual,
629624
assert_unreached(desc) {
630-
assert.fail(undefined, undefined, `Reached unreachable code: ${desc}`);
625+
assert.fail(`Reached unreachable code: ${desc}`);
631626
}
632627
};
633628

test/inspector/inspector-helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
217217
for (const id in this.messages_) {
218218
s += id + ', ';
219219
}
220-
common.fail('Messages without response: ' +
220+
assert.fail('Messages without response: ' +
221221
s.substring(0, s.length - 2));
222222
}, TIMEOUT);
223223
});

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

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ TEST(function test_lookup_all_mixed(done) {
453453
else if (isIPv6(ip.address))
454454
assert.strictEqual(ip.family, 6);
455455
else
456-
common.fail('unexpected IP address');
456+
assert.fail('unexpected IP address');
457457
});
458458

459459
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-
common.fail('should fail to connect');
41+
assert.fail('should fail to connect');
4242
}
4343

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

test/parallel/test-beforeexit-event-exit.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
const common = require('../common');
23+
require('../common');
24+
const assert = require('assert');
2425

2526
process.on('beforeExit', function() {
26-
common.fail('exit should not allow this to occur');
27+
assert.fail('exit should not allow this to occur');
2728
});
2829

2930
process.exit();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ switch (process.argv[2] || '') {
3737
case 'spawn':
3838
break;
3939
default:
40-
common.fail();
40+
assert.fail();
4141
}
4242

4343
function checkExit(statusCode) {

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

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

4343
child.stderr.setEncoding('utf8');
4444
child.stderr.on('data', function(data) {
45-
common.fail(`Unexpected parent stderr: ${data}`);
45+
assert.fail(`Unexpected parent stderr: ${data}`);
4646
});
4747

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (cluster.isMaster) {
5151
setTimeout(function() { client.end(); }, 50);
5252
}).on('error', function(e) {
5353
console.error(e);
54-
common.fail('server.listen failed');
54+
assert.fail('server.listen failed');
5555
cluster.worker.disconnect();
5656
});
5757
}

test/parallel/test-common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ assert.throws(function() {
4040
}, /^TypeError: Invalid expected value: \/foo\/$/);
4141

4242

43-
// common.fail() tests
43+
// assert.fail() tests
4444
assert.throws(
45-
() => { common.fail('fhqwhgads'); },
45+
() => { assert.fail('fhqwhgads'); },
4646
/^AssertionError: fhqwhgads$/
4747
);

test/parallel/test-dgram-address.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const dgram = require('dgram');
4141

4242
socket.on('error', (err) => {
4343
socket.close();
44-
common.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
44+
assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
4545
});
4646

4747
socket.bind(0, common.localhostIPv4);
@@ -65,7 +65,7 @@ if (common.hasIPv6) {
6565

6666
socket.on('error', (err) => {
6767
socket.close();
68-
common.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
68+
assert.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
6969
});
7070

7171
socket.bind(0, localhost);

test/parallel/test-dgram-implicit-bind-failure.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ socket.on('error', (err) => {
4040
return;
4141
}
4242

43-
common.fail(`Unexpected error: ${err}`);
43+
assert.fail(`Unexpected error: ${err}`);
4444
});
4545

4646
// Initiate a few send() operations, which will fail.

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

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

1111
const common = require('../common');
12+
const assert = require('assert');
1213
const domain = require('domain');
1314
const child_process = require('child_process');
1415

@@ -183,14 +184,14 @@ if (process.argv[2] === 'child') {
183184
test.expectedMessages.forEach(function(expectedMessage) {
184185
if (test.messagesReceived === undefined ||
185186
test.messagesReceived.indexOf(expectedMessage) === -1)
186-
common.fail('test ' + test.fn.name + ' should have sent message: ' +
187+
assert.fail('test ' + test.fn.name + ' should have sent message: ' +
187188
expectedMessage + ' but didn\'t');
188189
});
189190

190191
if (test.messagesReceived) {
191192
test.messagesReceived.forEach(function(receivedMessage) {
192193
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
193-
common.fail('test ' + test.fn.name +
194+
assert.fail('test ' + test.fn.name +
194195
' should not have sent message: ' + receivedMessage +
195196
' but did');
196197
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ const EventEmitter = require('events');
5353
});
5454

5555
ee.on('hello', hello);
56-
ee.once('foo', common.fail);
56+
ee.once('foo', assert.fail);
5757
assert.deepStrictEqual(['hello', 'foo'], events_new_listener_emitted);
58-
assert.deepStrictEqual([hello, common.fail], listeners_new_listener_emitted);
58+
assert.deepStrictEqual([hello, assert.fail], listeners_new_listener_emitted);
5959

6060
ee.emit('hello', 'a', 'b');
6161
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
const common = require('../common');
24+
require('../common');
2525
const assert = require('assert');
2626

2727
const EventEmitter = require('events').EventEmitter;
@@ -35,12 +35,12 @@ assert.strictEqual(fl.length, 0);
3535
assert(!(e._events instanceof Object));
3636
assert.deepStrictEqual(Object.keys(e._events), []);
3737

38-
e.on('foo', common.fail);
38+
e.on('foo', assert.fail);
3939
fl = e.listeners('foo');
40-
assert.strictEqual(e._events.foo, common.fail);
40+
assert.strictEqual(e._events.foo, assert.fail);
4141
assert(Array.isArray(fl));
4242
assert.strictEqual(fl.length, 1);
43-
assert.strictEqual(fl[0], common.fail);
43+
assert.strictEqual(fl[0], assert.fail);
4444

4545
e.listeners('bar');
4646

@@ -49,12 +49,12 @@ fl = e.listeners('foo');
4949

5050
assert(Array.isArray(e._events.foo));
5151
assert.strictEqual(e._events.foo.length, 2);
52-
assert.strictEqual(e._events.foo[0], common.fail);
52+
assert.strictEqual(e._events.foo[0], assert.fail);
5353
assert.strictEqual(e._events.foo[1], assert.ok);
5454

5555
assert(Array.isArray(fl));
5656
assert.strictEqual(fl.length, 2);
57-
assert.strictEqual(fl[0], common.fail);
57+
assert.strictEqual(fl[0], assert.fail);
5858
assert.strictEqual(fl[1], assert.ok);
5959

6060
console.log('ok');

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ e.emit('hello', 'a', 'b');
3434
e.emit('hello', 'a', 'b');
3535

3636
const remove = function() {
37-
common.fail('once->foo should not be emitted');
37+
assert.fail('once->foo should not be emitted');
3838
};
3939

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ function listener2() {}
7070
const ee = new EventEmitter();
7171

7272
function remove1() {
73-
common.fail('remove1 should not have been called');
73+
assert.fail('remove1 should not have been called');
7474
}
7575

7676
function remove2() {
77-
common.fail('remove2 should not have been called');
77+
assert.fail('remove2 should not have been called');
7878
}
7979

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

test/parallel/test-exception-handler2.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
const assert = require('assert');
2425

2526
process.on('uncaughtException', function(err) {
2627
console.log('Caught exception: ' + err);
@@ -32,4 +33,4 @@ setTimeout(common.mustCall(function() {
3233

3334
// Intentionally cause an exception, but don't catch it.
3435
nonexistentFunc(); // eslint-disable-line no-undef
35-
common.fail('This will not run.');
36+
assert.fail('This will not run.');

test/parallel/test-fs-null-bytes.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ check(fs.symlink, fs.symlinkSync, fileUrl, 'foobar');
9595
check(fs.symlink, fs.symlinkSync, 'foobar', fileUrl);
9696
check(fs.truncate, fs.truncateSync, fileUrl);
9797
check(fs.unlink, fs.unlinkSync, fileUrl);
98-
check(null, fs.unwatchFile, fileUrl, common.fail);
98+
check(null, fs.unwatchFile, fileUrl, assert.fail);
9999
check(fs.utimes, fs.utimesSync, fileUrl, 0, 0);
100-
check(null, fs.watch, fileUrl, common.fail);
101-
check(null, fs.watchFile, fileUrl, common.fail);
100+
check(null, fs.watch, fileUrl, assert.fail);
101+
check(null, fs.watchFile, fileUrl, assert.fail);
102102
check(fs.writeFile, fs.writeFileSync, fileUrl, 'abc');
103103

104104
check(fs.access, fs.accessSync, fileUrl2);
@@ -123,10 +123,10 @@ check(fs.symlink, fs.symlinkSync, fileUrl2, 'foobar');
123123
check(fs.symlink, fs.symlinkSync, 'foobar', fileUrl2);
124124
check(fs.truncate, fs.truncateSync, fileUrl2);
125125
check(fs.unlink, fs.unlinkSync, fileUrl2);
126-
check(null, fs.unwatchFile, fileUrl2, common.fail);
126+
check(null, fs.unwatchFile, fileUrl2, assert.fail);
127127
check(fs.utimes, fs.utimesSync, fileUrl2, 0, 0);
128-
check(null, fs.watch, fileUrl2, common.fail);
129-
check(null, fs.watchFile, fileUrl2, common.fail);
128+
check(null, fs.watch, fileUrl2, assert.fail);
129+
check(null, fs.watchFile, fileUrl2, assert.fail);
130130
check(fs.writeFile, fs.writeFileSync, fileUrl2, 'abc');
131131

132132
// an 'error' for exists means that it doesn't exist.

test/parallel/test-fs-stat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
6262
try {
6363
stats = fs.fstatSync(fd);
6464
} catch (err) {
65-
common.fail(err);
65+
assert.fail(err);
6666
}
6767
if (stats) {
6868
console.dir(stats);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ common.refreshTmpDir();
4444
const stream = fs.createWriteStream(file);
4545

4646
stream.on('drain', function() {
47-
common.fail('\'drain\' event must not be emitted before ' +
47+
assert.fail('\'drain\' event must not be emitted before ' +
4848
'stream.write() has been called at least once.');
4949
});
5050
stream.destroy();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ process.stderr.write = (data) => {
2626
if (write_calls === 0)
2727
assert.ok(data.match(leak_warning));
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
4242
res.resume();
4343
fn = common.mustCall(createConnectionError);
4444
http.get({ createConnection: fn }, function(res) {
45-
common.fail('Unexpected response callback');
45+
assert.fail('Unexpected response callback');
4646
}).on('error', common.mustCall(function(err) {
4747
assert.strictEqual(err.message, 'Could not create socket');
4848
server.close();

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

+2-2
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
const assert = require('assert');
2425
const http = require('http');
2526

2627
const invalidLocalAddress = '1.2.3.4';
@@ -43,7 +44,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
4344
method: 'GET',
4445
localAddress: invalidLocalAddress
4546
}, function(res) {
46-
common.fail('unexpectedly got response from server');
47+
assert.fail('unexpectedly got response from server');
4748
}).on('error', common.mustCall(function(e) {
4849
console.log('client got error: ' + e.message);
4950
server.close();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const s = http.createServer(common.mustCall((req, res) => {
127127
break;
128128

129129
default:
130-
common.fail('Unknown test');
130+
assert.fail('Unknown test');
131131
}
132132

133133
res.statusCode = 201;
@@ -174,7 +174,7 @@ function nextTest() {
174174
break;
175175

176176
default:
177-
common.fail('Unknown test');
177+
assert.fail('Unknown test');
178178
}
179179

180180
response.setEncoding('utf8');

0 commit comments

Comments
 (0)