From d90acab12229ecc1f0d0503defda82172e92bbc6 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 12 May 2014 21:35:47 -0400 Subject: [PATCH] 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. --- src/expect-core | 17 +++++++++++++++++ src/spec | 10 +++++----- 2 files changed, 22 insertions(+), 5 deletions(-) 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=