Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove assert.doesNotThrow() #18669

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ rules:
no-mixed-spaces-and-tabs: error
no-multiple-empty-lines: [error, {max: 2, maxEOF: 0, maxBOF: 0}]
no-restricted-syntax: [error, {
selector: "CallExpression[callee.object.name='assert'][callee.property.name='doesNotThrow']",
message: "Please replace `assert.doesNotThrow()` and add a comment next to the code instead."
}, {
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.1.type='Literal']:not([arguments.1.regex])",
message: "use a regular expression for second argument of assert.throws()"
message: "Use a regular expression for second argument of assert.throws()"
}, {
selector: "CallExpression[callee.object.name='assert'][callee.property.name='throws'][arguments.length<2]",
message: "assert.throws() must be invoked with at least two arguments."
Expand Down
1 change: 1 addition & 0 deletions benchmark/assert/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function main({ n, method }) {
case 'doesNotThrow':
bench.start();
for (i = 0; i < n; ++i) {
// eslint-disable-next-line no-restricted-syntax
assert.doesNotThrow(doesNotThrow);
}
bench.end(n);
Expand Down
3 changes: 3 additions & 0 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ to the caller.
The following, for instance, will throw the [`TypeError`][] because there is no
matching error type in the assertion:

<!-- eslint-disable no-restricted-syntax -->
```js
assert.doesNotThrow(
() => {
Expand All @@ -353,6 +354,7 @@ assert.doesNotThrow(
However, the following will result in an `AssertionError` with the message
'Got unwanted exception (TypeError)..':

<!-- eslint-disable no-restricted-syntax -->
```js
assert.doesNotThrow(
() => {
Expand All @@ -366,6 +368,7 @@ If an `AssertionError` is thrown and a value is provided for the `message`
parameter, the value of `message` will be appended to the `AssertionError`
message:

<!-- eslint-disable no-restricted-syntax -->
```js
assert.doesNotThrow(
() => {
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_general/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const y = {};
test_general.wrap(y);
test_general.removeWrap(y);
// Wrapping twice succeeds if a remove_wrap() separates the instances
assert.doesNotThrow(() => test_general.wrap(y));
test_general.wrap(y);

// Ensure that removing a wrap and garbage collecting does not fire the
// finalize callback.
Expand Down
2 changes: 1 addition & 1 deletion test/addons/symlinked-module/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ const sub = require('./submodule');
const mod = require(path.join(i, 'binding.node'));
assert.notStrictEqual(mod, null);
assert.strictEqual(mod.hello(), 'world');
assert.doesNotThrow(() => sub.test(i));
sub.test(i); // Should not throw.
});
10 changes: 3 additions & 7 deletions test/internet/test-dgram-membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// addMembership() with valid socket and multicast address should not throw
{
const socket = setup();
assert.doesNotThrow(() => { socket.addMembership(multicastAddress); });
socket.addMembership(multicastAddress);
socket.close();
}

Expand All @@ -27,11 +27,7 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// dropMembership() after addMembership() should not throw
{
const socket = setup();
assert.doesNotThrow(
() => {
socket.addMembership(multicastAddress);
socket.dropMembership(multicastAddress);
}
);
socket.addMembership(multicastAddress);
socket.dropMembership(multicastAddress);
socket.close();
}
17 changes: 5 additions & 12 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,8 @@ process.on('exit', function() {
assert.ok(getaddrinfoCallbackCalled);
});


assert.doesNotThrow(() =>
dns.lookup(addresses.INET6_HOST, 6, common.mustCall()));

assert.doesNotThrow(() =>
dns.lookup(addresses.INET_HOST, {}, common.mustCall()));

assert.doesNotThrow(() =>
dns.lookupService('0.0.0.0', '0', common.mustCall()));

assert.doesNotThrow(() =>
dns.lookupService('0.0.0.0', 0, common.mustCall()));
// Should not throw.
dns.lookup(addresses.INET6_HOST, 6, common.mustCall());
dns.lookup(addresses.INET_HOST, {}, common.mustCall());
dns.lookupService('0.0.0.0', '0', common.mustCall());
dns.lookupService('0.0.0.0', 0, common.mustCall());
8 changes: 4 additions & 4 deletions test/parallel/test-assert-checktag.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function re(literals, ...values) {
FakeDate.prototype = Date.prototype;
const fake = new FakeDate();

assert.doesNotThrow(() => assert.deepEqual(date, fake));
assert.doesNotThrow(() => assert.deepEqual(fake, date));
assert.deepEqual(date, fake);
assert.deepEqual(fake, date);

// For deepStrictEqual we check the runtime type,
// then reveal the fakeness of the fake date
Expand All @@ -47,7 +47,7 @@ function re(literals, ...values) {
for (const prop of Object.keys(global)) {
fakeGlobal[prop] = global[prop];
}
assert.doesNotThrow(() => assert.deepEqual(fakeGlobal, global));
assert.deepEqual(fakeGlobal, global);
// Message will be truncated anyway, don't validate
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global),
assert.AssertionError);
Expand All @@ -59,7 +59,7 @@ function re(literals, ...values) {
for (const prop of Object.keys(process)) {
fakeProcess[prop] = process[prop];
}
assert.doesNotThrow(() => assert.deepEqual(fakeProcess, process));
assert.deepEqual(fakeProcess, process);
// Message will be truncated anyway, don't validate
assert.throws(() => assert.deepStrictEqual(fakeProcess, process),
assert.AssertionError);
Expand Down
Loading