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

Re: [BUG] 'test' returns 1 (not >1) on error [was: test is not posix]



On Thu, 21 Jan 2016 14:06:38 +0100
Martijn Dekker <martijn@xxxxxxxx> wrote:
> Something I also noticed back in May, and which I'm now reminded of, is
> that test/[ returns status 1, and not 2 or higher, if an error occurs.

It's correct inside the condition code, so this is yet another thing the
test builtin needs fixing up for.

diff --git a/Src/builtin.c b/Src/builtin.c
index dd20f9e..98ecb09 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -6531,7 +6531,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func)
 	for (s = argv; *s; s++);
 	if (s == argv || strcmp(s[-1], "]")) {
 	    zwarnnam(name, "']' expected");
-	    return 1;
+	    return 2;
 	}
 	s[-1] = NULL;
     }
@@ -6574,19 +6574,19 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func)
     if (errflag) {
 	errflag &= ~ERRFLAG_ERROR;
 	zcontext_restore();
-	return 1;
+	return 2;
     }
 
     if (!prog || tok == LEXERR) {
 	zwarnnam(name, tokstr ? "parse error" : "argument expected");
 	zcontext_restore();
-	return 1;
+	return 2;
     }
     zcontext_restore();
 
     if (*curtestarg) {
 	zwarnnam(name, "too many arguments");
-	return 1;
+	return 2;
     }
 
     /* syntax is OK, so evaluate */
diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst
index 0b4608a..88cad0d 100644
--- a/Test/C02cond.ztst
+++ b/Test/C02cond.ztst
@@ -223,27 +223,27 @@ F:Failures in these cases do not indicate a problem in the shell.
 0:substitution in `[' builtin
 
   [ -n foo scrimble ]
-1:argument checking for [ builtin
+2:argument checking for [ builtin
 ?(eval):[:1: too many arguments
 
   test -n foo scramble
-1:argument checking for test builtin
+2:argument checking for test builtin
 ?(eval):test:1: too many arguments
 
   [ -n foo scrimble scromble ]
-1:argument checking for [ builtin
+2:argument checking for [ builtin
 ?(eval):[:1: too many arguments
 
   test -n foo scramble scrumble
-1:argument checking for test builtin
+2:argument checking for test builtin
 ?(eval):test:1: too many arguments
 
   [ -n foo -a -n bar scrimble ]
-1:argument checking for [ builtin
+2:argument checking for [ builtin
 ?(eval):[:1: too many arguments
 
   test -n foo -a -z "" scramble
-1:argument checking for test builtin
+2:argument checking for test builtin
 ?(eval):test:1: too many arguments
 
   fn() {



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