From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19574 invoked from network); 7 Mar 2021 17:17:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Mar 2021 17:17:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1615137454; b=LzyusP3Q0zSBUoAzJxQQrs9xIL6viqIUifD5zTy/8Y2sD6r8kybIPh/kOMWvrBTHJGOWcyPoxO 43hEHf8529DGL3fVlO+pNgz+mtSrxBH1R6S1o7fUSoVg8u8XJGcDa/96lLnizKy2YUvd+SAyfU YTZaP53++oiRanvXxhUsLgfktxtBLFL2zPqbQ9XEoggQ7pk4uMVz84Tdq8TbmNzX56Cb64qQrz WR4CIlZnhZvUNUchbJcaMvaRnXJlm5+5ao6BQVSNwg379dYscKBnLCPSGg5YWEu88+wNb158On hhAnOoNlMFnx4K02GcxJ+CuP+7iq2GGRrbAWxS74WOAPyQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out4-smtp.messagingengine.com) smtp.remote-ip=66.111.4.28; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1615137454; bh=l2kBz7JA/goS2VXWD0miq1g9P7cMXDkr69ZFcZMWRZE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature:DKIM-Signature:DKIM-Signature; b=PNl/S6CYtZ0lb4WweuBoh3rzKxLVQfTfeczwo7sRySdklqZCDb1nmhaISrZyVZdScArgF0i+7j BFmg+IWj9/2AEJC2V0RzIS78jqWMG0XGkxNI9B5cIIHUXT85+MUUrU4QnAd1CdYl9w+HKJjJ5x iPMIPbCrhUWy3GQyEoAcFofzGjFZ0j25cSsol78Q2bL86bQM3GLb96TopIi8kMIxGSRIFNByrI v9C/5IjQnl1Uk6lvnnI26LqSHwDASeTBH0v7xxOQegaR65i5D/OiA9KRgjLiOgEiAayMkSjmsy yYQBtbW9j9HvV/YgYCtvFeQDwVigSU6PyxoJ713MZi37Lg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Oh3zFD4sdl2xGtjf4RzhjgWxyrq/DdLSiuvLJkqYyqg=; b=gahtIKDZqc3d0+253f3uCWKVVZ PAXK6UGKla8K/+zqra0M4kq94x+osVcAbqYhDffD3dcvt36b9Xs2DZDTpN8XutFKBHgDA6XuxGqOd Nr4cc827FJxZkD+DCzBsiVWwHMs1P31rAMWO1t+k0OZeS58R2CIzclCBCQgDWoBzKDdd/k+IJz2qp a+DRgE49jbsrxoVsEU5ZklfN/fSEH7RNXy4NB+7dUR8csMNLiG+03LlCYdr+uAwW/39NnpIhRqGrp Jg+qfkdBE606MRRFENsarz6qIx6a6jARurjomraAuNa/ferd72wHSSzlUddzvnNKKk4kvoRy7VXu2 +jJVHH4A==; Received: from authenticated user by zero.zsh.org with local id 1lIx25-000J0a-W9; Sun, 07 Mar 2021 17:17:34 +0000 Authentication-Results: zsh.org; iprev=pass (out4-smtp.messagingengine.com) smtp.remote-ip=66.111.4.28; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out4-smtp.messagingengine.com ([66.111.4.28]:56029) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lIx1p-000IrC-C0; Sun, 07 Mar 2021 17:17:19 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 11A475C0106; Sun, 7 Mar 2021 12:17:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 07 Mar 2021 12:17:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=fm2; bh=Oh3 zFD4sdl2xGtjf4RzhjgWxyrq/DdLSiuvLJkqYyqg=; b=GfuLSAhDKFfAMEGEVtv 6Tgf92W9S1zsS6j+gbJhH10JgLqc5hO7QEuHmRMl96lwmcTaRVzShpZ6km1zINTT lfGlupRNwHGsMd9lK7TKdRrcGHbFxvmXSL7F7Y8ZFzo7EVNLGKyMN4PYtDjpKzkq 8KUazBQXg0Ks2Lz9jEpzd+6rwmyPDtlzaAAJ8QwPDXA8I+JAJvTE5TKfnVtNnNVD kGHrX8RQjsOcXED6VYKwCoEqTmfHrWwLndiv+1nY0MOjP5vvQRWL6iftHrs1J/S/ GLcQ4Z5xfBVh8BcOvoiZ7I4VJksRqP/oUdPxABVeWuvBPq+9IrDQxcsuOxjgCObu 3hw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Oh3zFD 4sdl2xGtjf4RzhjgWxyrq/DdLSiuvLJkqYyqg=; b=ESr2WBG+7DSibSsTjROV66 QlnKEv5vBAtFAwaP8eDw0tzAooO8bEz1EbZNuZc0HK5mhbXv9lC+Bg/NxvCVtC+v eRmzQNGfxBy+SNH2aj7f95eJrUq3n9PEHk3WASFP6kY4uL7tt20c9fA9fEz6oR62 Yc6Scr9xeTHcDpbBqm3obVmb8CuEpDLpImH4L0zczTPzSOroS3u9kwV31CGfB3nH xOzc1RyiaFyaw/9NLmSC+h0rN2q9tMANtr8xdqhCImdwgHZLrUGNZCK8dYqetFQq IWX8EZQW96Bz1jnAHJboKCQpqsVVN34IBE9oLMWhLY8dKOhzvQ8cEHU0ymVaXTRA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledruddutddgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujggfsehmtd dtredtredvnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceougdrshesuggrnhhi vghlrdhshhgrhhgrfhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpeduhefhieegkeduue eiieffieeutdegjeekueevuefhveeuuefgieehhfeivddutdenucfkphepjeelrddujeel rdehledruddvtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-79-179-59-120.red.bezeqint.net [79.179.59.120]) by mail.messagingengine.com (Postfix) with ESMTPA id 466FF24005C; Sun, 7 Mar 2021 12:17:15 -0500 (EST) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4Dtp7D4z3Bzm7; Sun, 7 Mar 2021 17:17:12 +0000 (UTC) Date: Sun, 7 Mar 2021 17:17:12 +0000 From: Daniel Shahaf To: Nikolaus Thiel Cc: zsh-workers@zsh.org Subject: Re: zmathfunc: min, max, sum throw error if result equals 0 Message-ID: <20210307171712.GA9936@tarpaulin.shahaf.local2> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="x+6KMIRAuhnl3hBn" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 48147 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Nikolaus Thiel wrote on Sun, Mar 07, 2021 at 17:37:09 +0100: > There seems to be a bug in zmathfunc: > > When the result of min, max or sum equals 0, the functions throw an error. If > they are used within a script with the option "set -e" then the script aborts, > cf. test script below. Ouch. Patch series attached. However, the examples in zshbuiltins(1) (under `functions -M`) have the same bug. Would you perchance be interested in fixing those? The manual sources are in Doc/Zsh/*.yo. Review below. > if [[ ${OS} == "Darwin" ]]; then > ### Mac OS X > source /usr/share/zsh/5.8/functions/zmathfunc > else > ### Ubuntu 20.04 > source /usr/share/zsh/functions/Math/zmathfunc > fi autoload -Uz zmathfunc && zmathfunc > echo "OS = ${OS}" typeset -p OS or use the builtin variable: typeset -p OSTYPE > zsh --version echo $ZSH_VERSION $ZSH_PATCHLEVEL > Cheers, Daniel --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-tests-Add-a-unit-test-for-zmathfunc-and-a-regres.patch.txt" >From eed36947fb1a35cdaf21638fb49ecfc4f40cdfc5 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 7 Mar 2021 16:58:03 +0000 Subject: [PATCH 1/2] tests: Add a unit test for zmathfunc and a regression test for workers/48146 affecting it. --- Test/Z02zmathfunc.ztst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Test/Z02zmathfunc.ztst diff --git a/Test/Z02zmathfunc.ztst b/Test/Z02zmathfunc.ztst new file mode 100644 index 000000000..94bc59576 --- /dev/null +++ b/Test/Z02zmathfunc.ztst @@ -0,0 +1,23 @@ +%prep + autoload -Uz zmathfunc && zmathfunc + +%test + + echo $(( min(42, 43) )) $(( max(42, 43) )) $(( sum(42, 43) )) + echo $(( min(42) )) $(( max(42) )) $(( sum(42) )) + echo $(( sum() )) +0:basic functionality test +>42 43 85 +>42 42 42 +>0 + + + (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 +>0 +>0 + +%clean --x+6KMIRAuhnl3hBn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-zmathfunc-Fix-bug-where-the-exit-code-would-be-n.patch.txt" >From dca20086146e7c6022e394cc760ad39b12d96db2 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 7 Mar 2021 17:07:06 +0000 Subject: [PATCH 2/2] zmathfunc: Fix bug where the exit code would be non-zero if the expression evaluted to zero. --- Functions/Math/zmathfunc | 10 ++++++++-- Test/Z02zmathfunc.ztst | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Functions/Math/zmathfunc b/Functions/Math/zmathfunc index 4ff40700d..8e4b78549 100644 --- a/Functions/Math/zmathfunc +++ b/Functions/Math/zmathfunc @@ -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 diff --git a/Test/Z02zmathfunc.ztst b/Test/Z02zmathfunc.ztst index 94bc59576..43a0a0d76 100644 --- a/Test/Z02zmathfunc.ztst +++ b/Test/Z02zmathfunc.ztst @@ -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 --x+6KMIRAuhnl3hBn--