summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/test.c13
-rwxr-xr-xtestsuite/test.tests10
2 files changed, 20 insertions, 3 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index 73048d311..c430f2210 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -627,7 +627,14 @@ static number_t nexpr(enum token n)
627 627
628 nest_msg(">nexpr(%s)\n", TOKSTR[n]); 628 nest_msg(">nexpr(%s)\n", TOKSTR[n]);
629 if (n == UNOT) { 629 if (n == UNOT) {
630 res = !nexpr(check_operator(*++args)); 630 n = check_operator(*++args);
631 if (n == EOI) {
632 /* special case: [ ! ], [ a -a ! ] are valid */
633 /* IOW, "! ARG" may miss ARG */
634 unnest_msg("<nexpr:1 (!EOI)\n");
635 return 1;
636 }
637 res = !nexpr(n);
631 unnest_msg("<nexpr:%lld\n", res); 638 unnest_msg("<nexpr:%lld\n", res);
632 return res; 639 return res;
633 } 640 }
@@ -798,7 +805,7 @@ int test_main(int argc, char **argv)
798 check_operator(argv[1]); 805 check_operator(argv[1]);
799 if (last_operator->op_type == BINOP) { 806 if (last_operator->op_type == BINOP) {
800 /* "test [!] arg1 <binary_op> arg2" */ 807 /* "test [!] arg1 <binary_op> arg2" */
801 args = &argv[0]; 808 args = argv;
802 res = (binop() == 0); 809 res = (binop() == 0);
803 goto ret; 810 goto ret;
804 } 811 }
@@ -811,7 +818,7 @@ int test_main(int argc, char **argv)
811 argv--; 818 argv--;
812 } 819 }
813#endif 820#endif
814 args = &argv[0]; 821 args = argv;
815 res = !oexpr(check_operator(*args)); 822 res = !oexpr(check_operator(*args));
816 823
817 if (*args != NULL && *++args != NULL) { 824 if (*args != NULL && *++args != NULL) {
diff --git a/testsuite/test.tests b/testsuite/test.tests
index d4be949ec..b7c84d9b2 100755
--- a/testsuite/test.tests
+++ b/testsuite/test.tests
@@ -21,6 +21,11 @@ testing "test '': should be false (1)" \
21 "1\n" \ 21 "1\n" \
22 "" "" 22 "" ""
23 23
24testing "test !: should be true (0)" \
25 "busybox test !; echo \$?" \
26 "0\n" \
27 "" ""
28
24testing "test a: should be true (0)" \ 29testing "test a: should be true (0)" \
25 "busybox test a; echo \$?" \ 30 "busybox test a; echo \$?" \
26 "0\n" \ 31 "0\n" \
@@ -51,6 +56,11 @@ testing "test -lt = -gt: should be false (1)" \
51 "1\n" \ 56 "1\n" \
52 "" "" 57 "" ""
53 58
59testing "test a -a !: should be true (0)" \
60 "busybox test a -a !; echo \$?" \
61 "0\n" \
62 "" ""
63
54testing "test -f = a -o b: should be true (0)" \ 64testing "test -f = a -o b: should be true (0)" \
55 "busybox test -f = a -o b; echo \$?" \ 65 "busybox test -f = a -o b; echo \$?" \
56 "0\n" \ 66 "0\n" \