Subject: Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"

From: Junio C Hamano <[email-masked]>
Date: Tue, 20 Apr 2021 15:25:05 -0700

Ævar Arnfjörð Bjarmason  <[email-masked]> writes:

> These will only match the simplistic forms of `test -X blah` (where
> "-X" is some single letter option), but will miss expressions such as
> `test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
> things like:
>
>     test whatever && ls -a foo
>     test whatever && foo -o outfile

I still do not understand why you have to insist on dashed operator
as the first thing given to "test", like this:

> +	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" ...
> +	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" ...

IOW, what over-matching would we get if we simplified the condition
like so?

    /\btest\s+[^&|]+\s+-a\s/
    /\btest\s+[^&|]+\s+-o\s/

The one in the patch would miss things like

	test "$a" = "$b" -o "$a" -lt "$b"
	test "$n" -a "$n" -lt 4

but the only thing that we care about is that a command that started
with "test " has "-a" or "-o" before we see "&" or "|", no?