* [BUG] test ! "-o" ([ ! -o ]) exit status should be 1
@ 2021-08-09 10:55 koichi nakashima
2021-08-09 14:16 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: koichi nakashima @ 2021-08-09 10:55 UTC (permalink / raw)
To: zsh-workers
In the following code, I expected the exit status to be 1.
However, in zsh 5.0.3 and later, it was actually 0.
$ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"'
4.3.17: 1
$ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"'
5.0.0: 1
$ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"'
5.0.2: 1
$ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"' # <===
5.0.3: 0
$ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"'
5.8: 0
I checked the release notes, and it does not appear to be
an intentional change.
In other latest shells, it is as expected.
$ dash -c '[ ! -o ]; echo $?'
1
$ bash -c '[ ! -o ]; echo $?'
1
$ ksh -c '[ ! -o ]; echo $?'
1
$ yash -c '[ ! -o ]; echo $?'
1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] test ! "-o" ([ ! -o ]) exit status should be 1
2021-08-09 10:55 [BUG] test ! "-o" ([ ! -o ]) exit status should be 1 koichi nakashima
@ 2021-08-09 14:16 ` Peter Stephenson
2021-08-10 8:21 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2021-08-09 14:16 UTC (permalink / raw)
To: koichi nakashima, zsh-workers
> On 09 August 2021 at 11:55 koichi nakashima <koichi@nksm.name> wrote:
>
>
> In the following code, I expected the exit status to be 1.
> However, in zsh 5.0.3 and later, it was actually 0.
>
> $ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"'
> 4.3.17: 1
It's a little bizarre that we've actually got a test for this, and it's
deliberately set up this way. But I think the fix for this case is simple
— more complicated expressions with "test" or "[", as opposed to "[[", can
go horribly wrong, but two arguments should be OK — so I've just flipped
the test. It can't possibly be right that -a and -o are treated differently
in this context, can it?
pws
diff --git a/Src/parse.c b/Src/parse.c
index b09c7989a..be26112a5 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2509,7 +2509,7 @@ par_cond_2(void)
* In "test" compatibility mode, "! -a ..." and "! -o ..."
* are treated as "[string] [and] ..." and "[string] [or] ...".
*/
- if (!(n_testargs > 1 && (check_cond(*testargs, "a") ||
+ if (!(n_testargs > 2 && (check_cond(*testargs, "a") ||
check_cond(*testargs, "o"))))
{
condlex();
diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst
index 5b105b2a0..4366b4142 100644
--- a/Test/C02cond.ztst
+++ b/Test/C02cond.ztst
@@ -380,7 +380,7 @@ F:scenario if you encounter it.
>0
>0
>1
->0
+>1
>0
>0
>1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] test ! "-o" ([ ! -o ]) exit status should be 1
2021-08-09 14:16 ` Peter Stephenson
@ 2021-08-10 8:21 ` Peter Stephenson
0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2021-08-10 8:21 UTC (permalink / raw)
To: koichi nakashima, zsh-workers
> On 09 August 2021 at 15:16 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> > On 09 August 2021 at 11:55 koichi nakashima <koichi@nksm.name> wrote:
> >
> >
> > In the following code, I expected the exit status to be 1.
> > However, in zsh 5.0.3 and later, it was actually 0.
> >
> > $ zsh -c '[ ! -o ]; echo "$ZSH_VERSION: $?"'
> > 4.3.17: 1
>
> It's a little bizarre that we've actually got a test for this, and it's
> deliberately set up this way. But I think the fix for this case is simple
> — more complicated expressions with "test" or "[", as opposed to "[[", can
> go horribly wrong, but two arguments should be OK — so I've just flipped
> the test. It can't possibly be right that -a and -o are treated differently
> in this context, can it?
I've assumed this is uncontroversial, which I think it is, and submitted this.
I'm guessing the test just got set up to reflect the status quo rather than
some deeper (but bizarre) thinking.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-08-10 8:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 10:55 [BUG] test ! "-o" ([ ! -o ]) exit status should be 1 koichi nakashima
2021-08-09 14:16 ` Peter Stephenson
2021-08-10 8:21 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).