Permalink
Browse files

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: nodejs#12293
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
Trott committed Apr 9, 2017
1 parent 6f202ef commit 06c29a66d479cf324037537d319dd2368b2692b7
Showing with 101 additions and 106 deletions.
  1. +0 −6 test/README.md
  2. +3 −8 test/common.js
  3. +1 −1 test/inspector/inspector-helper.js
  4. +1 −1 test/internet/test-dgram-send-cb-quelches-error.js
  5. +1 −1 test/internet/test-dns.js
  6. +1 −1 test/internet/test-tls-add-ca-cert.js
  7. +3 −2 test/parallel/test-beforeexit-event-exit.js
  8. +1 −1 test/parallel/test-child-process-fork-and-spawn.js
  9. +1 −1 test/parallel/test-child-process-stdout-flush-exit.js
  10. +1 −1 test/parallel/test-cluster-send-handle-twice.js
  11. +2 −2 test/parallel/test-common.js
  12. +2 −2 test/parallel/test-dgram-address.js
  13. +1 −1 test/parallel/test-dgram-implicit-bind-failure.js
  14. +3 −2 test/parallel/test-domain-uncaught-exception.js
  15. +2 −2 test/parallel/test-event-emitter-add-listeners.js
  16. +6 −6 test/parallel/test-event-emitter-listeners-side-effects.js
  17. +1 −1 test/parallel/test-event-emitter-once.js
  18. +2 −2 test/parallel/test-event-emitter-remove-listeners.js
  19. +2 −1 test/parallel/test-exception-handler2.js
  20. +6 −6 test/parallel/test-fs-null-bytes.js
  21. +1 −1 test/parallel/test-fs-stat.js
  22. +1 −1 test/parallel/test-fs-write-stream.js
  23. +1 −1 test/parallel/test-global-console-exists.js
  24. +1 −1 test/parallel/test-http-createConnection.js
  25. +2 −2 test/parallel/test-http-invalid-path-chars.js
  26. +2 −1 test/parallel/test-http-localaddress-bind-error.js
  27. +2 −2 test/parallel/test-http-mutable-headers.js
  28. +2 −2 test/parallel/test-http-response-multi-content-length.js
  29. +2 −2 test/parallel/test-http-response-splitting.js
  30. +2 −2 test/parallel/test-http-response-status-message.js
  31. +1 −1 test/parallel/test-http-server-reject-chunked-with-content-length.js
  32. +1 −1 test/parallel/test-http-unix-socket.js
  33. +2 −1 test/parallel/test-https-localaddress-bind-error.js
  34. +2 −2 test/parallel/test-net-error-twice.js
  35. +3 −3 test/parallel/test-net-pipe-connect-errors.js
  36. +2 −2 test/parallel/test-net-server-max-connections-close-makes-more-available.js
  37. +1 −1 test/parallel/test-net-server-pause-on-connect.js
  38. +1 −1 test/parallel/test-net-write-slow.js
  39. +2 −2 test/parallel/test-next-tick-when-exiting.js
  40. +2 −1 test/parallel/test-process-exit-from-before-exit.js
  41. +1 −1 test/parallel/test-process-no-deprecation.js
  42. +15 −15 test/parallel/test-promises-unhandled-rejections.js
  43. +1 −1 test/parallel/test-spawn-cmd-named-pipe.js
  44. +2 −2 test/parallel/test-stream2-base64-single-char-read-end.js
  45. +1 −1 test/parallel/test-tls-econnreset.js
  46. +1 −1 test/parallel/test-tls-empty-sni-context.js
  47. +1 −1 test/parallel/test-tls-session-cache.js
  48. +2 −2 test/parallel/test-util-inspect.js
  49. +1 −1 test/parallel/test-vm-debug-context.js
  50. +2 −2 test/parallel/test-vm-syntax-error-message.js
  51. +1 −1 test/parallel/test-vm-syntax-error-stderr.js
