Fixing bug in try
This commit is contained in:
parent
6de7798c8a
commit
c3425e0933
2 changed files with 4 additions and 2 deletions
|
@ -173,12 +173,12 @@ catch() {
|
||||||
local val=$(2>&1 eval "$cmd"; echo $?)
|
local val=$(2>&1 eval "$cmd"; echo $?)
|
||||||
local cnt=$(list $val | wc -l)
|
local cnt=$(list $val | wc -l)
|
||||||
local status=$(list $val | last)
|
local status=$(list $val | last)
|
||||||
list "$cmd" $status $(list $val | take $((cnt - 1)) | unlist | tup) | $f
|
$f < <(list "$cmd" $status $(list $val | take $((cnt - 1)) | unlist | tup))
|
||||||
}
|
}
|
||||||
|
|
||||||
try() {
|
try() {
|
||||||
local f="$@"
|
local f="$@"
|
||||||
catch lambda cmd status val . '[[ $status -eq 0 ]] && tupl $val || list $status | '$f
|
catch lambda cmd status val . '[[ $status -eq 0 ]] && tupx 1- $val | unlist || { '"$f"' < <(list $status); }'
|
||||||
}
|
}
|
||||||
|
|
||||||
ret() {
|
ret() {
|
||||||
|
|
|
@ -4,6 +4,8 @@ testTry() {
|
||||||
assertEquals 1 "$(echo 'expr 2 / 2' | try lambda _ . 'ret 0')"
|
assertEquals 1 "$(echo 'expr 2 / 2' | try lambda _ . 'ret 0')"
|
||||||
assertEquals 0 "$(echo 'expr 2 / 0' | try lambda _ . 'ret 0')"
|
assertEquals 0 "$(echo 'expr 2 / 0' | try lambda _ . 'ret 0')"
|
||||||
assertEquals 2 "$(echo 'expr 2 / 0' | try lambda status . 'ret $status')"
|
assertEquals 2 "$(echo 'expr 2 / 0' | try lambda status . 'ret $status')"
|
||||||
|
assertEquals 'already up to date' "$(echo 'echo already up to date' | try lambda _ . 'ret error')"
|
||||||
|
assertEquals 'error exit 1' "$(try λ _ . 'echo "error"; echo exit 1' < <(echo fgit pull) | unlist)"
|
||||||
}
|
}
|
||||||
|
|
||||||
. ./shunit2-init.sh
|
. ./shunit2-init.sh
|
Loading…
Reference in a new issue