{_sstack-=>shspec::stack::_}
parent
aa9044cc97
commit
961ebf0255
28
src/spec.sh
28
src/spec.sh
|
@ -78,12 +78,12 @@ shspec::begin-spec()
|
||||||
shspec::end-spec()
|
shspec::end-spec()
|
||||||
{
|
{
|
||||||
# if the stack is empty then everything is in order
|
# 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
|
# otherwise, output an error message for each item in the stack
|
||||||
until _sstack-empty; do
|
until shspec::stack::_empty; do
|
||||||
_sstack-read type line file _ < <(_sstack-head)
|
shspec::stack::_read type line file _ < <(shspec::stack::_head)
|
||||||
_sstack-pop
|
shspec::stack::_pop
|
||||||
echo "error: unterminated \`$type' at $file:$line"
|
echo "error: unterminated \`$type' at $file:$line"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ shspec::end-spec()
|
||||||
describe()
|
describe()
|
||||||
{
|
{
|
||||||
local -r desc="$*"
|
local -r desc="$*"
|
||||||
_sstack-push "describe" $(caller) "$desc"
|
shspec::stack::_push "describe" $(caller) "$desc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ describe()
|
||||||
it()
|
it()
|
||||||
{
|
{
|
||||||
local -r desc="$*"
|
local -r desc="$*"
|
||||||
_sstack-push "it" $(caller) "$desc"
|
shspec::stack::_push "it" $(caller) "$desc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ it()
|
||||||
# should not use this command.
|
# should not use this command.
|
||||||
end()
|
end()
|
||||||
{
|
{
|
||||||
local -r head="$(_sstack-head-type)"
|
local -r head="$(shspec::stack::_head-type)"
|
||||||
local -r cleanhead="$head"
|
local -r cleanhead="$head"
|
||||||
|
|
||||||
# some statements are implicitly terminated; explicitly doing so is
|
# some statements are implicitly terminated; explicitly doing so is
|
||||||
|
@ -131,7 +131,7 @@ end()
|
||||||
|| shspec::bail \
|
|| shspec::bail \
|
||||||
"unexpected \`end': still processing \`$cleanhead'" $(caller)
|
"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..."
|
# That is, this declares "given this command, I can expect that..."
|
||||||
expect()
|
expect()
|
||||||
{
|
{
|
||||||
_sstack-assert-within it expect $(caller)
|
shspec::stack::_assert-within it expect $(caller)
|
||||||
__spec_result="$("$@" 2>"$__spec_errpath")"
|
__spec_result="$("$@" 2>"$__spec_errpath")"
|
||||||
__spec_rexit=$?
|
__spec_rexit=$?
|
||||||
_sstack-push :expect $(caller) "$@"
|
shspec::stack::_push :expect $(caller) "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,8 +164,8 @@ to()
|
||||||
[ $# -gt 0 ] || \
|
[ $# -gt 0 ] || \
|
||||||
shspec::bail "missing assertion string for \`to'" $__spec_caller
|
shspec::bail "missing assertion string for \`to'" $__spec_caller
|
||||||
|
|
||||||
_sstack-assert-follow :expect to $(caller)
|
shspec::stack::_assert-follow :expect to $(caller)
|
||||||
_sstack-pop
|
shspec::stack::_pop
|
||||||
|
|
||||||
shspec::__handle-to "$__spec_rexit" $__SHIFTN \
|
shspec::__handle-to "$__spec_rexit" $__SHIFTN \
|
||||||
"$__spec_errpath" "$__spec_envpath" "$@" \
|
"$__spec_errpath" "$__spec_envpath" "$@" \
|
||||||
|
@ -223,8 +223,8 @@ and()
|
||||||
|
|
||||||
# the most recently popped value should be an expect premise, implying
|
# the most recently popped value should be an expect premise, implying
|
||||||
# that an expectation declaration implicitly popped it
|
# that an expectation declaration implicitly popped it
|
||||||
_sstack-unpop
|
shspec::stack::_unpop
|
||||||
_sstack-assert-within :expect and $(caller) \
|
shspec::stack::_assert-within :expect and $(caller) \
|
||||||
"follow an expectation as part of"
|
"follow an expectation as part of"
|
||||||
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
|
@ -28,7 +28,7 @@ declare -i __sstackp=0
|
||||||
|
|
||||||
##
|
##
|
||||||
# Push a frame onto the stack
|
# Push a frame onto the stack
|
||||||
_sstack-push()
|
shspec::stack::_push()
|
||||||
{
|
{
|
||||||
local -r type="$1"
|
local -r type="$1"
|
||||||
local -r srcline="$2"
|
local -r srcline="$2"
|
||||||
|
@ -44,7 +44,7 @@ _sstack-push()
|
||||||
# Pop a frame from the stack
|
# Pop a frame from the stack
|
||||||
#
|
#
|
||||||
# It is possible to recover the most recently popped frame.
|
# It is possible to recover the most recently popped frame.
|
||||||
_sstack-pop()
|
shspec::stack::_pop()
|
||||||
{
|
{
|
||||||
[ "$__sstackp" -gt 0 ] || return 1
|
[ "$__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
|
# 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
|
# recover additional frames; it will not work, and you will make bad things
|
||||||
# happen, and people will hate you.
|
# happen, and people will hate you.
|
||||||
_sstack-unpop()
|
shspec::stack::_unpop()
|
||||||
{
|
{
|
||||||
((__sstackp++))
|
((__sstackp++))
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ _sstack-unpop()
|
||||||
|
|
||||||
##
|
##
|
||||||
# Return with a non-zero status only if the stack is non-empty
|
# Return with a non-zero status only if the stack is non-empty
|
||||||
_sstack-empty()
|
shspec::stack::_empty()
|
||||||
{
|
{
|
||||||
test "$__sstackp" -eq 0
|
test "$__sstackp" -eq 0
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ _sstack-empty()
|
||||||
|
|
||||||
##
|
##
|
||||||
# Output the current size of the stack
|
# Output the current size of the stack
|
||||||
_sstack-size()
|
shspec::stack::_size()
|
||||||
{
|
{
|
||||||
echo "$__sstackp"
|
echo "$__sstackp"
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ _sstack-size()
|
||||||
|
|
||||||
##
|
##
|
||||||
# Output the current stack frame
|
# Output the current stack frame
|
||||||
_sstack-head()
|
shspec::stack::_head()
|
||||||
{
|
{
|
||||||
local -ri headi=$((__sstackp-1))
|
local -ri headi=$((__sstackp-1))
|
||||||
echo "${__sstack[$headi]}"
|
echo "${__sstack[$headi]}"
|
||||||
|
@ -94,27 +94,27 @@ _sstack-head()
|
||||||
|
|
||||||
##
|
##
|
||||||
# Output the type of the current stack frame
|
# 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
|
# Output the Nth datum of the current stack frame
|
||||||
__sstack-headn()
|
_shspec::stack::_headn()
|
||||||
{
|
{
|
||||||
local -ri i="$1"
|
local -ri i="$1"
|
||||||
local parts
|
local parts
|
||||||
|
|
||||||
_sstack-read -a parts <<< "$(_sstack-head)"
|
shspec::stack::_read -a parts <<< "$(shspec::stack::_head)"
|
||||||
echo "${parts[$i]}"
|
echo "${parts[$i]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Deconstruct stack frame from stdin in a `read`-like manner
|
# Deconstruct stack frame from stdin in a `read`-like manner
|
||||||
_sstack-read()
|
shspec::stack::_read()
|
||||||
{
|
{
|
||||||
IFS=\| read "$@"
|
IFS=\| read "$@"
|
||||||
}
|
}
|
||||||
|
@ -125,10 +125,10 @@ _sstack-read()
|
||||||
#
|
#
|
||||||
# Return immediately with a non-zero status if there are no frames on the
|
# Return immediately with a non-zero status if there are no frames on the
|
||||||
# stack.
|
# stack.
|
||||||
_sstack-read-pop()
|
shspec::stack::_read-pop()
|
||||||
{
|
{
|
||||||
local -r head="$(_sstack-pop)" || return 1
|
local -r head="$(shspec::stack::_pop)" || return 1
|
||||||
_sstack-read "$@" <<< "$head"
|
shspec::stack::_read "$@" <<< "$head"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ _sstack-read-pop()
|
||||||
#
|
#
|
||||||
# Conceptually, this allows determining if the parent node in a tree-like
|
# Conceptually, this allows determining if the parent node in a tree-like
|
||||||
# structure is of a certain type.
|
# structure is of a certain type.
|
||||||
_sstack-assert-within()
|
shspec::stack::_assert-within()
|
||||||
{
|
{
|
||||||
local -r in="$1"
|
local -r in="$1"
|
||||||
local -r chk="$2"
|
local -r chk="$2"
|
||||||
|
@ -145,7 +145,7 @@ _sstack-assert-within()
|
||||||
local -r file="$4"
|
local -r file="$4"
|
||||||
local -r phrase="${5:-be contained within}"
|
local -r phrase="${5:-be contained within}"
|
||||||
|
|
||||||
local -r head="$(_sstack-head-type)"
|
local -r head="$(shspec::stack::_head-type)"
|
||||||
|
|
||||||
[ "$head" == "$in" ] \
|
[ "$head" == "$in" ] \
|
||||||
|| shspec::bail \
|
|| 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
|
# This is intended to convey a different perspective: that a given node is a
|
||||||
# sibling, not a child, in a tree-like structure.
|
# 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue