git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/4] test-lib-functions: introduce test_line_count_cmd

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 24, 2021, 23:19 UTC
Message-ID
<87h7hmzw37.fsf@evledraar.gmail.com>
In-Reply-To
<CAPig+cRFjBXpm_WwSGBYu75z8TabCDZodYi=wKgTamB1a3aGmg@mail.gmail.com>
On Sun, Jun 13 2021, Eric Sunshine wrote:
Show 25 quoted lines
> On Sun, Jun 13, 2021 at 2:18 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>> On 13/06/2021 14:28, Ævar Arnfjörð Bjarmason wrote:
>> > On Sat, Jun 12 2021, Đoàn Trần Công Danh wrote:
>> >> +       { test "x$1" = "x!" && test $# = 1 ; }
>> >> [...]
>> >> +    if test "x$1" = "x!"
>> >
>> > We don't use this test idiom in other places, it's OK to just use "$1" =
>> > "!". I think we're past whatever portability concern made that popular
>> > in some older shell code in the wild.
>>
>> Slightly off topic but if anyone is interested in the history of this
>> test idiom and why it is no longer needed there is a good article at
>> https://www.vidarholen.net/contents/blog/?p=1035
>
> Thanks for the link to the article; it was an interesting read.
> However, the article does seem to say that such idioms and care may
> still be warranted. In particular, the epilog gives an example which
> is still relevant on macOS today. (Indeed, I just tried it and it does
> error out as the article states.) Even discounting macOS, it also
> talks about such bugs existing as late as 2015, which isn't long ago
> by any stretch. (And, as someone whose primary -- indeed only --
> development machine is ten years old, some of the other bugs it
> mentions -- which existed as recently as ten years ago -- don't seem
> all that long ago either.)

It's only for the case where the first byte is "(" or ")" though, so e.g. the use of this to compare things like command-line options and other things that don't start with those characters is portable, if I'm understanding the article correctly.

> At any rate, for those of us who are old-timers, the `"x$foo"` idiom
> is habit and only costs a couple extra characters, so I for one have
> no problem with its presence in the proposed patch.

Indeed, but it's interesting to dig and see if there's any reason for such workarounds still.

Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 19 of 22 in “t: new helper test_line_count_cmd”
  1. 0/4 t: new helper test_line_count_cmdĐoàn Trần Công Danh, Jun 12, 2021
  2. 3/4 t6400: use test_line_count_cmd to count # of lines in stdoutĐoàn Trần Công Danh, Jun 12, 2021
  3. Bagas SanjayaJun 12, 2021
  4. Đoàn Trần Công DanhJun 13, 2021
  5. Eric SunshineJun 13, 2021
  6. Đoàn Trần Công DanhJun 13, 2021
  7. 2/4 t6402: use find(1) builtin to filter instead of grepĐoàn Trần Công Danh, Jun 12, 2021
  8. 4/4 t6402: use test_line_count_cmd to count # of lines in stdoutĐoàn Trần Công Danh, Jun 12, 2021
  9. Eric SunshineJun 13, 2021
  10. 1/4 test-lib-functions: introduce test_line_count_cmdĐoàn Trần Công Danh, Jun 12, 2021
  11. Eric SunshineJun 13, 2021
  12. Đoàn Trần Công DanhJun 13, 2021
  13. Ævar Arnfjörð BjarmasonJun 13, 2021
  14. Đoàn Trần Công DanhJun 13, 2021
  15. Phillip WoodJun 13, 2021
  16. Felipe ContrerasJun 13, 2021
  17. Eric SunshineJun 13, 2021
  18. Junio C HamanoJun 14, 2021
  19. Ævar Arnfjörð BjarmasonJun 24, 2021
  20. Ævar Arnfjörð BjarmasonJun 13, 2021
  21. Junio C HamanoJun 14, 2021
  22. Đoàn Trần Công DanhJun 15, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.