aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/test.c69
-rwxr-xr-xtestsuite/test.tests20
2 files changed, 55 insertions, 34 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index 4df505a05..88cc55050 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -826,7 +826,6 @@ int test_main(int argc, char **argv)
826{ 826{
827 int res; 827 int res;
828 const char *arg0; 828 const char *arg0;
829// bool negate = 0;
830 829
831 arg0 = bb_basename(argv[0]); 830 arg0 = bb_basename(argv[0]);
832 if (arg0[0] == '[') { 831 if (arg0[0] == '[') {
@@ -844,6 +843,7 @@ int test_main(int argc, char **argv)
844 } 843 }
845 argv[argc] = NULL; 844 argv[argc] = NULL;
846 } 845 }
846 /* argc is unused after this point */
847 847
848 /* We must do DEINIT_S() prior to returning */ 848 /* We must do DEINIT_S() prior to returning */
849 INIT_S(); 849 INIT_S();
@@ -862,43 +862,45 @@ int test_main(int argc, char **argv)
862 */ 862 */
863 /*ngroups = 0; - done by INIT_S() */ 863 /*ngroups = 0; - done by INIT_S() */
864 864
865 //argc--;
866 argv++; 865 argv++;
866 args = argv;
867 867
868 /* Implement special cases from POSIX.2, section 4.62.4 */ 868 /* Implement special cases from POSIX.2, section 4.62.4.
869 if (!argv[0]) { /* "test" */ 869 * Testcase: "test '(' = '('"
870 res = 1; 870 * The general parser would misinterpret '(' as group start.
871 goto ret; 871 */
872 } 872 if (1) {
873#if 0 873 int negate = 0;
874// Now it's fixed in the parser and should not be needed 874 again:
875 if (LONE_CHAR(argv[0], '!') && argv[1]) { 875 if (!argv[0]) {
876 negate = 1; 876 /* "test" */
877 //argc--; 877 res = 1;
878 argv++; 878 goto ret_special;
879 } 879 }
880 if (!argv[1]) { /* "test [!] arg" */ 880 if (!argv[1]) {
881 res = (*argv[0] == '\0'); 881 /* "test [!] arg" */
882 goto ret; 882 res = (argv[0][0] == '\0');
883 } 883 goto ret_special;
884 if (argv[2] && !argv[3]) { 884 }
885 check_operator(argv[1]); 885 if (argv[2] && !argv[3]) {
886 if (last_operator->op_type == BINOP) { 886 check_operator(argv[1]);
887 /* "test [!] arg1 <binary_op> arg2" */ 887 if (last_operator->op_type == BINOP) {
888 args = argv; 888 /* "test [!] arg1 <binary_op> arg2" */
889 res = (binop() == 0); 889 args = argv;
890 goto ret; 890 res = (binop() == 0);
891 ret_special:
892 /* If there was leading "!" op... */
893 res ^= negate;
894 goto ret;
895 }
896 }
897 if (LONE_CHAR(argv[0], '!')) {
898 argv++;
899 negate ^= 1;
900 goto again;
891 } 901 }
892 } 902 }
893 903
894 /* Some complex expression. Undo '!' removal */
895 if (negate) {
896 negate = 0;
897 //argc++;
898 argv--;
899 }
900#endif
901 args = argv;
902 res = !oexpr(check_operator(*args)); 904 res = !oexpr(check_operator(*args));
903 905
904 if (*args != NULL && *++args != NULL) { 906 if (*args != NULL && *++args != NULL) {
@@ -911,6 +913,5 @@ int test_main(int argc, char **argv)
911 } 913 }
912 ret: 914 ret:
913 DEINIT_S(); 915 DEINIT_S();
914// return negate ? !res : res;
915 return res; 916 return res;
916} 917}
diff --git a/testsuite/test.tests b/testsuite/test.tests
index 2c92e34ba..1c2edaf62 100755
--- a/testsuite/test.tests
+++ b/testsuite/test.tests
@@ -76,4 +76,24 @@ testing "test ! a = b -a ! c = d: should be true (0)" \
76 "0\n" \ 76 "0\n" \
77 "" "" 77 "" ""
78 78
79testing "test '!' = '!': should be true (0)" \
80 "busybox test '!' = '!'; echo \$?" \
81 "0\n" \
82 "" ""
83
84testing "test '(' = '(': should be true (0)" \
85 "busybox test '(' = '('; echo \$?" \
86 "0\n" \
87 "" ""
88
89testing "test '!' '!' = '!': should be false (1)" \
90 "busybox test '!' '!' = '!'; echo \$?" \
91 "1\n" \
92 "" ""
93
94testing "test '!' '(' = '(': should be false (1)" \
95 "busybox test '!' '(' = '('; echo \$?" \
96 "1\n" \
97 "" ""
98
79exit $FAILCOUNT 99exit $FAILCOUNT