Skip to content

Commit 686e753

Browse files
Trottjasnell
authored andcommitted
test: use common.mustNotCall in test-crypto-random
Use `common.mustNotCall()` to confirm that noop callbacks are not run when functions throw errors. PR-URL: #13183 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 7b97f07 commit 686e753

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

test/parallel/test-crypto-random.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
3838
[crypto.randomBytes, crypto.pseudoRandomBytes].forEach(function(f) {
3939
[-1, undefined, null, false, true, {}, []].forEach(function(value) {
4040
assert.throws(function() { f(value); }, expectedErrorRegexp);
41-
assert.throws(function() { f(value, common.noop); }, expectedErrorRegexp);
41+
assert.throws(function() { f(value, common.mustNotCall()); },
42+
expectedErrorRegexp);
4243
});
4344

4445
[0, 1, 2, 4, 16, 256, 1024].forEach(function(len) {
@@ -153,11 +154,11 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
153154
}, /offset must be a number/);
154155

155156
assert.throws(() => {
156-
crypto.randomFill(buf, 'test', common.noop);
157+
crypto.randomFill(buf, 'test', common.mustNotCall());
157158
}, /offset must be a number/);
158159

159160
assert.throws(() => {
160-
crypto.randomFill(buf, NaN, common.noop);
161+
crypto.randomFill(buf, NaN, common.mustNotCall());
161162
}, /offset must be a number/);
162163

163164
const max = require('buffer').kMaxLength + 1;
@@ -171,11 +172,11 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
171172
}, /offset out of range/);
172173

173174
assert.throws(() => {
174-
crypto.randomFill(buf, 11, common.noop);
175+
crypto.randomFill(buf, 11, common.mustNotCall());
175176
}, /offset out of range/);
176177

177178
assert.throws(() => {
178-
crypto.randomFill(buf, max, common.noop);
179+
crypto.randomFill(buf, max, common.mustNotCall());
179180
}, /offset out of range/);
180181

181182
assert.throws(() => {
@@ -187,11 +188,11 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
187188
}, /size must be a number/);
188189

189190
assert.throws(() => {
190-
crypto.randomFill(buf, 0, 'test', common.noop);
191+
crypto.randomFill(buf, 0, 'test', common.mustNotCall());
191192
}, /size must be a number/);
192193

193194
assert.throws(() => {
194-
crypto.randomFill(buf, 0, NaN, common.noop);
195+
crypto.randomFill(buf, 0, NaN, common.mustNotCall());
195196
}, /size must be a number/);
196197

197198
{
@@ -206,11 +207,11 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
206207
}, /size must be a uint32/);
207208

208209
assert.throws(() => {
209-
crypto.randomFill(buf, 0, -10, common.noop);
210+
crypto.randomFill(buf, 0, -10, common.mustNotCall());
210211
}, /size must be a uint32/);
211212

212213
assert.throws(() => {
213-
crypto.randomFill(buf, 0, size, common.noop);
214+
crypto.randomFill(buf, 0, size, common.mustNotCall());
214215
}, /size must be a uint32/);
215216
}
216217

@@ -219,23 +220,23 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
219220
}, /offset must be a uint32/);
220221

221222
assert.throws(() => {
222-
crypto.randomFill(buf, -10, common.noop);
223+
crypto.randomFill(buf, -10, common.mustNotCall());
223224
}, /offset must be a uint32/);
224225

225226
assert.throws(() => {
226227
crypto.randomFillSync(buf, 1, 10);
227228
}, /buffer too small/);
228229

229230
assert.throws(() => {
230-
crypto.randomFill(buf, 1, 10, common.noop);
231+
crypto.randomFill(buf, 1, 10, common.mustNotCall());
231232
}, /buffer too small/);
232233

233234
assert.throws(() => {
234235
crypto.randomFillSync(buf, 0, 12);
235236
}, /buffer too small/);
236237

237238
assert.throws(() => {
238-
crypto.randomFill(buf, 0, 12, common.noop);
239+
crypto.randomFill(buf, 0, 12, common.mustNotCall());
239240
}, /buffer too small/);
240241

241242
{
@@ -246,7 +247,7 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
246247
}, /offset must be a uint32/);
247248

248249
assert.throws(() => {
249-
crypto.randomFill(buf, offset, 10, common.noop);
250+
crypto.randomFill(buf, offset, 10, common.mustNotCall());
250251
}, /offset must be a uint32/);
251252
}
252253
}

0 commit comments

Comments
 (0)