[git commit] test: fix "test !" and "test abc -a !". closes bug 465

Denys Vlasenko vda.linux at googlemail.com
Thu Jul 16 22:59:26 UTC 2009


commit: http://git.busybox.net/busybox/commit/?id=d23f64eba79a702c36d8d8cec23b49c320897138
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master


function                                             old     new   delta
nexpr                                                826     840     +14

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/test.c     |   13 ++++++++++---
 testsuite/test.tests |   10 ++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/coreutils/test.c b/coreutils/test.c
index 73048d3..c430f22 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -627,7 +627,14 @@ static number_t nexpr(enum token n)
 
 	nest_msg(">nexpr(%s)\n", TOKSTR[n]);
 	if (n == UNOT) {
-		res = !nexpr(check_operator(*++args));
+		n = check_operator(*++args);
+		if (n == EOI) {
+			/* special case: [ ! ], [ a -a ! ] are valid */
+			/* IOW, "! ARG" may miss ARG */
+			unnest_msg("<nexpr:1 (!EOI)\n");
+			return 1;
+		}
+		res = !nexpr(n);
 		unnest_msg("<nexpr:%lld\n", res);
 		return res;
 	}
@@ -798,7 +805,7 @@ int test_main(int argc, char **argv)
 		check_operator(argv[1]);
 		if (last_operator->op_type == BINOP) {
 			/* "test [!] arg1 <binary_op> arg2" */
-			args = &argv[0];
+			args = argv;
 			res = (binop() == 0);
 			goto ret;
 		}
@@ -811,7 +818,7 @@ int test_main(int argc, char **argv)
 		argv--;
 	}
 #endif
-	args = &argv[0];
+	args = argv;
 	res = !oexpr(check_operator(*args));
 
 	if (*args != NULL && *++args != NULL) {
diff --git a/testsuite/test.tests b/testsuite/test.tests
index d4be949..b7c84d9 100755
--- a/testsuite/test.tests
+++ b/testsuite/test.tests
@@ -21,6 +21,11 @@ testing "test '': should be false (1)" \
 	"1\n" \
 	"" ""
 
+testing "test !: should be true (0)" \
+	"busybox test !; echo \$?" \
+	"0\n" \
+	"" ""
+
 testing "test a: should be true (0)" \
 	"busybox test a; echo \$?" \
 	"0\n" \
@@ -51,6 +56,11 @@ testing "test -lt = -gt: should be false (1)" \
 	"1\n" \
 	"" ""
 
+testing "test a -a !: should be true (0)" \
+	"busybox test a -a !; echo \$?" \
+	"0\n" \
+	"" ""
+
 testing "test -f = a -o b: should be true (0)" \
 	"busybox test -f = a -o b; echo \$?" \
 	"0\n" \
-- 
1.6.3.3


More information about the busybox-cvs mailing list