summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcsgr <csgr@FreeBSD.org>1994-09-11 13:57:31 +0000
committercsgr <csgr@FreeBSD.org>1994-09-11 13:57:31 +0000
commitb819d56caf66a2bbb416cd1a946e286daf646469 (patch)
treeca86369a9fb0914094e68aeca4fc515a587bf285
parent15c2fa33ec4181b8477c00ae0052d90c04091039 (diff)
downloadFreeBSD-src-b819d56caf66a2bbb416cd1a946e286daf646469.zip
FreeBSD-src-b819d56caf66a2bbb416cd1a946e286daf646469.tar.gz
- handle signs on integers properly,
- make sure error messages for bad integers are moderately sensible - handle test ! "abc" -o "abc" (This should evaluate to true) (and similar cases) ie: and/or operator test added to POSIX special case processing. - more test cases added. Based on: Work done on 1.x's test(1) by Andrew Moore and Adam David.
-rw-r--r--bin/test/TEST.csh14
-rw-r--r--bin/test/operators.c10
-rw-r--r--bin/test/operators.h1
-rw-r--r--bin/test/test.c5
4 files changed, 28 insertions, 2 deletions
diff --git a/bin/test/TEST.csh b/bin/test/TEST.csh
index e5b9652..e36ec84 100644
--- a/bin/test/TEST.csh
+++ b/bin/test/TEST.csh
@@ -135,3 +135,17 @@ echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
t 700 -le 1000 -a -n "1" -a "20" = "20"
echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
+
+echo 't -5 -eq 5'
+t -5 -eq 5
+
+
+echo 't foo -a ""'
+t foo -a ""
+echo 't "" -a foo'
+t "" -a foo
+echo 't "" -a ""'
+t "" -a ""
+echo 't "" -o ""'
+t "" -o ""
+
diff --git a/bin/test/operators.c b/bin/test/operators.c
index 335223b..21f653f 100644
--- a/bin/test/operators.c
+++ b/bin/test/operators.c
@@ -81,6 +81,16 @@ const char *const binary_op[] = {
NULL
};
+const char *const andor_op[] = {
+ "-o",
+ "|",
+ "-a",
+ "&",
+ NULL
+};
+
+
+
const char op_priority[] = {
3,
12,
diff --git a/bin/test/operators.h b/bin/test/operators.h
index f8746df..74a5a95 100644
--- a/bin/test/operators.h
+++ b/bin/test/operators.h
@@ -73,5 +73,6 @@
extern const char *const unary_op[];
extern const char *const binary_op[];
+extern const char *const andor_op[];
extern const char op_priority[];
extern const char op_argflag[];
diff --git a/bin/test/test.c b/bin/test/test.c
index b9a8ebf..832257e 100644
--- a/bin/test/test.c
+++ b/bin/test/test.c
@@ -161,7 +161,7 @@ main(argc, argv)
}
break;
case 4: /* % test ! arg1 op arg2 */
- if (IS_BANG(argv[1])) {
+ if (IS_BANG(argv[1]) && lookup_op(argv[3], andor_op) < 0 ) {
ret_val = posix_binary_op(&argv[2]);
if (ret_val >= 0)
return (!ret_val);
@@ -528,7 +528,8 @@ get_int(v, lp)
char *ep;
for (; *v && isspace(*v); ++v);
- if (isdigit(*v)) {
+
+ if (isdigit(*v) || ((*v == '-' || *v == '+') && isdigit(*(v+1)))) {
errno = 0;
val = strtol(v, &ep, 10);
if (*ep != '\0')
OpenPOWER on IntegriCloud