From: Peter Stephenson <pws@csr.com>
To: zsh-workers@zsh.org (Zsh hackers list)
Subject: PATCH: minor condition fixes
Date: Fri, 19 Feb 2010 12:02:37 +0000 [thread overview]
Message-ID: <22045.1266580957@csr.com> (raw)
I noticed the condition code is output too many "-"s when it doesn't
recognised a test. Bizarrely, I copied this error into the test code
without noticing: it's complaining about a non-existent "-foo" when
the failure was on "-fail foo".
Looking further, it's doing a bad job of guessing what the condition it
doesn't know is (even ignoring the misplaced '-'):
% [[ -fail badly ]]
zsh: unknown condition: -badly
% [[ really -fail badly ]]
zsh: unknown condition: -really
There's no point trying too hard if it couldn't parse it properly
anyway, but it would be sensible to guess that something with a "-" is
the unknown condition, and it might as well be the first one we come
across.
While looking I noticed that that first getconddef() you can see is
checking name + 1 without ever looking at name[0]; presumably it should be
ensuring name[0] is a '-'?
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
Index: Src/cond.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/cond.c,v
retrieving revision 1.15
diff -p -u -r1.15 cond.c
--- Src/cond.c 11 May 2008 19:55:21 -0000 1.15
+++ Src/cond.c 19 Feb 2010 11:56:20 -0000
@@ -104,7 +104,7 @@ evalcond(Estate state, char *fromtest)
case COND_MODI:
{
Conddef cd;
- char *name = overridename;
+ char *name = overridename, *errname;
char **strs;
int l = WC_COND_SKIP(code);
@@ -122,10 +122,17 @@ evalcond(Estate state, char *fromtest)
strs = arrdup(sbuf);
l = 2;
}
- if ((cd = getconddef((ctype == COND_MODI), name + 1, 1))) {
+ if (name && name[0] == '-')
+ errname = name;
+ else if (strs[0] && *strs[0] == '-')
+ errname = strs[0];
+ else
+ errname = "<null>";
+ if (name && name[0] == '-' &&
+ (cd = getconddef((ctype == COND_MODI), name + 1, 1))) {
if (ctype == COND_MOD &&
(l < cd->min || (cd->max >= 0 && l > cd->max))) {
- zwarnnam(fromtest, "unknown condition: -%s", name);
+ zwarnnam(fromtest, "unknown condition: %s", name);
return 2;
}
if (tracingcond)
@@ -151,8 +158,8 @@ evalcond(Estate state, char *fromtest)
if (name && name[0] == '-' &&
(cd = getconddef(0, name + 1, 1))) {
if (l < cd->min || (cd->max >= 0 && l > cd->max)) {
- zwarnnam(fromtest, "unknown condition: -%s",
- name);
+ zwarnnam(fromtest, "unknown condition: %s",
+ errname);
return 2;
}
if (tracingcond)
@@ -160,8 +167,8 @@ evalcond(Estate state, char *fromtest)
return !cd->handler(strs, cd->condid);
} else {
zwarnnam(fromtest,
- "unknown condition: -%s",
- name ? name : "<null>");
+ "unknown condition: %s",
+ errname);
}
}
/* module not found, error */
Index: Test/C02cond.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C02cond.ztst,v
retrieving revision 1.25
diff -p -u -r1.25 C02cond.ztst
--- Test/C02cond.ztst 20 Jan 2010 11:17:13 -0000 1.25
+++ Test/C02cond.ztst 19 Feb 2010 11:56:20 -0000
@@ -285,6 +285,14 @@ F:Failures in these cases do not indicat
0:MATCH, MBEGIN, MEND, match, mbegin, mend
>OK
+ [[ -fail badly ]]
+1:Error message for unknown prefix condition
+?(eval):1: unknown condition: -fail
+
+ [[ really -fail badly ]]
+1:Error message for unknown infix condition
+?(eval):1: unknown condition: -fail
+
%clean
# This works around a bug in rm -f in some versions of Cygwin
chmod 644 unmodish
Index: Test/V01zmodload.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/V01zmodload.ztst,v
retrieving revision 1.13
diff -p -u -r1.13 V01zmodload.ztst
--- Test/V01zmodload.ztst 13 Aug 2008 21:07:03 -0000 1.13
+++ Test/V01zmodload.ztst 19 Feb 2010 11:56:20 -0000
@@ -151,7 +151,7 @@
print "Shouldn't get here.")
2:Failed condition autoload
?(eval):3: module `zsh/parameter' has no such feature: `c:fail': autoload cancelled
-?(eval):3: unknown condition: -foo
+?(eval):3: unknown condition: -fail
(zmodload -u zsh/parameter
zmodload -aF zsh/parameter f:fail
--
Peter Stephenson <pws@csr.com> 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
next reply other threads:[~2010-02-19 12:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-19 12:02 Peter Stephenson [this message]
2010-02-19 12:14 ` Peter Stephenson
2010-02-19 12:35 ` 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=22045.1266580957@csr.com \
--to=pws@csr.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).