Commit 007ad1d1 authored by Frank Terbeck's avatar Frank Terbeck

vcsup: Propagate return values from cd builtin

parent 9b780e9b
......@@ -262,6 +262,7 @@ function VCSUP_push() {
}
function VCSUP_from_() {
local -i ret
VCSUP_pop $1
ret=$?
if (( ret == 2 )); then
......@@ -270,8 +271,9 @@ function VCSUP_from_() {
printf 'vcsup-BUG: Please report how this happened.\n' >&2
else
VCSUP_cd "${REPLY}"
ret=$?
fi
return 0
return $ret
}
function VCSUP_stacksize() {
......@@ -312,6 +314,7 @@ function VCSUP_cd() {
VCSUP_push ${PWD}
fi
unset VCSUPGUARD
return $ret
}
function "${cmd}" () {
......@@ -329,6 +332,7 @@ function "${cmd}" () {
if [[ ${PWD} != ${vcsupdata[currentbasedir]} ]]; then
VCSUPGUARD='-guarded-'
builtin cd ${vcsupdata[currentbasedir]}
ret=$?
unset VCSUPGUARD
fi
elif [[ ${PWD} != ${vcsupdata[currentbasedir]} ]]; then
......@@ -337,6 +341,7 @@ function "${cmd}" () {
fi
VCSUPGUARD='-guarded-'
builtin cd ${vcsupdata[currentbasedir]}
ret=$?
unset VCSUPGUARD
else
VCSUP_from_top 0
......@@ -346,16 +351,20 @@ function "${cmd}" () {
context="${context}:plus"
if zstyle -t ${context} stack-minus; then
VCSUP_from_top "${match[@]}"
ret=$?
else
VCSUP_from_bot "${match[@]}"
ret=$?
fi
;;
(-|(#b)-(<->))
context="${context}:minus"
if zstyle -t ${context} stack-minus; then
VCSUP_from_bot "${match[@]}"
ret=$?
else
VCSUP_from_top "${match[@]}"
ret=$?
fi
;;
(-h|--help)
......@@ -364,6 +373,7 @@ function "${cmd}" () {
[[ -z ${vcsupdata[currentbasedir]} ]] && return 1
VCSUPGUARD='-guarded-'
builtin cd "${vcsupdata[currentbasedir]}"
ret=$?
unset VCSUPGUARD
;;
(*)
......@@ -373,6 +383,7 @@ function "${cmd}" () {
return 1
fi
VCSUP_cd "$1"
ret=$?
;;
esac
......
......@@ -15,8 +15,20 @@ vcs_info
autoload -Uz vcsupinit
vcsupinit ,
# Simulate updating vcs_info state in precmd() or similar:
function comma () { , "$@"; vcs_info; }
function tool () { vcsuptool "$@"; vcs_info; }
function comma () {
local -i rc
, "$@"
rc=$?
vcs_info
return $rc
}
function tool () {
local -i rc
vcsuptool "$@"
rc=$?
vcs_info
return $rc
}
#functions -t -- +vi-vcsup-setup
#functions -t -- +vi-vcsup-destroy
......@@ -86,8 +98,23 @@ function expect_pwd () {
fi
return 0
}
echo
function expect_return_value () {
local title="$1"
local expect="$2"
local actual="$3"
(( ntests++ ))
printf '#%s: %s\n' $ntests $title
if [[ $expect != $actual ]]; then
printf '%s: Expected return value (%s) not met: %s\n' \
$0 $expect $actual
(( nfailed++ ))
return 1
fi
return 0
}
echo
# Default behaviour:
#
# - Dups are not filtered
......@@ -129,6 +156,10 @@ expect_stack "Many entries on the stack" \
$base/src/periph/mu \
$base/src/drivers/spi
# comma needs to propagate builtin errors properly:
comma does-not-exist
expect_return_value "Comma fails with non-existing directory" 1 $?
# Teardown
printf '\nRemoving test base directory: %s\n' $base
rm -Rf $base || exit 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment