Added shift argument to expectation handlers
This allows the implementation to vary in the number of arguments provided to the expectation handlers without breaking BC so long as the meanings of the shifted arguments do not change.stderr
parent
c1d1b66fa9
commit
b3b3a9fcef
7
src/spec
7
src/spec
|
@ -167,7 +167,12 @@ to()
|
||||||
type "$assert" &>/dev/null \
|
type "$assert" &>/dev/null \
|
||||||
|| _bail "unknown expectation: \`$type'" $__spec_caller
|
|| _bail "unknown expectation: \`$type'" $__spec_caller
|
||||||
|
|
||||||
$assert "$__spec_rexit" "$@" <<< "$__spec_result" \
|
# 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" \
|
||||||
|| fail "$expect_full"
|
|| fail "$expect_full"
|
||||||
|
|
||||||
__spec_caller=
|
__spec_caller=
|
||||||
|
|
|
@ -127,30 +127,72 @@ describe expect
|
||||||
'; to fail
|
'; to fail
|
||||||
end
|
end
|
||||||
|
|
||||||
it properly executes quoted command lines
|
|
||||||
expect test-run <<< '
|
# the "premise" is the command executed by the `expect' line
|
||||||
chk() { test $# -eq 1; }
|
describe premise
|
||||||
describe foo
|
it properly executes quoted command lines
|
||||||
it handles whitespace
|
expect test-run <<< '
|
||||||
expect chk "foo bar"
|
chk() { test $# -eq 1; }
|
||||||
to succeed
|
describe foo
|
||||||
|
it handles whitespace
|
||||||
|
expect chk "foo bar"
|
||||||
|
to succeed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
'; to succeed
|
||||||
'; to succeed
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it pipes command stdout to expectation handler
|
|
||||||
expect test-run <<< '
|
|
||||||
declare str=foo
|
|
||||||
_expect--chk() { test "$(cat)" == "$2"; }
|
|
||||||
|
|
||||||
describe foo
|
# the expectation handler performs the assertion logic
|
||||||
it pipes command output
|
describe handler
|
||||||
expect echo "$str"
|
it is provided premise exit code as first argument
|
||||||
to chk "$str"
|
expect test-run <<< '
|
||||||
|
declare excode=123
|
||||||
|
_expect--chk() { test "$1" -eq $excode; }
|
||||||
|
|
||||||
|
describe foo
|
||||||
|
it exposes exit code
|
||||||
|
expect exit $excode
|
||||||
|
to chk
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
'; to succeed
|
||||||
'; to succeed
|
end
|
||||||
|
|
||||||
|
# the "remainder" clause is the portion of the sentence that follows the
|
||||||
|
# execution of the expectation handler
|
||||||
|
it is provided remainder clause after shift argument
|
||||||
|
expect test-run <<< '
|
||||||
|
declare remain="a b c"
|
||||||
|
_expect--chk()
|
||||||
|
{
|
||||||
|
shift "$2"
|
||||||
|
test "$*" == "$remain"
|
||||||
|
}
|
||||||
|
|
||||||
|
describe foo
|
||||||
|
it should expose remainder clause
|
||||||
|
expect true
|
||||||
|
to chk $remain
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'; to succeed
|
||||||
|
end
|
||||||
|
|
||||||
|
it receives premise output via stdin
|
||||||
|
expect test-run <<< '
|
||||||
|
declare str=foo
|
||||||
|
_expect--chk() { test "$(cat)" == "$str"; }
|
||||||
|
|
||||||
|
describe foo
|
||||||
|
it pipes command output
|
||||||
|
expect echo "$str"
|
||||||
|
to chk
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'; to succeed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue