Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: minor condition fixes



On Fri, 19 Feb 2010 12:02:37 +0000
Peter Stephenson <pws@xxxxxxx> wrote:
> Then there's a problem I haven't fixed, which is for some reason in the
> test code the status is returning as 1 for an unrecognised condition
> whereas it should return 2 (and does at the command line).  This shows
> up with:
> 
> % eval '[[ -fail badly ]]'
> zsh: unknown condition: -fail
> % print $?
> 1

I think it's as simple as the following; certainly the documentation for
"eval" says quite clearly it returns the same status as executing the code
directly, and so does the principle of least surprise, so I don't see how
the current behaviour can be right.  One would hope that the "if" I've
modified is redundant, in fact: the code already executed should have set
lastval.  However, it should now be harmless, I hope.

This means fixing a glob test.  It really is a fix; again, the status 2 was
already returned if there was no eval, and that's what we should be testing.
(Of course if you tell me the pattern code should really return status 1
that's a different bug, but I think it's correct with the patch.)

I'll modify the other patch accordingly.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.239
diff -p -u -r1.239 builtin.c
--- Src/builtin.c	7 Feb 2010 18:49:36 -0000	1.239
+++ Src/builtin.c	19 Feb 2010 12:06:16 -0000
@@ -4885,7 +4885,7 @@ eval(char **argv)
 	} else {
 	    execode(prog, 1, 0);
 
-	    if (errflag)
+	    if (errflag && !lastval)
 		lastval = errflag;
 	}
     } else {
Index: Test/D02glob.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D02glob.ztst,v
retrieving revision 1.16
diff -p -u -r1.16 D02glob.ztst
--- Test/D02glob.ztst	9 Feb 2010 17:47:04 -0000	1.16
+++ Test/D02glob.ztst	19 Feb 2010 12:06:16 -0000
@@ -425,7 +425,7 @@
 >/ [[:WORD:]] yes
 
  [[ foo = (#c0)foo ]]
-1:Misplaced (#c...) flag
+2:Misplaced (#c...) flag
 ?(eval):1: bad pattern: (#c0)foo
 
  mkdir glob.tmp/dir5

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author