@@ -406,36 +406,49 @@ function runCallChecks(exitCode) {
406
406
if ( exitCode !== 0 ) return ;
407
407
408
408
const failed = mustCallChecks . filter ( function ( context ) {
409
- return context . actual !== context . expected ;
409
+ if ( 'minimum' in context ) {
410
+ context . messageSegment = `at least ${ context . minimum } ` ;
411
+ return context . actual < context . minimum ;
412
+ } else {
413
+ context . messageSegment = `exactly ${ context . exact } ` ;
414
+ return context . actual !== context . exact ;
415
+ }
410
416
} ) ;
411
417
412
418
failed . forEach ( function ( context ) {
413
- console . log ( 'Mismatched %s function calls. Expected %d , actual %d.' ,
419
+ console . log ( 'Mismatched %s function calls. Expected %s , actual %d.' ,
414
420
context . name ,
415
- context . expected ,
421
+ context . messageSegment ,
416
422
context . actual ) ;
417
423
console . log ( context . stack . split ( '\n' ) . slice ( 2 ) . join ( '\n' ) ) ;
418
424
} ) ;
419
425
420
426
if ( failed . length ) process . exit ( 1 ) ;
421
427
}
422
428
429
+ exports . mustCall = function ( fn , exact ) {
430
+ return _mustCallInner ( fn , exact , 'exact' ) ;
431
+ } ;
423
432
424
- exports . mustCall = function ( fn , expected ) {
433
+ exports . mustCallAtLeast = function ( fn , minimum ) {
434
+ return _mustCallInner ( fn , minimum , 'minimum' ) ;
435
+ } ;
436
+
437
+ function _mustCallInner ( fn , criteria , field ) {
425
438
if ( typeof fn === 'number' ) {
426
- expected = fn ;
439
+ criteria = fn ;
427
440
fn = noop ;
428
441
} else if ( fn === undefined ) {
429
442
fn = noop ;
430
443
}
431
444
432
- if ( expected === undefined )
433
- expected = 1 ;
434
- else if ( typeof expected !== 'number' )
435
- throw new TypeError ( `Invalid expected value: ${ expected } ` ) ;
445
+ if ( criteria === undefined )
446
+ criteria = 1 ;
447
+ else if ( typeof criteria !== 'number' )
448
+ throw new TypeError ( `Invalid ${ field } value: ${ criteria } ` ) ;
436
449
437
450
const context = {
438
- expected : expected ,
451
+ [ field ] : criteria ,
439
452
actual : 0 ,
440
453
stack : ( new Error ( ) ) . stack ,
441
454
name : fn . name || '<anonymous>'
@@ -450,7 +463,7 @@ exports.mustCall = function(fn, expected) {
450
463
context . actual ++ ;
451
464
return fn . apply ( this , arguments ) ;
452
465
} ;
453
- } ;
466
+ }
454
467
455
468
exports . hasMultiLocalhost = function hasMultiLocalhost ( ) {
456
469
const TCP = process . binding ( 'tcp_wrap' ) . TCP ;
0 commit comments