about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-07-10 22:10:25 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-07-10 22:10:25 +0000
commit4db28c55b64ec25cd258f87a0d60b0544fe50059 (patch)
tree7e6c98c9aeae22faf5bc1bb06ff776da5edbf795
parentb4c2ea2cece1adeaa915f6c12f310f2268a58751 (diff)
downloadzsh-4db28c55b64ec25cd258f87a0d60b0544fe50059.tar.gz
zsh-4db28c55b64ec25cd258f87a0d60b0544fe50059.tar.xz
zsh-4db28c55b64ec25cd258f87a0d60b0544fe50059.zip
27126: a few more contexts where executing empty lists gives status zero
-rw-r--r--ChangeLog6
-rw-r--r--Src/exec.c5
-rw-r--r--Src/init.c1
-rw-r--r--Test/A01grammar.ztst22
-rw-r--r--Test/C04funcdef.ztst15
-rw-r--r--Test/D08cmdsubst.ztst4
6 files changed, 51 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 323ade3a9..41c4de6c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-07-10  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* 27126: Src/exec.c, Src/init.c, Test/A01grammar.ztst,
+	Test/C04funcdef.ztst, Test/D08cmdsubst.ztst: a few more
+	contexts where empty lists should give status zero.
+
 	* 27125: Src/prompt.c: handle nested use of colour code buffer
 	allocation.
 
@@ -11950,5 +11954,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4734 $
+* $Revision: 1.4735 $
 *****************************************************
diff --git a/Src/exec.c b/Src/exec.c
index 852d75bb5..0788ecbb9 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1372,7 +1372,8 @@ execpline(Estate state, wordcode slcode, int how, int last1)
 	else
 	    spawnjob();
 	child_unblock();
-	return 0;
+	/* Executing background code resets shell status */
+	return lastval = 0;
     } else {
 	if (newjob != lastwj) {
 	    Job jn = jobtab + newjob;
@@ -3512,6 +3513,7 @@ getoutput(char *cmd, int qt)
 	return retval;
     }
     /* pid == 0 */
+    lastval = 0;		/* status of empty list is zero */
     child_unblock();
     zclose(pipes[0]);
     redup(pipes[1], 1);
@@ -4259,6 +4261,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
     if (trap_state == TRAP_STATE_PRIMED)
 	trap_return--;
     oldlastval = lastval;
+    lastval = 0;		/* status of empty function is zero */
     oldnumpipestats = numpipestats;
     if (noreturnval) {
 	/*
diff --git a/Src/init.c b/Src/init.c
index b0378ccfa..b3224f65a 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1131,6 +1131,7 @@ source(char *s)
     fstack.tp = FS_SOURCE;
     funcstack = &fstack;
 
+    lastval = 0;		/* status of empty file is zero */
     if (prog) {
 	pushheap();
 	errflag = 0;
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index b250d0984..1fe249869 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -27,6 +27,18 @@
   $nonexistent_variable
 0:Executing command that evaluates to empty resets status
 
+  false
+  sleep 1 &
+  print $?
+  # a tidy test is a happy test
+  wait $!
+0:Starting background command resets status
+>0
+
+  false
+  . /dev/null
+0:Sourcing empty file resets status
+
   fn() { local foo; read foo; print $foo; }
   coproc fn
   print -p coproc test output
@@ -531,3 +543,13 @@
   . ./bad_syntax
 126: Attempt to "." file with bad syntax.
 ?./bad_syntax:2: parse error near `\n'
+
+  echo 'false' >dot_false
+  . ./dot_false
+  print $?
+  echo 'true' >dot_true
+  . ./dot_true
+  print $?
+0:Last status of successfully executed "." file is retained
+>1
+>0
diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst
index 73eba8697..338c36fab 100644
--- a/Test/C04funcdef.ztst
+++ b/Test/C04funcdef.ztst
@@ -1,5 +1,20 @@
 %test
 
+  fn1() { return 1; }
+  fn2() {
+      fn1
+      print $?
+      return 2
+  }
+  fn2
+2:Basic status returns from functions
+>1
+
+  fnz() { }
+  false
+  fnz
+0:Empty function body resets status
+
   function f$$ () {
     print regress expansion of function names
   }
diff --git a/Test/D08cmdsubst.ztst b/Test/D08cmdsubst.ztst
index 015796ed6..1b5c7f728 100644
--- a/Test/D08cmdsubst.ztst
+++ b/Test/D08cmdsubst.ztst
@@ -89,3 +89,7 @@
   X=$(exit 2) $(exit 0) || print $?
 0:variable assignments processed after other substitutions
 >2
+
+ false
+ ``
+0:Empty command substitution resets status