zsh-workers
 help / color / mirror / code / Atom feed
* Tests RE behavior of ERR_EXIT
@ 2022-11-09  5:29 Bart Schaefer
  2022-11-10  5:22 ` [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT) Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2022-11-09  5:29 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 318 bytes --]

Changed a set of tests from success to xfail.  Anyone have ideas of
why these aren't working?

If I change the ( subshell ) constructs to use
$ZTST_testdir/../Src/zsh -fc then they all correctly exit on nonzero
status as expected.

Aside, should 'setopt err_return' in the nested function test be using
localoptions ?

[-- Attachment #2: errexit_xfail.txt --]
[-- Type: text/plain, Size: 1901 bytes --]

diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index f120809a7..e3d9ea871 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -720,14 +720,15 @@ F:Must be tested with a top-level script rather than source or function
 0:ERR_RETURN in "else" branch in nested function
 >Good
 
+  unsetopt err_return	# "leaked" from previous test
   (setopt err_exit
   for x in y; do
     false && true
   done
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of for
->OK
+1f:ERR_EXIT triggered by status 1 at end of for
+F:This fails to exit for unknown reasons and prints OK
 
   (setopt err_exit
   integer x=0
@@ -736,8 +737,8 @@ F:Must be tested with a top-level script rather than source or function
   done
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of while
->OK
+1f:ERR_EXIT triggered by status 1 at end of while
+F:This fails to exit for unknown reasons and prints OK
 
   (setopt err_exit
   repeat 1; do
@@ -745,8 +746,8 @@ F:Must be tested with a top-level script rather than source or function
   done
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of repeat
->OK
+1f:ERR_EXIT triggered by status 1 at end of repeat
+F:This fails to exit for unknown reasons and prints OK
 
   (setopt err_exit
   if true; then
@@ -754,8 +755,8 @@ F:Must be tested with a top-level script rather than source or function
   fi
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of if
->OK
+1f:ERR_EXIT triggered by status 1 at end of if
+F:This fails to exit for unknown reasons and prints OK
 
   (setopt err_exit
   {
@@ -763,8 +764,8 @@ F:Must be tested with a top-level script rather than source or function
   }
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of { }
->OK
+1f:ERR_EXIT triggered by status 1 at end of { }
+F:This fails to exit for unknown reasons and prints OK
 
   unsetopt err_exit err_return
   (setopt err_exit

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT)
  2022-11-09  5:29 Tests RE behavior of ERR_EXIT Bart Schaefer
@ 2022-11-10  5:22 ` Bart Schaefer
  2022-11-10  5:47   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2022-11-10  5:22 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 375 bytes --]

On Tue, Nov 8, 2022 at 9:29 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Changed a set of tests from success to xfail.  Anyone have ideas of
> why these aren't working?

Found it.  Grateful for the thorough regression tests in E01options, too.

> Aside, should 'setopt err_return' in the nested function test be using
> localoptions ?

I'm going to vote "yes" ...

[-- Attachment #2: errexit_testspass.txt --]
[-- Type: text/plain, Size: 2687 bytes --]

diff --git a/NEWS b/NEWS
index cdafd1ff5..9c28169bb 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,15 @@ CHANGES FROM PREVIOUS VERSIONS OF ZSH
 
 Note also the list of incompatibilities in the README file.
 
+Changes since 5.9
+-----------------
+
+Handling of ERR_EXIT is corrected when the final status of a structured
+command (for, select, while, repeat, if, case, or a list in braces) is
+nonzero.  To be compatible with other shells, "zsh -e" now exits in
+those circumstances, whereas previous versions did not.  This does not
+affect the handling of nonzero status within conditional statements.
+
 Changes since 5.8.1
 -------------------
 
diff --git a/Src/exec.c b/Src/exec.c
index d4e681887..eef40232e 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1442,6 +1442,8 @@ execlist(Estate state, int dont_change_job, int exiting)
 		    execsimple(state);
 		else
 		    execpline(state, code, ltype, (ltype & Z_END) && exiting);
+		if (unset(ERRRETURN))
+		    this_noerrexit = noerrexit;
 		state->pc = next;
 		goto sublist_done;
 		break;
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index f120809a7..5cc45e2de 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -713,7 +713,7 @@ F:Must be tested with a top-level script rather than source or function
     fi
   }
   fn() {
-    setopt err_return
+    setopt localoptions err_return
     fn2 || true
   }
   fn
@@ -726,8 +726,7 @@ F:Must be tested with a top-level script rather than source or function
   done
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of for
->OK
+1:ERR_EXIT triggered by status 1 at end of for
 
   (setopt err_exit
   integer x=0
@@ -736,8 +735,7 @@ F:Must be tested with a top-level script rather than source or function
   done
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of while
->OK
+1:ERR_EXIT triggered by status 1 at end of while
 
   (setopt err_exit
   repeat 1; do
@@ -745,8 +743,7 @@ F:Must be tested with a top-level script rather than source or function
   done
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of repeat
->OK
+1:ERR_EXIT triggered by status 1 at end of repeat
 
   (setopt err_exit
   if true; then
@@ -754,8 +751,7 @@ F:Must be tested with a top-level script rather than source or function
   fi
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of if
->OK
+1:ERR_EXIT triggered by status 1 at end of if
 
   (setopt err_exit
   {
@@ -763,8 +759,7 @@ F:Must be tested with a top-level script rather than source or function
   }
   print OK
   )
-0:ERR_EXIT not triggered by status 1 at end of { }
->OK
+1:ERR_EXIT triggered by status 1 at end of { }
 
   unsetopt err_exit err_return
   (setopt err_exit

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT)
  2022-11-10  5:22 ` [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT) Bart Schaefer
@ 2022-11-10  5:47   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2022-11-10  5:47 UTC (permalink / raw)
  To: Zsh hackers list

On Wed, Nov 9, 2022 at 9:22 PM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> Grateful for the thorough regression tests in E01options, too.

Of course I still missed one detail ... ERR_RETURN only applies inside
functions.

diff --git a/Src/exec.c b/Src/exec.c
index eef40232e..ce0c1f1ad 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1442,7 +1442,7 @@ execlist(Estate state, int dont_change_job, int exiting)
             execsimple(state);
         else
             execpline(state, code, ltype, (ltype & Z_END) && exiting);
-        if (unset(ERRRETURN))
+        if (!locallevel || unset(ERRRETURN))
             this_noerrexit = noerrexit;
         state->pc = next;
         goto sublist_done;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-10  5:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09  5:29 Tests RE behavior of ERR_EXIT Bart Schaefer
2022-11-10  5:22 ` [PATCH] More ERR_EXIT (was Re: Tests RE behavior of ERR_EXIT) Bart Schaefer
2022-11-10  5:47   ` Bart Schaefer

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).