diff --git a/src/expect-core b/src/expect-core index c45f1db..29dbb45 100644 --- a/src/expect-core +++ b/src/expect-core @@ -34,6 +34,23 @@ _bail_clause() } +## +# Asserts that at least the given argument shift count was provided +# +# The shift count is used to determine where shspec's arguments end and +# where the remainder clause begins; this ensures that shspec can continue +# to evolve in the future without BC breaks in properly designed expection +# handlers. +__chk-nshift() +{ + local -ri expect="$1" + local -ri given="$2" + + test "$given" -ge "$expect" || _bail \ + "internal: expected shift of at least $expect, but given $given" +} + + _expect--succeed() { test "$1" -eq 0; } _expect--fail() { test "$1" -ne 0; } diff --git a/src/spec b/src/spec index feaab9c..0b0f5a5 100644 --- a/src/spec +++ b/src/spec @@ -168,11 +168,11 @@ to() || _bail "unknown expectation: \`$type'" $__spec_caller # first argument is exit code, second is the number of arguments to shift - # to place $1 at the remainder clause, and all remaining arguments are - # said remainder clause; the shift argument allows the implementation to - # vary without breaking BC so long as the meaning of the shifted arguments - # do not change - $assert "$__spec_rexit" 2 "$@" <<< "$__spec_result" \ + # to place $1 at the remainder clause, third is the path to the stderr + # output file, and all remaining arguments are said remainder clause; the + # shift argument allows the implementation to vary without breaking BC so + # long as the meaning of the shifted arguments do not change + $assert "$__spec_rexit" 3 "$__spec_errpath" "$@" <<< "$__spec_result" \ || fail "$expect_full" __spec_caller=