Make test(1) complain when we pass unexpected extra args instead of silently ignoring them or returning TRUE. This is a bit more consistent with PoSix systems and avoids confusion (fgb thought that test -dw /tmp would check if /tmp was a writable dir). Also complain when the argument to -t is not a valid filedes. Fix small typo in the man page and document that there is on way to test if a dir is writeable. uriel Notes: Sat Aug 12 01:57:48 EDT 2006 rsc I don't think it's a bug that -w tells you that directories cannot be opened OWRITE. Reference: /n/sources/patch/applied/test-invalid-args-and-man-page Date: Mon Jul 24 22:20:54 CES 2006 Signed-off-by: uriel@cat-v.org Reviewed-by: rsc --- /sys/src/cmd/test.c Mon Jul 24 22:06:28 2006 +++ /sys/src/cmd/test.c Mon Jul 24 22:06:24 2006 @@ -30,10 +30,13 @@ int hasmode(char *, ulong); int tio(char *, int); int e(void), e1(void), e2(void), e3(void); +char *nxtarg(int); void main(int argc, char *argv[]) { + int r; + char *c; ac = argc; av = argv; ap = 1; if(EQ(argv[0],"[")) { @@ -42,7 +45,10 @@ } argv[ac] = 0; if (ac<=1) exits("usage"); - exits(e()?0:"false"); + r = e(); + if(c = nxtarg(1)) + synbad("unexpected operator/operand: ", c); + exits(r?0:"false"); } char * @@ -153,10 +159,12 @@ return(fsizep(nxtarg(0))); if(EQ(a, "-t")) - if(ap>=ac || !nxtintarg(&int1)) + if(ap>=ac) return(isatty(1)); - else + else if(nxtintarg(&int1)) return(isatty(int1)); + else + synbad("not a valid file descriptor number ", ""); if(EQ(a, "-n")) return(!EQ(nxtarg(0), "")); @@ -182,7 +190,7 @@ return(isnewerthan(nxtarg(0), a)); if(!isint(a, &int1)) - return(!EQ(a,"")); + synbad("unexpected operator/operand: ", p2); if(nxtintarg(&int2)){ if(EQ(p2, "-eq")) --- /sys/man/1/test Mon Jul 24 22:06:54 2006 +++ /sys/man/1/test Mon Jul 24 22:06:50 2006 @@ -50,7 +50,7 @@ .BI -L " file" True if the file exists and is exclusive-use. .TP -.BI -T "file" +.BI -T " file" True if the file exists and is temporary. .TP .IB s1 " = " s2 @@ -209,3 +209,7 @@ .B /sys/src/cmd/test.c .SH "SEE ALSO" .IR rc (1) +.SH BUGS +There is no way to test if a directory is writable, +.B -w +always returns false for directories.