bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#69939: test utility bug: "test -a -a -a" and "test -o -o -o" fail


From: Collin Funk
Subject: bug#69939: test utility bug: "test -a -a -a" and "test -o -o -o" fail
Date: Sun, 26 Jul 2026 13:01:02 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

Pádraig Brady <P@draigBrady.com> writes:

> On 25/07/2026 18:54, Collin Funk wrote:
>> The attached patch should fix the issue. We were treating "-o" and "-a"
>> as if they could be unary operators, which they cannot be. They are
>> either a string operand or a binary operator.
>> Will push it in a bit.
>
> Very nice. This now matches behavior of bash and dash at least.
> One nit on the NEWS, I was a bit confused at the double mention
> of binary operators, when perhaps unary was more accurate.
> Therefore it might be best to simplify the first line to:
>
>   'test' no longer treats '-a' and '-o' as operators when given as

Right. I was trying to make the entry friendly to those who may not be
familiar with the terminology, hence the added example. While thinking
of how to word it I must have made that silly mistake.

I pushed this v2 patch with the changes in two_arguments removed. It
caused an incorrect error message, as noticed by
tests/test/test-diag.pl:

    $ ./src/test -o arg
    test: missing argument after ‘arg’

Whereas, in v2 it gives the more correct error, telling us that -o is
not a unary operator:

    $ ./src/test -o arg
    test: ‘-o’: unary operator expected

I'm not too sure why I added it in v1, to be honest. I added a check for
-a in tests/test/test-diag.pl, just because it seems nice to cover that
case as well.

One thing I found confusing is that 'bash' doesn't have error messages
in the following cases:

    $ test -o -o; echo $?
    1
    $ test -a -a; echo $?
    1

Before testing both, I tested 'test -a -a' and thought it might have
been treated as the same as:

    $ test -a -a ''

But we can see that isn't the case from this:

    $ test -o -o; echo $?
    1
    $ test -o -o ''; echo $?
    0

I probably put too much thought into these seldom used operators. :)

Collin

Attachment: v2-0001-test-handle-adjacent-binary-operators.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]