mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-12-29 16:25:35 +01:00
48147/0002: zmathfunc: Fix bug where the exit code would be non-zero if the expression evaluted to zero.
This commit is contained in:
parent
6a2a8acf09
commit
f87b73e677
3 changed files with 13 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
|||
2021-03-07 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
||||
* 48147/0002: Functions/Math/zmathfunc, Test/Z02zmathfunc.ztst:
|
||||
zmathfunc: Fix bug where the exit code would be non-zero if
|
||||
the expression evaluted to zero.
|
||||
|
||||
* 48147/0001: Test/Z02zmathfunc.ztst: tests: Add a unit test for
|
||||
zmathfunc and a regression test for workers/48146 affecting it.
|
||||
|
||||
|
|
|
@ -1,34 +1,40 @@
|
|||
#autoload
|
||||
|
||||
zsh_math_func_min() {
|
||||
emulate -L zsh
|
||||
local result=$1
|
||||
shift
|
||||
local arg
|
||||
for arg ; do
|
||||
(( $arg < result )) && result=$arg
|
||||
done
|
||||
(( result )) # return
|
||||
(( result ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
}
|
||||
functions -M min 1 -1 zsh_math_func_min # at least one argument
|
||||
|
||||
zsh_math_func_max() {
|
||||
emulate -L zsh
|
||||
local result=$1
|
||||
shift
|
||||
local arg
|
||||
for arg ; do
|
||||
(( $arg > result )) && result=$arg
|
||||
done
|
||||
(( result )) # return
|
||||
(( result ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
}
|
||||
functions -M max 1 -1 zsh_math_func_max # at least one argument
|
||||
|
||||
zsh_math_func_sum() {
|
||||
emulate -L zsh
|
||||
local sum
|
||||
local arg
|
||||
for arg ; do
|
||||
(( sum += $arg ))
|
||||
done
|
||||
(( sum ))
|
||||
true # Careful here: `return 0` evaluates an arithmetic expression
|
||||
}
|
||||
functions -M sum 0 -1 zsh_math_func_sum
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
(set -e; echo $(( min(0, 42) )))
|
||||
(set -e; echo $(( max(0, -42) )))
|
||||
(set -e; echo $(( sum(42, -42) )))
|
||||
-f:regression test for ERR_EXIT
|
||||
0:regression test for ERR_EXIT
|
||||
>0
|
||||
>0
|
||||
>0
|
||||
|
|
Loading…
Reference in a new issue