git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] test: fix for COLUMNS and bash 5
@ 2021-08-05 19:48 Felipe Contreras
  2021-08-05 23:35 ` Ævar Arnfjörð Bjarmason
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Felipe Contreras @ 2021-08-05 19:48 UTC (permalink / raw)
  To: git; +Cc: ZheNing Hu, Felipe Contreras, Fabian Stelzer

Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
repeatability, 2021-06-29) multiple tests have been failing when using
bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
reset using TIOCGWINSZ even for non-interactive shells.

It's debatable whether or not bash should even be doing that, but for
now we can avoid this undesirable behavior by disabling this option.

Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 t/test-lib.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index db61081d6b..a2b7dfecee 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -419,6 +419,12 @@ COLUMNS=80
 export LANG LC_ALL PAGER TZ COLUMNS
 EDITOR=:
 
+# Since bash 5.0, checkwinsize is enabled by default which does update the
+# COLUMNS variable every time a command completes, even for non-interactive
+# shells.
+# Disable that since we are aiming for reproducibility.
+test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
+
 # A call to "unset" with no arguments causes at least Solaris 10
 # /usr/xpg4/bin/sh and /bin/ksh to bail out.  So keep the unsets
 # deriving from the command substitution clustered with the other
-- 
2.32.0.40.gb9b36f9b52


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] test: fix for COLUMNS and bash 5
  2021-08-05 19:48 [PATCH] test: fix for COLUMNS and bash 5 Felipe Contreras
@ 2021-08-05 23:35 ` Ævar Arnfjörð Bjarmason
  2021-08-06 16:15   ` Felipe Contreras
  2021-08-06 14:49 ` SZEDER Gábor
  2021-08-06 16:44 ` [PATCH v2] " Felipe Contreras
  2 siblings, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-08-05 23:35 UTC (permalink / raw)
  To: Felipe Contreras
  Cc: git, ZheNing Hu, Fabian Stelzer, SZEDER Gábor,
	Junio C Hamano


On Thu, Aug 05 2021, Felipe Contreras wrote:

> Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
> repeatability, 2021-06-29) multiple tests have been failing when using
> bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
> reset using TIOCGWINSZ even for non-interactive shells.
>
> It's debatable whether or not bash should even be doing that, but for
> now we can avoid this undesirable behavior by disabling this option.
>
> Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>

I've got an alternative way of solving the same immeditate issue in[1],
there's discussion on that approach in the latest What's Cooking[2]. I
belive this approach would make at least SZEDER happier than with my
series :)

As noted in that discussion I'd prefer going for mine, but would also be
fine with this if it's what Junio decides to pick up. We should have one
or the other before 2.33 is out.

My preference for mine is in no small part that I'd like to not be
responsible for into-the-past test suite breakage the next time a
popular shell decides to be clever about COLUMNS.

But this way we'll solve the immediate problem with bash, and I can say
I told you so if that submarine breakage occurs with this approach :)

1. https://lore.kernel.org/git/cover-v3-0.3-00000000000-20210804T230335Z-avarab@gmail.com/
2. https://lore.kernel.org/git/cover-v3-0.3-00000000000-20210804T230335Z-avarab@gmail.com/

> ---
>  t/test-lib.sh | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index db61081d6b..a2b7dfecee 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -419,6 +419,12 @@ COLUMNS=80
>  export LANG LC_ALL PAGER TZ COLUMNS
>  EDITOR=:
>  
> +# Since bash 5.0, checkwinsize is enabled by default which does update the
> +# COLUMNS variable every time a command completes, even for non-interactive
> +# shells.

I don't think this needs updating, but FWIW I think that around bash 4.X
(I think 4.1, but that's from memory) is where it started doing this for
non-interactive shells, so we could have had breakage going back that
far.

But we're seeing this in practice now because with 5.0 this was turned
on by default.

I.e. I think if you turn on checkwinsize it'll also break with the tests
on bash 4.1 (or whatever it was), but not on 3.x.

None of that's something I've tested, just from memory of skimming the
bash commit logs for changes related to checkwinsize a some days ago
when I came up with my fix for this.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test: fix for COLUMNS and bash 5
  2021-08-05 19:48 [PATCH] test: fix for COLUMNS and bash 5 Felipe Contreras
  2021-08-05 23:35 ` Ævar Arnfjörð Bjarmason
