Skip to content

Commit 3ed0204

Browse files
cjihrigevanlucas
authored andcommittedJul 20, 2016
test: s/assert.fail/common.fail as appropriate
Many tests use assert.fail(null, null, msg) where it would be simpler to use common.fail(msg). This is largely because common.fail() is fairly new. This commit makes the replacement when applicable. PR-URL: #7735 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 1f00359 commit 3ed0204

27 files changed

+47
-57
lines changed
 

‎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-
assert.fail(null, null, 'Error should not be emitted if there is callback');
31+
common.fail('Error should not be emitted if there is callback');
3232
}
3333

3434
function onError(err) {

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

+6-6
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
var assert = require('assert');
55

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

17-
e.on('foo', assert.fail);
17+
e.on('foo', common.fail);
1818
fl = e.listeners('foo');
19-
assert(e._events.foo === assert.fail);
19+
assert(e._events.foo === common.fail);
2020
assert(Array.isArray(fl));
2121
assert(fl.length === 1);
22-
assert(fl[0] === assert.fail);
22+
assert(fl[0] === common.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(e._events.foo.length === 2);
31-
assert(e._events.foo[0] === assert.fail);
31+
assert(e._events.foo[0] === common.fail);
3232
assert(e._events.foo[1] === assert.ok);
3333

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

3939
console.log('ok');

‎test/parallel/test-event-emitter-once.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
var assert = require('assert');
44
var events = require('events');
55

@@ -16,7 +16,7 @@ e.emit('hello', 'a', 'b');
1616
e.emit('hello', 'a', 'b');
1717

1818
var remove = function() {
19-
assert.fail(1, 0, 'once->foo should not be emitted', '!');
19+
common.fail('once->foo should not be emitted');
2020
};
2121

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ server.listen(0, () => {
1818
// both a Content-Length header and a Transfer-Encoding: chunked
1919
// header, which is a violation of the HTTP spec.
2020
const req = http.get({port: server.address().port}, (res) => {
21-
assert.fail(null, null, 'callback should not be called');
21+
common.fail('callback should not be called');
2222
});
2323
req.on('error', common.mustCall((err) => {
2424
assert(/^Parse Error/.test(err.message));

‎test/parallel/test-http-client-reject-cr-no-lf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ server.listen(0, () => {
1717
// The callback should not be called because the server is sending a
1818
// header field that ends only in \r with no following \n
1919
const req = http.get({port: server.address().port}, (res) => {
20-
assert.fail(null, null, 'callback should not be called');
20+
common.fail('callback should not be called');
2121
});
2222
req.on('error', common.mustCall((err) => {
2323
assert(/^Parse Error/.test(err.message));

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

+1-1
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-
assert.fail(null, null, 'Unexpected response callback');
24+
common.fail('Unexpected response callback');
2525
}).on('error', common.mustCall(function(err) {
2626
assert.equal(err.message, 'Could not create socket');
2727
server.close();

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ server.listen(0, () => {
2323
// Send two content-length header values.
2424
headers: {'Content-Length': [1, 2]}},
2525
(res) => {
26-
assert.fail(null, null, 'an error should have occurred');
27-
server.close();
26+
common.fail('an error should have occurred');
2827
}
2928
);
3029
req.on('error', common.mustCall(() => {

‎test/parallel/test-http-localaddress-bind-error.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
var assert = require('assert');
44
var http = require('http');
55

@@ -24,7 +24,7 @@ server.listen(0, '127.0.0.1', function() {
2424
method: 'GET',
2525
localAddress: invalidLocalAddress
2626
}, function(res) {
27-
assert.fail(null, null, 'unexpectedly got response from server');
27+
common.fail('unexpectedly got response from server');
2828
}).on('error', function(e) {
2929
console.log('client got error: ' + e.message);
3030
gotError = true;

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

+1-1
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-
assert.fail(null, null, 'should never get here');
22+
common.fail('should never get here');
2323
}
2424
res.end('ok');
2525
});

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const server = http.createServer((req, res) => {
3838
}));
3939
break;
4040
default:
41-
assert.fail(null, null, 'should not get to here.');
41+
common.fail('should not get to here.');
4242
}
4343
if (count === 3)
4444
server.close();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const reqstr = 'POST / HTTP/1.1\r\n' +
1010
'Transfer-Encoding: chunked\r\n\r\n';
1111

1212
const server = http.createServer((req, res) => {
13-
assert.fail(null, null, 'callback should not be invoked');
13+
common.fail('callback should not be invoked');
1414
});
1515
server.on('clientError', common.mustCall((err) => {
1616
assert(/^Parse Error/.test(err.message));
@@ -25,7 +25,7 @@ server.listen(0, () => {
2525
client.on('data', (data) => {
2626
// Should not get to this point because the server should simply
2727
// close the connection without returning any data.
28-
assert.fail(null, null, 'no data should be returned by the server');
28+
common.fail('no data should be returned by the server');
2929
});
3030
client.on('end', common.mustCall(() => {}));
3131
});

‎test/parallel/test-http-server-reject-cr-no-lf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const str = 'GET / HTTP/1.1\r\n' +
1212

1313

1414
const server = http.createServer((req, res) => {
15-
assert.fail(null, null, 'this should not be called');
15+
common.fail('this should not be called');
1616
});
1717
server.on('clientError', common.mustCall((err) => {
1818
assert(/^Parse Error/.test(err.message));
@@ -22,7 +22,7 @@ server.on('clientError', common.mustCall((err) => {
2222
server.listen(0, () => {
2323
const client = net.connect({port: server.address().port}, () => {
2424
client.on('data', (chunk) => {
25-
assert.fail(null, null, 'this should not be called');
25+
common.fail('this should not be called');
2626
});
2727
client.on('end', common.mustCall(() => {
2828
server.close();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ server.listen(0, '127.0.0.1', function() {
3535
method: 'GET',
3636
localAddress: invalidLocalAddress
3737
}, function(res) {
38-
assert.fail(null, null, 'unexpectedly got response from server');
38+
common.fail('unexpectedly got response from server');
3939
}).on('error', function(e) {
4040
console.log('client got error: ' + e.message);
4141
gotError = true;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
43
const net = require('net');
54

6-
const socket = net.connect(common.PORT, common.localhostIPv4, assert.fail);
7-
socket.on('error', assert.fail);
5+
const socket = net.connect(common.PORT, common.localhostIPv4, common.fail);
6+
socket.on('error', common.fail);
87
socket.destroy();
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
43

54
var net = require('net');
65

@@ -10,6 +9,6 @@ net.createServer(function(conn) {
109
net.connect(this.address().port, 'localhost').pause();
1110

1211
setTimeout(function() {
13-
assert.fail(null, null, 'expected to exit');
12+
common.fail('expected to exit');
1413
}, 1000).unref();
1514
}).unref();

‎test/parallel/test-net-listen-close-server-callback-is-not-function.js

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

6-
var server = net.createServer(assert.fail);
6+
var server = net.createServer(common.fail);
77
var closeEvents = 0;
88

99
server.on('close', function() {
1010
++closeEvents;
1111
});
1212

13-
server.listen(0, function() {
14-
assert(false);
15-
});
13+
server.listen(0, common.fail);
1614

1715
server.close('bad argument');
1816

‎test/parallel/test-net-listen-port-option.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ net.Server().listen({ port: '' + common.PORT }, close);
1717
'-Infinity'
1818
].forEach(function(port) {
1919
assert.throws(function() {
20-
net.Server().listen({ port: port }, assert.fail);
20+
net.Server().listen({ port: port }, common.fail);
2121
}, /"port" argument must be >= 0 and < 65536/i);
2222
});
2323

2424
[null, true, false].forEach(function(port) {
2525
assert.throws(function() {
26-
net.Server().listen({ port: port }, assert.fail);
26+
net.Server().listen({ port: port }, common.fail);
2727
}, /invalid listen argument/i);
2828
});

‎test/parallel/test-net-server-max-connections-close-makes-more-available.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
var assert = require('assert');
44

55
var net = require('net');
@@ -86,5 +86,5 @@ process.on('exit', function() {
8686

8787
process.on('unhandledRejection', function() {
8888
console.error('promise rejected');
89-
assert.fail(null, null, 'A promise in the chain rejected');
89+
common.fail('A promise in the chain rejected');
9090
});

‎test/parallel/test-net-write-slow.js

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

@@ -13,8 +13,7 @@ var server = net.createServer(function(socket) {
1313
socket.setNoDelay();
1414
socket.setTimeout(9999);
1515
socket.on('timeout', function() {
16-
assert.fail(null, null, 'flushed: ' + flushed +
17-
', received: ' + received + '/' + SIZE * N);
16+
common.fail(`flushed: ${flushed}, received: ${received}/${SIZE * N}`);
1817
});
1918

2019
for (var i = 0; i < N; ++i) {

‎test/parallel/test-path-parse-format.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 path = require('path');
55

@@ -169,7 +169,7 @@ function checkErrors(path) {
169169
return;
170170
}
171171

172-
assert.fail(null, null, 'should have thrown');
172+
common.fail('should have thrown');
173173
});
174174
}
175175

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
2-
var assert = require('assert');
32
var common = require('../common');
43

54
process.on('beforeExit', common.mustCall(function() {
6-
setTimeout(assert.fail, 5);
5+
setTimeout(common.fail, 5);
76
process.exit(0); // Should execute immediately even if we schedule new work.
8-
assert.fail();
7+
common.fail();
98
}));

‎test/parallel/test-repl-reset-event.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function testResetGlobal(cb) {
4242
}
4343

4444
var timeout = setTimeout(function() {
45-
assert.fail(null, null, 'Timeout, REPL did not emit reset events');
45+
common.fail('Timeout, REPL did not emit reset events');
4646
}, 5000);
4747

4848
testReset(function() {

‎test/parallel/test-repl-tab.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
var assert = require('assert');
44
var repl = require('repl');
55
var zlib = require('zlib');
@@ -10,9 +10,7 @@ var testMe = repl.start('', putIn, function(cmd, context, filename, callback) {
1010
callback(null, cmd);
1111
});
1212

13-
testMe._domain.on('error', function(e) {
14-
assert.fail();
15-
});
13+
testMe._domain.on('error', common.fail);
1614

1715
testMe.complete('', function(err, results) {
1816
assert.equal(err, null);

‎test/parallel/test-spawn-cmd-named-pipe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (!process.argv[2]) {
3939

4040
const comspec = process.env['comspec'];
4141
if (!comspec || comspec.length === 0) {
42-
assert.fail(null, null, 'Failed to get COMSPEC');
42+
common.fail('Failed to get COMSPEC');
4343
}
4444

4545
const args = ['/c', process.execPath, __filename, 'child',

‎test/parallel/test-stream2-base64-single-char-read-end.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
var R = require('_stream_readable');
44
var W = require('_stream_writable');
55
var assert = require('assert');
@@ -33,5 +33,5 @@ src.on('end', function() {
3333
src.pipe(dst);
3434

3535
timeout = setTimeout(function() {
36-
assert.fail(null, null, 'timed out waiting for _write');
36+
common.fail('timed out waiting for _write');
3737
}, 100);

‎test/parallel/test-tls-client-mindhsize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function testDHE2048() {
7575

7676
testDHE1024();
7777

78-
assert.throws(() => test(512, true, assert.fail),
78+
assert.throws(() => test(512, true, common.fail),
7979
/DH parameter is less than 1024 bits/);
8080

8181
[0, -1, -Infinity, NaN].forEach((minDHSize) => {

‎test/sequential/test-child-process-emfile.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ proc.on('error', common.mustCall(function(err) {
4444
}));
4545

4646
proc.on('exit', function() {
47-
const msg = '"exit" should not be emitted (the process never spawned!)';
48-
assert.fail(null, null, msg);
47+
common.fail('"exit" should not be emitted (the process never spawned!)');
4948
});
5049

5150
// close one fd for LSan

0 commit comments

Comments
 (0)
Please sign in to comment.