diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/builtin.c | 13 | ||||
-rw-r--r-- | Test/C02cond.ztst | 6 |
3 files changed, 20 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog index 72fc65195..0e8809ad3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-09-06 Peter Stephenson <p.w.stephenson@ntlworld.com> + + * 31706: Src/builtin.c, Test/C02cond.ztst: standardise + handling of "test ! <x> <y> <z>". + 2013-09-04 Peter Stephenson <p.w.stephenson@ntlworld.com> * 31696: Src/parse.c, Test/C02cond.ztst: in "test", no one diff --git a/Src/builtin.c b/Src/builtin.c index f8be4acc9..c3f0169c7 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -5995,7 +5995,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) char **s; Eprog prog; struct estate state; - int nargs; + int nargs, sense = 0, ret; /* if "test" was invoked as "[", it needs a matching "]" * * which is subsequently ignored */ @@ -6014,7 +6014,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) /* * Implement some XSI extensions to POSIX here. * See - * http://www.opengroup.org/onlinepubs/009695399/utilities/test.html. + * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html */ nargs = arrlen(argv); if (nargs == 3 || nargs == 4) @@ -6023,6 +6023,10 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) argv[nargs-1] = NULL; argv++; } + if (nargs == 4 && !strcmp("!", argv[0])) { + sense = 1; + argv++; + } } lexsave(); @@ -6057,8 +6061,11 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func) state.pc = prog->prog; state.strs = prog->strs; + ret = evalcond(&state, name); + if (ret < 2 && sense) + ret = ! ret; - return evalcond(&state, name); + return ret; } /* display a time, provided in units of 1/60s, as minutes and seconds */ diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 856251923..94fca8b68 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -331,7 +331,9 @@ F:Failures in these cases do not indicate a problem in the shell. '! -o' '! -a ! -a !' '! = !' - '! !') + '! !' + '= -a o' + '! = -a o') for w in $weirdies; do eval test $w print $? @@ -344,6 +346,8 @@ F:Failures in these cases do not indicate a problem in the shell. >0 >0 >1 +>0 +>1 %clean # This works around a bug in rm -f in some versions of Cygwin |