@ 2021-08-06 14:49 ` SZEDER Gábor
  2021-08-06 16:59   ` Junio C Hamano
  2021-08-06 16:44 ` [PATCH v2] " Felipe Contreras
  2 siblings, 1 reply; 9+ messages in thread
From: SZEDER Gábor @ 2021-08-06 14:49 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git, ZheNing Hu, Fabian Stelzer

On Thu, Aug 05, 2021 at 02:48:25PM -0500, Felipe Contreras wrote:
> Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
> repeatability, 2021-06-29) multiple tests have been failing when using
> bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
> reset using TIOCGWINSZ even for non-interactive shells.
> 
> It's debatable whether or not bash should even be doing that, but for
> now we can avoid this undesirable behavior by disabling this option.
> 
> Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  t/test-lib.sh | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index db61081d6b..a2b7dfecee 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -419,6 +419,12 @@ COLUMNS=80

COLUMNS is set just before the start of the hunk context ...

>  export LANG LC_ALL PAGER TZ COLUMNS
>  EDITOR=:

... so these two "commands" above are executed while COLUMNS is
already set but checkwinsize is not yet disabled.  The reason I put
quotes around that commands is that while exporting and setting
variables are indeed commands as defined in the POSIX Shell Command
Language specs, Bash with checkwinsize enabled only "checks the window
size after each extern (non-builtin) command" (quoting 'man bash').

So even though it is safe to execute these variable setting and
exporting commands after setting COLUMNS but disabling checkwinsize, I
think it would be prudent to disable checkwinsize before initializing
COLUMNS.  (And perhaps adding "non-builtin" to the comment below.)

> +# Since bash 5.0, checkwinsize is enabled by default which does update the
> +# COLUMNS variable every time a command completes, even for non-interactive
> +# shells.
> +# Disable that since we are aiming for reproducibility.
> +test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
> +
>  # A call to "unset" with no arguments causes at least Solaris 10
>  # /usr/xpg4/bin/sh and /bin/ksh to bail out.  So keep the unsets
>  # deriving from the command substitution clustered with the other
> -- 
> 2.32.0.40.gb9b36f9b52
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test: fix for COLUMNS and bash 5
  2021-08-05 23:35 ` Ævar Arnfjörð Bjarmason
@ 2021-08-06 16:15   ` Felipe Contreras
  0 siblings, 0 replies; 9+ messages in thread
From: Felipe Contreras @ 2021-08-06 16:15 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, Felipe Contreras
  Cc: git, ZheNing Hu, Fabian Stelzer, SZEDER Gábor,
	Junio C Hamano

Ævar Arnfjörð Bjarmason wrote:
> On Thu, Aug 05 2021, Felipe Contreras wrote:
> 
> > Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
> > repeatability, 2021-06-29) multiple tests have been failing when using
> > bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
> > reset using TIOCGWINSZ even for non-interactive shells.
> >
> > It's debatable whether or not bash should even be doing that, but for
> > now we can avoid this undesirable behavior by disabling this option.
> >
> > Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
> > Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> 
> I've got an alternative way of solving the same immeditate issue in[1],
> there's discussion on that approach in the latest What's Cooking[2].

Yes, but I'm not allowed to participate in that discussion.

> My preference for mine is in no small part that I'd like to not be
> responsible for into-the-past test suite breakage the next time a
> popular shell decides to be clever about COLUMNS.
> 
> But this way we'll solve the immediate problem with bash, and I can say
> I told you so if that submarine breakage occurs with this approach :)

I believe what bash is doing is a mistake. I don't think COLUMNS should
be updated within a non-interactive shell by default. I'll report that
as a bug once I'm able to subsscribe to the bug-bash mailing list.

So I think it's the opposite: not only would similar fixes not be needed
for other shells, but it won't be needed for bash either.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] test: fix for COLUMNS and bash 5
  2021-08-05 19:48 [PATCH] test: fix for COLUMNS and bash 5 Felipe Contreras
  2021-08-05 23:35 ` Ævar Arnfjörð Bjarmason
  2021-08-06 14:49 ` SZEDER Gábor
@ 2021-08-06 16:44 ` Felipe Contreras
  2021-08-07  1:37   ` ZheNing Hu
  2 siblings, 1 reply; 9+ messages in thread
From: Felipe Contreras @ 2021-08-06 16:44 UTC (permalink / raw)
  To: git
  Cc: Ævar Arnfjörð Bjarmason, SZEDER Gábor,
	ZheNing Hu, Felipe Contreras, Fabian Stelzer

Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
repeatability, 2021-06-29) multiple tests have been failing when using
bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
reset using TIOCGWINSZ even for non-interactive shells.

It's debatable whether or not bash should even be doing that, but for
now we can avoid this undesirable behavior by disabling this option.

Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---

Since v1 moved the code before setting COLUMNS as SZEDER Gábor suggested
and mention checkwinsize could be set before bash 5 as Ævar Arnfjörð
Bjarmason mentioned.

Range-diff against v1:
1:  40273074de < -:  ---------- test: fix for COLUMNS and bash 5
-:  ---------- > 1:  9f8c3ffa6a test: fix for COLUMNS and bash 5

 t/test-lib.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index db61081d6b..6b1015a5af 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -409,6 +409,12 @@ then
 	verbose=t
 fi
 
+# In bash if checkwinsize is enabled the COLUMNS variable is updated every time
+# an external command completes, even for non-interactive shells. Since bash 5.0
+# this is enabled by default.
+# Disable that since we are aiming for reproducibility.
+test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
+
 # For repeatability, reset the environment to known value.
 # TERM is sanitized below, after saving color control sequences.
 LANG=C
-- 
2.32.0.40.gb9b36f9b52


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] test: fix for COLUMNS and bash 5
  2021-08-06 14:49 ` SZEDER Gábor
