tools: add lint rule to ensure assertions are reached

PR-URL: https://github.com/nodejs/node/pull/60125
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
Antoine du Hamel committed 2025-11-12 00:15:32 +01:00
1 parent daaaf04a32
commit 2a85aa4e7b
47 files changed
+458 -217

No files matched your search

@@ -46,9 +46,9 @@ for (let i = 0; i < arr.length; i++)
arr[i] = {};
assert.strictEqual(hook_result.destroy_called, false);
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(hook_result.destroy_called, false);
makeCallback(asyncResource, process, () => {
makeCallback(asyncResource, process, common.mustCall(() => {
const executionAsyncResource = async_hooks.executionAsyncResource();
// Assuming the executionAsyncResource was created for the absence of the
// initial `{ foo: 'bar' }`.
@@ -58,8 +58,8 @@ setImmediate(() => {
assert.strictEqual(typeof executionAsyncResource, 'object');
assert.strictEqual(executionAsyncResource.foo, undefined);
destroyAsyncResource(asyncResource);
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(hook_result.destroy_called, true);
});
});
});
}));
}));
}));
@@ -39,6 +39,6 @@ for (let i = 0; i < arr.length; i++)
arr[i] = {};
assert.strictEqual(hook_result.destroy_called, false);
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(hook_result.destroy_called, true);
});
}));
+6 -6
View File
@@ -40,7 +40,7 @@ const resourceWrap = createAsyncResource(
assert.strictEqual(hook_result.destroy_called, false);
const recv = {};
makeCallback(resourceWrap, recv, function callback() {
makeCallback(resourceWrap, recv, common.mustCall(function callback() {
assert.strictEqual(hook_result.destroy_called, false);
assert.strictEqual(
hook_result.resource,
@@ -48,7 +48,7 @@ makeCallback(resourceWrap, recv, function callback() {
);
assert.strictEqual(this, recv);
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(hook_result.destroy_called, false);
assert.notStrictEqual(
hook_result.resource,
@@ -56,8 +56,8 @@ makeCallback(resourceWrap, recv, function callback() {
);
destroyAsyncResource(resourceWrap);
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(hook_result.destroy_called, true);
});
});
});
}));
}));
}));
+1
View File
@@ -11,6 +11,7 @@ function testFinalize(binding) {
x = null;
global.gc();
process.on('uncaughtException', (err) => {
// eslint-disable-next-line node-core/must-call-assert
assert.strictEqual(err.message, 'Error during Finalize');
});
@@ -39,15 +39,15 @@ test_hook.enable();
* slots. Testing with plain object here.
*/
const resource = {};
makeCallback(resource, process, function cb() {
makeCallback(resource, process, common.mustCall(function cb() {
assert.strictEqual(this, process);
assert.strictEqual(async_hooks.executionAsyncResource(), resource);
});
}));
assert.strictEqual(hook_result.init_called, true);
assert.strictEqual(hook_result.before_called, true);
assert.strictEqual(hook_result.after_called, true);
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(hook_result.destroy_called, true);
test_hook.disable();
});
}));
@@ -72,11 +72,11 @@ assert.throws(function() {
if (arg === 1) {
// The tests are first run on bootstrap during LoadEnvironment() in
// src/node.cc. Now run the tests through node::MakeCallback().
setImmediate(function() {
setImmediate(common.mustCall(function() {
makeCallback({}, common.mustCall(function() {
verifyExecutionOrder(2);
}));
});
}));
} else if (arg === 2) {
// Make sure there are no conflicts using node::MakeCallback()
// within timers.
@@ -7,7 +7,7 @@
// and symbol types, while in newer versions they can be created for
// any value type.
//
const { buildType } = require('../../common');
const { mustCall, buildType } = require('../../common');
const { gcUntil } = require('../../common/gc');
const assert = require('assert');
const addon_v8 = require(`./build/${buildType}/test_reference_obj_only`);
@@ -122,4 +122,4 @@ async function runAllTests() {
await runTests(addon_new, /* isVersion8 */ false, /* isLocalSymbol */ false);
}
runAllTests();
runAllTests().then(mustCall());
@@ -44,9 +44,9 @@ function testWithJSMarshaller({
array.push(value);
if (array.length === quitAfter) {
setImmediate(() => {
binding.StopThread(common.mustCall(() => {
binding.StopThread(() => {
resolve(array);
}), !!abort);
}, !!abort);
});
}
}, !!abort, !!launchSecondary, maxQueueSize);
@@ -79,19 +79,19 @@ function testUnref(queueSize) {
new Promise(function testWithoutJSMarshaller(resolve) {
let callCount = 0;
binding.StartThreadNoNative(function testCallback() {
binding.StartThreadNoNative(common.mustCallAtLeast(function testCallback() {
callCount++;
// The default call-into-JS implementation passes no arguments.
assert.strictEqual(arguments.length, 0);
if (callCount === binding.ARRAY_LENGTH) {
setImmediate(() => {
binding.StopThread(common.mustCall(() => {
binding.StopThread(() => {
resolve();
}), false);
}, false);
});
}
}, false /* abort */, false /* launchSecondary */, binding.MAX_QUEUE_SIZE);
}), false /* abort */, false /* launchSecondary */, binding.MAX_QUEUE_SIZE);
})
// Start the thread in blocking mode, and assert that all values are passed.
@@ -224,4 +224,6 @@ new Promise(function testWithoutJSMarshaller(resolve) {
.then(() => testUnref(binding.MAX_QUEUE_SIZE))
// Start a child process with an infinite queue to test rapid teardown
.then(() => testUnref(0));
.then(() => testUnref(0))
.then(common.mustCall());