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.stderr
parent
2b5411d67a
commit
d90acab122
|
@ -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--succeed() { test "$1" -eq 0; }
|
||||||
_expect--fail() { test "$1" -ne 0; }
|
_expect--fail() { test "$1" -ne 0; }
|
||||||
|
|
||||||
|
|
10
src/spec
10
src/spec
|
@ -168,11 +168,11 @@ to()
|
||||||
|| _bail "unknown expectation: \`$type'" $__spec_caller
|
|| _bail "unknown expectation: \`$type'" $__spec_caller
|
||||||
|
|
||||||
# first argument is exit code, second is the number of arguments to shift
|
# 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
|
# to place $1 at the remainder clause, third is the path to the stderr
|
||||||
# said remainder clause; the shift argument allows the implementation to
|
# output file, and all remaining arguments are said remainder clause; the
|
||||||
# vary without breaking BC so long as the meaning of the shifted arguments
|
# shift argument allows the implementation to vary without breaking BC so
|
||||||
# do not change
|
# long as the meaning of the shifted arguments do not change
|
||||||
$assert "$__spec_rexit" 2 "$@" <<< "$__spec_result" \
|
$assert "$__spec_rexit" 3 "$__spec_errpath" "$@" <<< "$__spec_result" \
|
||||||
|| fail "$expect_full"
|
|| fail "$expect_full"
|
||||||
|
|
||||||
__spec_caller=
|
__spec_caller=
|
||||||
|
|
Loading…
Reference in New Issue