@ 2021-08-06 16:59   ` Junio C Hamano
  2021-08-23 12:59     ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2021-08-06 16:59 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Felipe Contreras, git, ZheNing Hu, Fabian Stelzer,
	Ævar Arnfjörð Bjarmason

SZEDER Gábor <szeder.dev@gmail.com> writes:

>> @@ -419,6 +419,12 @@ COLUMNS=80
>
> COLUMNS is set just before the start of the hunk context ...
>
>>  export LANG LC_ALL PAGER TZ COLUMNS
>>  EDITOR=:
>
> ... so these two "commands" above are executed while COLUMNS is
> already set but checkwinsize is not yet disabled.  The reason I put
> quotes around that commands is that while exporting and setting
> variables are indeed commands as defined in the POSIX Shell Command
> Language specs, Bash with checkwinsize enabled only "checks the window
> size after each extern (non-builtin) command" (quoting 'man bash').
>
> So even though it is safe to execute these variable setting and
> exporting commands after setting COLUMNS but disabling checkwinsize, I
> think it would be prudent to disable checkwinsize before initializing
> COLUMNS.  (And perhaps adding "non-builtin" to the comment below.)

OK.  I tend to agree that a less invasive solution like this is
preferred over adding new code to only help tests in the everyday
binary, especially this close to the final.  Taking the above, I'd
queue this and hopefully I can merge it by -rc2 at the latest.

---- >8 ------- >8 ------- >8 ------- >8 ------- >8 ------- >8 ----
From: Felipe Contreras <felipe.contreras@gmail.com>
Date: Thu, 5 Aug 2021 14:48:25 -0500
Subject: [PATCH] test: fix for COLUMNS and bash 5

Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
repeatability, 2021-06-29) multiple tests have been failing when using
bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
reset using TIOCGWINSZ even for non-interactive shells.

It's debatable whether or not bash should even be doing that, but for
now we can avoid this undesirable behavior by disabling this option.

Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
[jc: with SZEDER Gábor's suggestion to do this before setting COLUMNS]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/test-lib.sh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 4d4439a917..52701afaea 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -395,6 +395,12 @@ then
 	verbose=t
 fi
 
+# Since bash 5.0, checkwinsize is enabled by default which does
+# update the COLUMNS variable every time a non-builtin command
+# completes, even for non-interactive shells.
+# Disable that since we are aiming for repeatability.
+test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
+
 # For repeatability, reset the environment to known value.
 # TERM is sanitized below, after saving color control sequences.
 LANG=C
-- 
2.33.0-rc0-215-ge3efc65752


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] test: fix for COLUMNS and bash 5
  2021-08-06 16:44 ` [PATCH v2] " Felipe Contreras
