zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] ERR_EXIT with "for" loops and shell functions (Re: Bug report)
Date: Fri, 2 Jan 2015 16:56:23 +0000	[thread overview]
Message-ID: <20150102165623.7c4e3dd1@ntlworld.com> (raw)
In-Reply-To: <141227163220.ZM11821@torch.brasslantern.com>

On Sat, 27 Dec 2014 16:32:20 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Dec 26,  6:35pm, Bart Schaefer wrote:
> }
> } This is very tricky because we have to propagate the value of $? from
> } before the "for" keyword (including before the start of the function)
> } into the "do" body, but must *not* *use* the value of $? for deciding
> } whether to exit-on-error, because the nonzero value came from an "if"
> } test.  There is a "noerrexit" flag that is supposed to cover this case,
> } but it's not set when the very first "sublist" in a function body is
> } a for-loop (there are likely to be other similar cases).
> 
> The following patch attempts to fix all of this weirdness.

I had a look at this myself while in 2Gnetworkland, and sent a couple of
messages which didn't get through quite possibly because the gmail app
sent them to zsh-hackers@zsh.org for undetermined reasons.

However, you must have found everything I did since the tests I added
now pass.  They're all just for status, nothing specific to ERR_EXIT or
ERR_RETURN; I didn't find I needed to change anything there in the main
code, just for the status value itself.  They overlap with yours but that's no big deal.  Here they are.

diff --git a/Test/A07control.ztst b/Test/A07control.ztst
index 397a821..b1a2487 100644
--- a/Test/A07control.ztst
+++ b/Test/A07control.ztst
@@ -110,3 +110,56 @@
   done
 1:break error case -1
 ?(eval):break:2: argument is not positive: -1
+
+  false
+  for x in; do
+    print nothing executed
+  done
+0:Status 0 from for with explicit empty list
+
+  set --
+  false
+  for x; do
+    print nothing executed
+  done
+0:Status 0 from for with implicit empty list
+
+  (exit 2)
+  for x in 1 2; do
+    print $?
+  done
+0:Status from previous command propagated into for loop
+>2
+>0
+
+  false
+  for x in $(echo 1 2; (exit 3)); do
+    print $?
+  done
+0:Status from expansion propagated into for loop
+>3
+>0
+
+  false
+  for x in $(exit 4); do
+    print not executed
+  done
+0:Status from expansion not propagated after unexecuted for loop
+  
+  false
+  for x in NonExistentFilePrefix*(N); do
+    print not executed, either
+  done
+0:Status from before for loop not propagated if empty after expansion
+
+  for x in $(echo 1; false); do
+  done
+0:Status reset by empty list in for loop
+
+  false
+  for x in $(echo 1; false); do
+    echo $?
+    (exit 4)  
+  done
+4:Last status from loop body is kept even with other funny business going on
+>1

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2015-01-02 17:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-26 16:53 Bug report mvxxc
2014-12-27  2:35 ` Bart Schaefer
2014-12-28  0:32   ` [PATCH] ERR_EXIT with "for" loops and shell functions (Re: Bug report) Bart Schaefer
2015-01-02 16:56     ` Peter Stephenson [this message]
2015-01-02 18:56       ` Bart Schaefer
2015-01-02 20:15         ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150102165623.7c4e3dd1@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).