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

Re: [PATCH] test-lib: check Bash version for '-x' without using shell arrays

From
Jeff King <peff@peff.net>
Date
Jan 3, 2019, 04:52 UTC
Message-ID
<20190103045200.GB20047@sigill.intra.peff.net>
In-Reply-To
<a82251fa-38e1-233e-50d3-3ed4850b4e11@kdbg.org>
On Wed, Jan 02, 2019 at 01:20:47AM +0100, Johannes Sixt wrote:
Show 31 quoted lines
> > diff --git a/t/test-lib.sh b/t/test-lib.sh
> > index 0f1faa24b2..f47a191e3b 100644
> > --- a/t/test-lib.sh
> > +++ b/t/test-lib.sh
> > @@ -324,9 +324,12 @@ do
> >   		# isn't executed with a suitable Bash version.
> >   		if test -z "$test_untraceable" || {
> >   		     test -n "$BASH_VERSION" && {
> > -		       test ${BASH_VERSINFO[0]} -gt 4 || {
> > -			 test ${BASH_VERSINFO[0]} -eq 4 &&
> > -			 test ${BASH_VERSINFO[1]} -ge 1
> > +		       bash_major=${BASH_VERSION%%.*}
> > +		       bash_minor=${BASH_VERSION#*.}
> > +		       bash_minor=${bash_minor%%.*}
> > +		       test $bash_major -gt 4 || {
> > +			 test $bash_major -eq 4 &&
> > +			 test $bash_minor -ge 1
> >   		       }
> >   		     }
> >   		   }
> > 
> 
> Would it perhaps be simpler to just hide the syntax behind eval? Like
> 
>  		if test -z "$test_untraceable" || {
>  		     test -n "$BASH_VERSION" && eval '
> 		       test ${BASH_VERSINFO[0]} -gt 4 || {
> 			 test ${BASH_VERSINFO[0]} -eq 4 &&
> 			 test ${BASH_VERSINFO[1]} -ge 1
> 		       }
>  		     '
That was my first thought, too. :)

The parsing here is simple enough that I'd be fine either with the original patch, or an eval-based version (and otherwise, the goal and description seem quite good to me).

-Peff
Previous: Junio C HamanoNext: Eric Sunshine
Message 11 of 14 in “test-lib: check Bash version for '-x' without using shell arrays”
  1. test-lib: check Bash version for '-x' without using shell arraysSZEDER Gábor, Jan 1, 2019
  2. Johannes SixtJan 2, 2019
  3. Junio C HamanoJan 2, 2019
  4. test-lib: check Bash version for '-x' without using shell arraysSZEDER Gábor, Jan 3, 2019
  5. Junio C HamanoJan 3, 2019
  6. SZEDER GáborJan 4, 2019
  7. Junio C HamanoJan 4, 2019
  8. SZEDER GáborJan 4, 2019
  9. Carlo ArenasJan 4, 2019
  10. Junio C HamanoJan 4, 2019
  11. Jeff KingJan 3, 2019
  12. Eric SunshineJan 2, 2019
  13. Carlo ArenasJan 2, 2019
  14. SZEDER GáborJan 3, 2019

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.