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 60de9f8

Browse filesBrowse files
Myles Borinsrvagg
authored andcommitted
test: wrap assert.fail when passed to callback
Currently there are many instances where assert.fail is directly passed to a callback for error handling. Unfortunately this will swallow the error as it is the third argument of assert.fail that sets the message not the first. This commit adds a new function to test/common.js that simply wraps assert.fail and calls it with the provided message. Tip of the hat to @Trott for pointing me in the direction of this. PR-URL: #3453 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 7added3 commit 60de9f8
Copy full SHA for 60de9f8
Expand file treeCollapse file tree

37 files changed

+81
-77
lines changed
Open diff view settings
Collapse file

‎test/common.js‎

Copy file name to clipboardExpand all lines: test/common.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,7 @@ exports.fileExists = function(pathname) {
442442
return false;
443443
}
444444
};
445+
446+
exports.fail = function(msg) {
447+
assert.fail(null, null, msg);
448+
};
Collapse file

‎test/parallel/test-child-process-recv-handle.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-recv-handle.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function master() {
2424
});
2525
proc.stdout.on('data', function(data) {
2626
assert.equal(data, 'ok\r\n');
27-
net.createServer(assert.fail).listen(common.PORT, function() {
27+
net.createServer(common.fail).listen(common.PORT, function() {
2828
handle = this._handle;
2929
proc.send('one');
3030
proc.send('two', handle);
Collapse file

‎test/parallel/test-child-process-spawn-typeerror.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-spawn-typeerror.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const empty = common.fixturesDir + '/empty.js';
1313

1414
assert.throws(function() {
1515
var child = spawn(invalidcmd, 'this is not an array');
16-
child.on('error', assert.fail);
16+
child.on('error', common.fail);
1717
}, TypeError);
1818

1919
// verify that valid argument combinations do not throw
Collapse file

‎test/parallel/test-cluster-bind-privileged-port.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-bind-privileged-port.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ if (cluster.isMaster) {
2020
}));
2121
}
2222
else {
23-
var s = net.createServer(assert.fail);
24-
s.listen(42, assert.fail.bind(null, 'listen should have failed'));
23+
var s = net.createServer(common.fail);
24+
s.listen(42, common.fail.bind(null, 'listen should have failed'));
2525
s.on('error', common.mustCall(function(err) {
2626
assert.equal(err.code, 'EACCES');
2727
process.disconnect();
Collapse file

‎test/parallel/test-cluster-bind-twice.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-bind-twice.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ if (!id) {
6868
else if (id === 'one') {
6969
if (cluster.isMaster) return startWorker();
7070

71-
var server = http.createServer(assert.fail).listen(common.PORT, function() {
71+
var server = http.createServer(common.fail).listen(common.PORT, function() {
7272
process.send('READY');
7373
});
7474

@@ -84,12 +84,12 @@ else if (id === 'two') {
8484
assert(ok);
8585
});
8686

87-
var server = http.createServer(assert.fail);
87+
var server = http.createServer(common.fail);
8888
process.on('message', function(m) {
8989
if (typeof m === 'object') return; // ignore system messages
9090
if (m === 'QUIT') process.exit();
9191
assert.equal(m, 'START');
92-
server.listen(common.PORT, assert.fail);
92+
server.listen(common.PORT, common.fail);
9393
server.on('error', function(e) {
9494
assert.equal(e.code, 'EADDRINUSE');
9595
process.send(e.code);
Collapse file

‎test/parallel/test-cluster-eaddrinuse.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-eaddrinuse.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var net = require('net');
1212
var id = '' + process.argv[2];
1313

1414
if (id === 'undefined') {
15-
var server = net.createServer(assert.fail);
15+
var server = net.createServer(common.fail);
1616
server.listen(common.PORT, function() {
1717
var worker = fork(__filename, ['worker']);
1818
worker.on('message', function(msg) {
@@ -24,14 +24,14 @@ if (id === 'undefined') {
2424
});
2525
}
2626
else if (id === 'worker') {
27-
var server = net.createServer(assert.fail);
28-
server.listen(common.PORT, assert.fail);
27+
var server = net.createServer(common.fail);
28+
server.listen(common.PORT, common.fail);
2929
server.on('error', common.mustCall(function(e) {
3030
assert(e.code, 'EADDRINUSE');
3131
process.send('stop-listening');
3232
process.once('message', function(msg) {
3333
if (msg !== 'stopped-listening') return;
34-
server = net.createServer(assert.fail);
34+
server = net.createServer(common.fail);
3535
server.listen(common.PORT, common.mustCall(function() {
3636
server.close();
3737
}));
Collapse file

‎test/parallel/test-cluster-net-listen.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-net-listen.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ if (cluster.isMaster) {
1717
}
1818
else {
1919
// listen() without port should not trigger a libuv assert
20-
net.createServer(assert.fail).listen(process.exit);
20+
net.createServer(common.fail).listen(process.exit);
2121
}
Collapse file

‎test/parallel/test-cluster-rr-ref.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-rr-ref.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (cluster.isMaster) {
1010
if (msg === 'done') this.kill();
1111
});
1212
} else {
13-
const server = net.createServer(assert.fail);
13+
const server = net.createServer(common.fail);
1414
server.listen(common.PORT, function() {
1515
server.unref();
1616
server.ref();
Collapse file

‎test/parallel/test-cluster-setup-master-argv.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-setup-master-argv.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var common = require('../common');
33
var assert = require('assert');
44
var cluster = require('cluster');
55

6-
setTimeout(assert.fail.bind(assert, 'setup not emitted'), 1000).unref();
6+
setTimeout(common.fail.bind(assert, 'setup not emitted'), 1000).unref();
77

88
cluster.on('setup', function() {
99
var clusterArgs = cluster.settings.args;
Collapse file

‎test/parallel/test-cluster-shared-handle-bind-error.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-shared-handle-bind-error.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (cluster.isMaster) {
88
// Master opens and binds the socket and shares it with the worker.
99
cluster.schedulingPolicy = cluster.SCHED_NONE;
1010
// Hog the TCP port so that when the worker tries to bind, it'll fail.
11-
net.createServer(assert.fail).listen(common.PORT, function() {
11+
net.createServer(common.fail).listen(common.PORT, function() {
1212
var server = this;
1313
var worker = cluster.fork();
1414
worker.on('exit', common.mustCall(function(exitCode) {
@@ -18,8 +18,8 @@ if (cluster.isMaster) {
1818
});
1919
}
2020
else {
21-
var s = net.createServer(assert.fail);
22-
s.listen(common.PORT, assert.fail.bind(null, 'listen should have failed'));
21+
var s = net.createServer(common.fail);
22+
s.listen(common.PORT, common.fail.bind(null, 'listen should have failed'));
2323
s.on('error', common.mustCall(function(err) {
2424
assert.equal(err.code, 'EADDRINUSE');
2525
process.disconnect();

0 commit comments

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