diff mbox series

test: fix for COLUMNS and bash 5

Message ID 20210805194825.1796765-1-felipe.contreras@gmail.com (mailing list archive)
State Superseded
Headers show
Series test: fix for COLUMNS and bash 5 | expand

Commit Message

Felipe Contreras Aug. 5, 2021, 7:48 p.m. UTC
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(+)

Comments

Ævar Arnfjörð Bjarmason Aug. 5, 2021, 11:35 p.m. UTC | #1
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.
SZEDER Gábor Aug. 6, 2021, 2:49 p.m. UTC | #2
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
>
Felipe Contreras Aug. 6, 2021, 4:15 p.m. UTC | #3
Æ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.
Junio C Hamano Aug. 6, 2021, 4:59 p.m. UTC | #4
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
Ævar Arnfjörð Bjarmason Aug. 23, 2021, 12:59 p.m. UTC | #5
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...
Junio C Hamano Aug. 23, 2021, 8:24 p.m. UTC | #6
Æ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.
diff mbox series

Patch

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