Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: err_exit/err_return regression
On Thu, 9 Jul 2015 13:33:09 +0200
jsks <js.shirin@xxxxxxxxx> wrote:
> Since patch 34065, with either err_exit or err_return set, zsh does
> not exit/return given a nonzero exist status of a command following
> 'else'.
Hmm, this code is quite hairy and is crying out to be a bit more
structured (it's not lonely in that respect). But the test suite says
the following is good enough for now.
diff --git a/Src/exec.c b/Src/exec.c
index 960601f..4eee82b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1351,7 +1351,13 @@ execlist(Estate state, int dont_change_job, int exiting)
state->pc--;
sublist_done:
- noerrexit = oldnoerrexit;
+ /*
+ * See hairy code near the end of execif() for the
+ * following. "noerrexit == 2" only applies until
+ * we hit execcmd on the way down. We're now
+ * on the way back up, so don't restore it.
+ */
+ noerrexit = (oldnoerrexit == 2) ? 0 : oldnoerrexit;
if (sigtrapped[SIGDEBUG] && !isset(DEBUGBEFORECMD) && !donedebug) {
/*
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst
index 757f75c..4e23388 100644
--- a/Test/C03traps.ztst
+++ b/Test/C03traps.ztst
@@ -399,6 +399,46 @@
)
1:ERREXIT in loop with simple commands
+ fn() {
+ emulate -L zsh
+ setopt errreturn
+ if false; then
+ false
+ print No.
+ else
+ print Oh, yes
+ fi
+ }
+ fn
+0:ERRRETURN not triggered in if condition
+>Oh, yes
+
+ fn() {
+ emulate -L zsh
+ setopt errreturn
+ if true; then
+ false
+ print No.
+ else
+ print No, no.
+ fi
+ }
+ fn
+1:ERRRETURN in "if"
+
+ fn() {
+ emulate -L zsh
+ setopt errreturn
+ if false; then
+ print No.
+ else
+ false
+ print No, no.
+ fi
+ }
+ fn
+1:ERRRETURN in "else" branch (regression test)
+
%clean
rm -f TRAPEXIT
Messages sorted by:
Reverse Date,
Date,
Thread,
Author