{_sstack-=>shspec::stack::_}

master
Mike Gerwitz 2014-06-13 17:17:30 -04:00
parent aa9044cc97
commit 961ebf0255
2 changed files with 33 additions and 33 deletions

View File

@ -78,12 +78,12 @@ shspec::begin-spec()
shspec::end-spec()
{
# if the stack is empty then everything is in order
_sstack-empty && return 0
shspec::stack::_empty && return 0
# otherwise, output an error message for each item in the stack
until _sstack-empty; do
_sstack-read type line file _ < <(_sstack-head)
_sstack-pop
until shspec::stack::_empty; do
shspec::stack::_read type line file _ < <(shspec::stack::_head)
shspec::stack::_pop
echo "error: unterminated \`$type' at $file:$line"
done
@ -100,7 +100,7 @@ shspec::end-spec()
describe()
{
local -r desc="$*"
_sstack-push "describe" $(caller) "$desc"
shspec::stack::_push "describe" $(caller) "$desc"
}
@ -111,7 +111,7 @@ describe()
it()
{
local -r desc="$*"
_sstack-push "it" $(caller) "$desc"
shspec::stack::_push "it" $(caller) "$desc"
}
@ -122,7 +122,7 @@ it()
# should not use this command.
end()
{
local -r head="$(_sstack-head-type)"
local -r head="$(shspec::stack::_head-type)"
local -r cleanhead="$head"
# some statements are implicitly terminated; explicitly doing so is
@ -131,7 +131,7 @@ end()
|| shspec::bail \
"unexpected \`end': still processing \`$cleanhead'" $(caller)
_sstack-pop >/dev/null || shspec::bail "unmatched \`end'"
shspec::stack::_pop >/dev/null || shspec::bail "unmatched \`end'"
}
@ -145,10 +145,10 @@ end()
# That is, this declares "given this command, I can expect that..."
expect()
{
_sstack-assert-within it expect $(caller)
shspec::stack::_assert-within it expect $(caller)
__spec_result="$("$@" 2>"$__spec_errpath")"
__spec_rexit=$?
_sstack-push :expect $(caller) "$@"
shspec::stack::_push :expect $(caller) "$@"
}
@ -164,8 +164,8 @@ to()
[ $# -gt 0 ] || \
shspec::bail "missing assertion string for \`to'" $__spec_caller
_sstack-assert-follow :expect to $(caller)
_sstack-pop
shspec::stack::_assert-follow :expect to $(caller)
shspec::stack::_pop
shspec::__handle-to "$__spec_rexit" $__SHIFTN \
"$__spec_errpath" "$__spec_envpath" "$@" \
@ -223,8 +223,8 @@ and()
# the most recently popped value should be an expect premise, implying
# that an expectation declaration implicitly popped it
_sstack-unpop
_sstack-assert-within :expect and $(caller) \
shspec::stack::_unpop
shspec::stack::_assert-within :expect and $(caller) \
"follow an expectation as part of"
"$@"

View File

@ -28,7 +28,7 @@ declare -i __sstackp=0
##
# Push a frame onto the stack
_sstack-push()
shspec::stack::_push()
{
local -r type="$1"
local -r srcline="$2"
@ -44,7 +44,7 @@ _sstack-push()
# Pop a frame from the stack
#
# It is possible to recover the most recently popped frame.
_sstack-pop()
shspec::stack::_pop()
{
[ "$__sstackp" -gt 0 ] || return 1
@ -61,7 +61,7 @@ _sstack-pop()
# Note that this should never be called more than once in an attempt to
# recover additional frames; it will not work, and you will make bad things
# happen, and people will hate you.
_sstack-unpop()
shspec::stack::_unpop()
{
((__sstackp++))
}
@ -69,7 +69,7 @@ _sstack-unpop()
##
# Return with a non-zero status only if the stack is non-empty
_sstack-empty()
shspec::stack::_empty()
{
test "$__sstackp" -eq 0
}
@ -77,7 +77,7 @@ _sstack-empty()
##
# Output the current size of the stack
_sstack-size()
shspec::stack::_size()
{
echo "$__sstackp"
}
@ -85,7 +85,7 @@ _sstack-size()
##
# Output the current stack frame
_sstack-head()
shspec::stack::_head()
{
local -ri headi=$((__sstackp-1))
echo "${__sstack[$headi]}"
@ -94,27 +94,27 @@ _sstack-head()
##
# Output the type of the current stack frame
_sstack-head-type()
shspec::stack::_head-type()
{
__sstack-headn 0
_shspec::stack::_headn 0
}
##
# Output the Nth datum of the current stack frame
__sstack-headn()
_shspec::stack::_headn()
{
local -ri i="$1"
local parts
_sstack-read -a parts <<< "$(_sstack-head)"
shspec::stack::_read -a parts <<< "$(shspec::stack::_head)"
echo "${parts[$i]}"
}
##
# Deconstruct stack frame from stdin in a `read`-like manner
_sstack-read()
shspec::stack::_read()
{
IFS=\| read "$@"
}
@ -125,10 +125,10 @@ _sstack-read()
#
# Return immediately with a non-zero status if there are no frames on the
# stack.
_sstack-read-pop()
shspec::stack::_read-pop()
{
local -r head="$(_sstack-pop)" || return 1
_sstack-read "$@" <<< "$head"
local -r head="$(shspec::stack::_pop)" || return 1
shspec::stack::_read "$@" <<< "$head"
}
@ -137,7 +137,7 @@ _sstack-read-pop()
#
# Conceptually, this allows determining if the parent node in a tree-like
# structure is of a certain type.
_sstack-assert-within()
shspec::stack::_assert-within()
{
local -r in="$1"
local -r chk="$2"
@ -145,7 +145,7 @@ _sstack-assert-within()
local -r file="$4"
local -r phrase="${5:-be contained within}"
local -r head="$(_sstack-head-type)"
local -r head="$(shspec::stack::_head-type)"
[ "$head" == "$in" ] \
|| shspec::bail \
@ -154,12 +154,12 @@ _sstack-assert-within()
##
# Alias for _sstack-assert-within with altered error message
# Alias for shspec::stack::_assert-within with altered error message
#
# This is intended to convey a different perspective: that a given node is a
# sibling, not a child, in a tree-like structure.
_sstack-assert-follow()
shspec::stack::_assert-follow()
{
_sstack-assert-within "$@" follow
shspec::stack::_assert-within "$@" follow
}