View
@@ -246,12 +246,6 @@ Checks whether `IPv6` is supported on this platform.
Checks if there are multiple localhosts available.
### fail(msg)
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
Throws an `AssertionError` with `msg`
### fileExists(pathname)
* pathname [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
View
@@ -404,7 +404,7 @@ process.on('exit', function() {
if (!exports.globalCheck) return;
const leaked = leakedGlobals();
if (leaked.length > 0) {
fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`);
}
});
@@ -507,14 +507,9 @@ exports.canCreateSymLink = function() {
return true;
};
function fail(msg) {
assert.fail(null, null, msg);
}
exports.fail = fail;
exports.mustNotCall = function(msg) {
return function mustNotCall() {
fail(msg || 'function should not have been called');
assert.fail(msg || 'function should not have been called');
};
};
@@ -627,7 +622,7 @@ exports.WPT = {
},
assert_array_equals: assert.deepStrictEqual,
assert_unreached(desc) {
assert.fail(undefined, undefined, `Reached unreachable code: ${desc}`);
assert.fail(`Reached unreachable code: ${desc}`);
}
};
@@ -217,7 +217,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
for (const id in this.messages_) {
s += id + ', ';
}
common.fail('Messages without response: ' +
assert.fail('Messages without response: ' +
s.substring(0, s.length - 2));
}, TIMEOUT);
});
@@ -28,7 +28,7 @@ function callbackOnly(err) {
}
function onEvent(err) {
common.fail('Error should not be emitted if there is callback');
assert.fail('Error should not be emitted if there is callback');
}
function onError(err) {
@@ -453,7 +453,7 @@ TEST(function test_lookup_all_mixed(done) {
else if (isIPv6(ip.address))
assert.strictEqual(ip.family, 6);
else
common.fail('unexpected IP address');
assert.fail('unexpected IP address');
});
done();
@@ -38,7 +38,7 @@ tls.connect(opts, fail).on('error', common.mustCall((err) => {
}));
function fail() {
common.fail('should fail to connect');
assert.fail('should fail to connect');
}
// New secure contexts have the well-known root CAs.
@@ -20,10 +20,11 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
process.on('beforeExit', function() {
common.fail('exit should not allow this to occur');
assert.fail('exit should not allow this to occur');
});
process.exit();
@@ -37,7 +37,7 @@ switch (process.argv[2] || '') {
case 'spawn':
break;
default:
common.fail();
assert.fail();
}
function checkExit(statusCode) {
@@ -42,7 +42,7 @@ if (process.argv[2] === 'child') {
child.stderr.setEncoding('utf8');
child.stderr.on('data', function(data) {
common.fail(`Unexpected parent stderr: ${data}`);
assert.fail(`Unexpected parent stderr: ${data}`);
});
// check if we receive both 'hello' at start and 'goodbye' at end
@@ -51,7 +51,7 @@ if (cluster.isMaster) {
setTimeout(function() { client.end(); }, 50);
}).on('error', function(e) {
console.error(e);
common.fail('server.listen failed');
assert.fail('server.listen failed');
cluster.worker.disconnect();
});
}
@@ -40,8 +40,8 @@ assert.throws(function() {
}, /^TypeError: Invalid expected value: \/foo\/$/);
// common.fail() tests
// assert.fail() tests
assert.throws(
() => { common.fail('fhqwhgads'); },
() => { assert.fail('fhqwhgads'); },
/^AssertionError: fhqwhgads$/
);
@@ -41,7 +41,7 @@ const dgram = require('dgram');
socket.on('error', (err) => {
socket.close();
common.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
});
socket.bind(0, common.localhostIPv4);
@@ -65,7 +65,7 @@ if (common.hasIPv6) {
socket.on('error', (err) => {
socket.close();
common.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
assert.fail(`Unexpected error on udp6 socket. ${err.toString()}`);
});
socket.bind(0, localhost);
@@ -40,7 +40,7 @@ socket.on('error', (err) => {
return;
}
common.fail(`Unexpected error: ${err}`);
assert.fail(`Unexpected error: ${err}`);
});
// Initiate a few send() operations, which will fail.
@@ -9,6 +9,7 @@
*/
const common = require('../common');
const assert = require('assert');
const domain = require('domain');
const child_process = require('child_process');
@@ -183,14 +184,14 @@ if (process.argv[2] === 'child') {
test.expectedMessages.forEach(function(expectedMessage) {
if (test.messagesReceived === undefined ||
test.messagesReceived.indexOf(expectedMessage) === -1)
common.fail('test ' + test.fn.name + ' should have sent message: ' +
assert.fail('test ' + test.fn.name + ' should have sent message: ' +
expectedMessage + ' but didn\'t');
});
if (test.messagesReceived) {
test.messagesReceived.forEach(function(receivedMessage) {
if (test.expectedMessages.indexOf(receivedMessage) === -1) {
common.fail('test ' + test.fn.name +
assert.fail('test ' + test.fn.name +
' should not have sent message: ' + receivedMessage +
' but did');
}
@@ -53,9 +53,9 @@ const EventEmitter = require('events');
});
ee.on('hello', hello);
ee.once('foo', common.fail);
ee.once('foo', assert.fail);
assert.deepStrictEqual(['hello', 'foo'], events_new_listener_emitted);
assert.deepStrictEqual([hello, common.fail], listeners_new_listener_emitted);
assert.deepStrictEqual([hello, assert.fail], listeners_new_listener_emitted);
ee.emit('hello', 'a', 'b');
}
@@ -21,7 +21,7 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const EventEmitter = require('events').EventEmitter;
@@ -35,12 +35,12 @@ assert.strictEqual(fl.length, 0);
assert(!(e._events instanceof Object));
assert.deepStrictEqual(Object.keys(e._events), []);
e.on('foo', common.fail);
e.on('foo', assert.fail);
fl = e.listeners('foo');
assert.strictEqual(e._events.foo, common.fail);
assert.strictEqual(e._events.foo, assert.fail);
assert(Array.isArray(fl));
assert.strictEqual(fl.length, 1);
assert.strictEqual(fl[0], common.fail);
assert.strictEqual(fl[0], assert.fail);
e.listeners('bar');
@@ -49,12 +49,12 @@ fl = e.listeners('foo');
assert(Array.isArray(e._events.foo));
assert.strictEqual(e._events.foo.length, 2);
assert.strictEqual(e._events.foo[0], common.fail);
assert.strictEqual(e._events.foo[0], assert.fail);
assert.strictEqual(e._events.foo[1], assert.ok);
assert(Array.isArray(fl));
assert.strictEqual(fl.length, 2);
assert.strictEqual(fl[0], common.fail);
assert.strictEqual(fl[0], assert.fail);
assert.strictEqual(fl[1], assert.ok);
console.log('ok');
@@ -34,7 +34,7 @@ e.emit('hello', 'a', 'b');
e.emit('hello', 'a', 'b');
const remove = function() {
common.fail('once->foo should not be emitted');
assert.fail('once->foo should not be emitted');
};
e.once('foo', remove);
@@ -70,11 +70,11 @@ function listener2() {}
const ee = new EventEmitter();
function remove1() {
common.fail('remove1 should not have been called');
assert.fail('remove1 should not have been called');
}
function remove2() {
common.fail('remove2 should not have been called');
assert.fail('remove2 should not have been called');
}
ee.on('removeListener', common.mustCall(function(name, cb) {
@@ -21,6 +21,7 @@
'use strict';
const common = require('../common');
const assert = require('assert');
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
@@ -32,4 +33,4 @@ setTimeout(common.mustCall(function() {
// Intentionally cause an exception, but don't catch it.
nonexistentFunc(); // eslint-disable-line no-undef
common.fail('This will not run.');
assert.fail('This will not run.');
@@ -95,10 +95,10 @@ check(fs.symlink, fs.symlinkSync, fileUrl, 'foobar');
check(fs.symlink, fs.symlinkSync, 'foobar', fileUrl);
check(fs.truncate, fs.truncateSync, fileUrl);
check(fs.unlink, fs.unlinkSync, fileUrl);
check(null, fs.unwatchFile, fileUrl, common.fail);
check(null, fs.unwatchFile, fileUrl, assert.fail);
check(fs.utimes, fs.utimesSync, fileUrl, 0, 0);
check(null, fs.watch, fileUrl, common.fail);
check(null, fs.watchFile, fileUrl, common.fail);
check(null, fs.watch, fileUrl, assert.fail);
check(null, fs.watchFile, fileUrl, assert.fail);
check(fs.writeFile, fs.writeFileSync, fileUrl, 'abc');
check(fs.access, fs.accessSync, fileUrl2);
@@ -123,10 +123,10 @@ check(fs.symlink, fs.symlinkSync, fileUrl2, 'foobar');
check(fs.symlink, fs.symlinkSync, 'foobar', fileUrl2);
check(fs.truncate, fs.truncateSync, fileUrl2);
check(fs.unlink, fs.unlinkSync, fileUrl2);
check(null, fs.unwatchFile, fileUrl2, common.fail);
check(null, fs.unwatchFile, fileUrl2, assert.fail);
check(fs.utimes, fs.utimesSync, fileUrl2, 0, 0);
check(null, fs.watch, fileUrl2, common.fail);
check(null, fs.watchFile, fileUrl2, common.fail);
check(null, fs.watch, fileUrl2, assert.fail);
check(null, fs.watchFile, fileUrl2, assert.fail);
check(fs.writeFile, fs.writeFileSync, fileUrl2, 'abc');
// an 'error' for exists means that it doesn't exist.
@@ -62,7 +62,7 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) {
try {
stats = fs.fstatSync(fd);
} catch (err) {
common.fail(err);
assert.fail(err);
}
if (stats) {
console.dir(stats);
@@ -44,7 +44,7 @@ common.refreshTmpDir();
const stream = fs.createWriteStream(file);
stream.on('drain', function() {
common.fail('\'drain\' event must not be emitted before ' +
assert.fail('\'drain\' event must not be emitted before ' +
'stream.write() has been called at least once.');
});
stream.destroy();
@@ -26,7 +26,7 @@ process.stderr.write = (data) => {
if (write_calls === 0)
assert.ok(data.match(leak_warning));
else
common.fail('stderr.write should be called only once');
assert.fail('stderr.write should be called only once');
write_calls++;
};
@@ -42,7 +42,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
res.resume();
fn = common.mustCall(createConnectionError);
http.get({ createConnection: fn }, function(res) {
common.fail('Unexpected response callback');
assert.fail('Unexpected response callback');
}).on('error', common.mustCall(function(err) {
assert.strictEqual(err.message, 'Could not create socket');
server.close();
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const http = require('http');
@@ -8,7 +8,7 @@ const theExperimentallyDeterminedNumber = 39;
function fail(path) {
assert.throws(() => {
http.request({ path }, common.fail);
http.request({ path }, assert.fail);
}, expectedError);
}
@@ -21,6 +21,7 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const invalidLocalAddress = '1.2.3.4';
@@ -43,7 +44,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
method: 'GET',
localAddress: invalidLocalAddress
}, function(res) {
common.fail('unexpectedly got response from server');
assert.fail('unexpectedly got response from server');
}).on('error', common.mustCall(function(e) {
console.log('client got error: ' + e.message);
server.close();
@@ -127,7 +127,7 @@ const s = http.createServer(common.mustCall((req, res) => {
break;
default:
common.fail('Unknown test');
assert.fail('Unknown test');
}
res.statusCode = 201;
@@ -174,7 +174,7 @@ function nextTest() {
break;
default:
common.fail('Unknown test');
assert.fail('Unknown test');
}
response.setEncoding('utf8');
Oops, something went wrong.

0 comments on commit 06c29a6

Please sign in to comment.