Added support for stderr param for expectation handlers
This is unfortunately one of the cleanest ways to implement this, since stdout is piped to stdin of the handler; I did not want to rely on using a file descriptor, because then you have to deal with issues of rewinding the pointer for possible future uses, and other considerations.env
parent
61051dc165
commit
e3ab1e400e
|
@ -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; }
|
||||
|
||||
|
|
10
src/spec
10
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=
|
||||
|
|
Loading…
Reference in New Issue