@ 2021-08-07  1:37   ` ZheNing Hu
  0 siblings, 0 replies; 9+ messages in thread
From: ZheNing Hu @ 2021-08-07  1:37 UTC (permalink / raw)
  To: Felipe Contreras
  Cc: Git List, Ævar Arnfjörð Bjarmason,
	SZEDER Gábor, Fabian Stelzer

Felipe Contreras <felipe.contreras@gmail.com> 于2021年8月7日周六 上午12:44写道:
>
> Since c49a177bec (test-lib.sh: set COLUMNS=80 for --verbose
> repeatability, 2021-06-29) multiple tests have been failing when using
> bash 5 because checkwinsize is enabled by default, therefore COLUMNS is
> reset using TIOCGWINSZ even for non-interactive shells.
>
> It's debatable whether or not bash should even be doing that, but for
> now we can avoid this undesirable behavior by disabling this option.
>
> Reported-by: Fabian Stelzer <fabian.stelzer@campoint.net>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>
> Since v1 moved the code before setting COLUMNS as SZEDER Gábor suggested
> and mention checkwinsize could be set before bash 5 as Ævar Arnfjörð
> Bjarmason mentioned.
>
> Range-diff against v1:
> 1:  40273074de < -:  ---------- test: fix for COLUMNS and bash 5
> -:  ---------- > 1:  9f8c3ffa6a test: fix for COLUMNS and bash 5
>
>  t/test-lib.sh | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index db61081d6b..6b1015a5af 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -409,6 +409,12 @@ then
>         verbose=t
>  fi
>
> +# In bash if checkwinsize is enabled the COLUMNS variable is updated every time
> +# an external command completes, even for non-interactive shells. Since bash 5.0
> +# this is enabled by default.
> +# Disable that since we are aiming for reproducibility.
> +test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
> +
>  # For repeatability, reset the environment to known value.
>  # TERM is sanitized below, after saving color control sequences.
>  LANG=C
> --
> 2.32.0.40.gb9b36f9b52
>

This can work on Arch-Linux. LGTM.

Thanks.
--
ZheNing Hu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test: fix for COLUMNS and bash 5
  2021-08-06 16:59   ` Junio C Hamano
@ 2021-08-23 12:59     ` Ævar Arnfjörð Bjarmason
  2021-08-23 20:24       ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-08-23 12:59 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: SZEDER Gábor, Felipe Contreras, git, ZheNing Hu,
	Fabian Stelzer


On Fri, Aug 06 2021, Junio C Hamano wrote:

> SZEDER Gábor <szeder.dev@gmail.com> writes:
>
>>> @@ -419,6 +419,12 @@ COLUMNS=80
>>
>> COLUMNS is set just before the start of the hunk context ...
>>
>>>  export LANG LC_ALL PAGER TZ COLUMNS
>>>  EDITOR=:
>>
>> ... so these two "commands" above are executed while COLUMNS is
>> already set but checkwinsize is not yet disabled.  The reason I put
>> quotes around that commands is that while exporting and setting
>> variables are indeed commands as defined in the POSIX Shell Command
>> Language specs, Bash with checkwinsize enabled only "checks the window
>> size after each extern (non-builtin) command" (quoting 'man bash').
>>
>> So even though it is safe to execute these variable setting and
>> exporting commands after setting COLUMNS but disabling checkwinsize, I
>> think it would be prudent to disable checkwinsize before initializing
>> COLUMNS.  (And perhaps adding "non-builtin" to the comment below.)
>
> OK.  I tend to agree that a less invasive solution like this is
> preferred over adding new code to only help tests in the everyday
> binary, especially this close to the final.  Taking the above, I'd
> queue this and hopefully I can merge it by -rc2 at the latest.

Now that we're post-release are you interested in a re-roll of
https://lore.kernel.org/git/cover-v3-0.3-00000000000-20210804T230335Z-avarab@gmail.com/
+ removal of the bash-specific checkwinsize added here, or would you
like to just keep Felipe's version which you integrated as 390b44eb2bc
(test: fix for COLUMNS and bash 5, 2021-08-05).

Either works for me, just poking to see whether I should drop this from
my local TODO list or not...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] test: fix for COLUMNS and bash 5
  2021-08-23 12:59     ` Ævar Arnfjörð Bjarmason
@ 2021-08-23 20:24       ` Junio C Hamano
  0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2021-08-23 20:24 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: SZEDER Gábor, Felipe Contreras, git, ZheNing Hu,
	Fabian Stelzer

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> Now that we're post-release are you interested in a re-roll of
> https://lore.kernel.org/git/cover-v3-0.3-00000000000-20210804T230335Z-avarab@gmail.com/
> + removal of the bash-specific checkwinsize added here, or would you

Let's wait until we see a concrete breakage report that shows that
checkwinsize is insufficient.  Even if such a second shell calls its
facility differently, as long as it works in a similar way and
another single liner like

    test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null

we can keep piling such a single-liner next to each other, as the
number of shells we need to cater to would be less than a handful
anyway.

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-23 20:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 19:48 [PATCH] test: fix for COLUMNS and bash 5 Felipe Contreras
2021-08-05 23:35 ` Ævar Arnfjörð Bjarmason
2021-08-06 16:15   ` Felipe Contreras
2021-08-06 14:49 ` SZEDER Gábor
2021-08-06 16:59   ` Junio C Hamano
2021-08-23 12:59     ` Ævar Arnfjörð Bjarmason
2021-08-23 20:24       ` Junio C Hamano
2021-08-06 16:44 ` [PATCH v2] " Felipe Contreras
2021-08-07  1:37   ` ZheNing Hu

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).