[Toybox] test.c patches on GitHub

Kevin Spiteri kspiteri at ieee.org
Wed Sep 5 18:45:20 PDT 2018


I'm not sure coreutils is consistent.

[ ! "" -o s ] is false, so -o has higher priority than ! here, but
[ ! 1 -eq 2 -o s ] is true, so ! has higher priority than -o here.
Changing either 1 or 2 with walrus gives the integer expression expected
error.

[ ! '"" -a "" ] is true, so -a has higher priority than ! here, but
[ s -a ! "" -a "" ] is false, so ! has higher priority than the right -a
here.

I think the precedence should be as simple as:
1. anything enclosed in ( )
2. any expression not containing !, -a, -o
3. !
4. -a
5. -o

Of course, matching coreutils is more important than matching what I think.
But I'm not sure how to get a consistent set of rules short of reading the
code and mirroring it.

Kevin


On Wed, Sep 5, 2018 at 3:24 PM Rob Landley <rob at landley.net> wrote:

> On 09/05/2018 01:21 PM, Rob Landley wrote:
> > Ah, I remember what the big timesink for this one is: [ TEST -a TEST -o
> TEST -a
> > TEST ] needs a loop, which is reminiscent of the logic in "find" which
> meant I
> > wanted to look at the find code to see if anything there was worth
> factoring out
> > into lib so it could be shared.
>
> I should copy a bunch of the tests from "find" with regard to ! inside
> parentheses meaning something different from ! outside parentheses and
> such, I
> think I wrote about this in old mailing post lists, I should compare the
> git
> commit dates with the web archive and see what i can dig up?
>
> I left myself comments at the end of tests/test.test (what a lovely name);
>
> # test ! = -o a
> # test ! \( = -o a \)
> # test \( ! = \) -o a
>
> And I dunno what the priority of -a and -o are here:
>
> [ 1 -a "" -a "" -o 1 -a 1 ]
>
> (Let's see, find is doing something like -a chains fast forward on
> failure, and
> -o chains fast forward on success? There's conditional evaluation in find
> that
> doesn't seem to be the case here:
>
> $ test 1 -o 3 -gt walrus
> bash: test: walrus: integer expression expected
>
> Confirm ] only matters as last argument when name is [
>
> [ ] = ] ]
>
> And of course gratuitous parentheses:
>
> [ \( 1 -lt 2 \) ]
>
> (So often coming up with the tests to run is the hard part and
> development's at
> most half the work...)
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20180905/e731d679/attachment-0001.htm>


More information about the Toybox mailing list