mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-05-06 07:36:20 +02:00
48606 + 48607 + unposted test: zmathfunc: Force arguments to be numbers and catch errors.
This commit is contained in:
parent
e7711e37e4
commit
b0bd14035d
|
@ -1,5 +1,9 @@
|
||||||
2021-04-21 Daniel Shahaf <d.s@daniel.shahaf.name>
|
2021-04-21 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||||
|
|
||||||
|
* 48606 + 48607 + unposted test: Functions/Math/zmathfunc,
|
||||||
|
Test/Z02zmathfunc.ztst: zmathfunc: Force arguments to be numbers
|
||||||
|
and catch errors.
|
||||||
|
|
||||||
* unposted (cf. 48156): Test/Z02zmathfunc.ztst: New test.
|
* unposted (cf. 48156): Test/Z02zmathfunc.ztst: New test.
|
||||||
|
|
||||||
* users/26635 (tweaked):
|
* users/26635 (tweaked):
|
||||||
|
|
|
@ -6,7 +6,12 @@ zsh_math_func_min() {
|
||||||
shift
|
shift
|
||||||
local arg
|
local arg
|
||||||
for arg ; do
|
for arg ; do
|
||||||
(( $arg < result )) && result=$arg
|
(( arg < result ))
|
||||||
|
case $? in
|
||||||
|
(0) (( result = arg ));;
|
||||||
|
(1) ;;
|
||||||
|
(*) return $?;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
(( result ))
|
(( result ))
|
||||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||||
|
@ -19,7 +24,12 @@ zsh_math_func_max() {
|
||||||
shift
|
shift
|
||||||
local arg
|
local arg
|
||||||
for arg ; do
|
for arg ; do
|
||||||
(( $arg > result )) && result=$arg
|
(( arg > result ))
|
||||||
|
case $? in
|
||||||
|
(0) (( result = arg ));;
|
||||||
|
(1) ;;
|
||||||
|
(*) return $?;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
(( result ))
|
(( result ))
|
||||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||||
|
@ -31,7 +41,7 @@ zsh_math_func_sum() {
|
||||||
local sum
|
local sum
|
||||||
local arg
|
local arg
|
||||||
for arg ; do
|
for arg ; do
|
||||||
(( sum += $arg ))
|
(( sum += arg ))
|
||||||
done
|
done
|
||||||
(( sum ))
|
(( sum ))
|
||||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||||
|
|
|
@ -44,7 +44,13 @@
|
||||||
?(eval):1: wrong number of arguments: max()
|
?(eval):1: wrong number of arguments: max()
|
||||||
|
|
||||||
zsh_math_func_min "foo bar" x y z
|
zsh_math_func_min "foo bar" x y z
|
||||||
2dDf:check errors from an unsupported use-case (workers/48156)
|
2d:check errors from an unsupported use-case (workers/48156)
|
||||||
|
# We expect one non-empty line of stderr, but don't care about the specific
|
||||||
|
# error message; thus, the expectation is a pattern (*), for stderr (?), which
|
||||||
|
# matches any non-empty string (?*).
|
||||||
|
#
|
||||||
|
# Sorry, Perl, but I had to give you a run for your money.
|
||||||
|
*??*
|
||||||
F:Calling zsh_math_func_min directly isn't a supported use-case, but if it
|
F:Calling zsh_math_func_min directly isn't a supported use-case, but if it
|
||||||
F:returns zero, something's probably wrong.
|
F:returns zero, something's probably wrong.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue