git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	git@vger.kernel.org, "Alex Henrie" <alexhenrie24@gmail.com>,
	"Felipe Contreras" <felipe.contreras@gmail.com>,
	"Fabian Stelzer" <fabian.stelzer@campoint.net>,
	"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>
Subject: Re: [PATCH] test-lib.sh: use GIT_TEST_COLUMNS over COLUMNS
Date: Tue, 27 Jul 2021 17:53:04 -0700	[thread overview]
Message-ID: <xmqqzgu7b6of.fsf@gitster.g> (raw)
In-Reply-To: <YQBEhj/Y6m0pqOth@coredump.intra.peff.net> (Jeff King's message of "Tue, 27 Jul 2021 13:38:14 -0400")

Jeff King <peff@peff.net> writes:

>> Let's instead solve this more thoroughly. We'll now take
>> GIT_TEST_COLUMNS over COLUMNS, and furthermore intentionally spoil the
>> COLUMNS variable to break any tests that rely on it being set to a
>> sane value.
>> 
>> If something breaks because we have a codepath that's not
>> term_columns() checking COLUMNS we'd like to know about it, the narrow
>> "shopt -u checkwinsize" fix won't give us that.
>
> I guess people running with bash won't see the test breakage (because
> bash will quietly "fix" the COLUMNS setting). But enough people run with
> /bin/sh that we'll eventually notice.
>
>> This approach does mean that any tests of ours that expected to test
>> term_columns() behavior by setting COLUMNS will need to explicitly
>> unset GIT_TEST_COLUMNS, or set it to the empty string. I'm doing the
>> latter in all the tests changed here.
>
> This is rather ugly, and I'm not in general a fan of adding more
> test-only code into the bowels of Git itself. But it may be the least
> bad solution.

Yeah, this really look unsatisfactory, especially with this repeated
pattern that is hard to read:

+	GIT_TEST_COLUMNS= COLUMNS=81 git branch --column=column >actual &&
+	GIT_TEST_COLUMNS= COLUMNS=80 git branch --column=column >actual &&
+	GIT_TEST_COLUMNS= COLUMNS=80 git branch >actual &&
+	GIT_TEST_COLUMNS= COLUMNS=80 git branch -v | cut -c -8 | sed "s/ *$//" >actual &&

Perhaps with something like

	test_with_columns () {
        	local columns=$1
		shift
		GIT_TEST_COLUMNS= COLUMNS=$columns "$@"
	}

we may be able to hide the ugly implementation detail like this:

	test_with_columns 81 git branch --column=column >actual

and may become a bit more palatable?  A good thing is that this can
be done as two-step process, with its first step being 

    s/^(\s*)COLUMNS=(\d+)/$1test_with_columns $2/;

plus addition of the helper to test-lib, perhaps like so:

	test_with_columns () {
        	local columns=$1
		shift
		COLUMNS=$columns "$@"
	}

and the whole GIT_TEST_COLUMNS stuff being the second step.

  reply	other threads:[~2021-07-28  0:53 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 12:39 progress test failure on fedora34 Fabian Stelzer
2021-07-14 15:35 ` Ævar Arnfjörð Bjarmason
2021-07-14 16:35   ` Alex Henrie
2021-07-18  8:05     ` Ævar Arnfjörð Bjarmason
2021-07-19  9:00       ` Jeff King
2021-07-19 17:18       ` Alex Henrie
2021-07-19 18:21         ` Alex Henrie
2021-07-19 18:43       ` Felipe Contreras
2021-07-19 19:34         ` Felipe Contreras
2021-07-19 20:42           ` Alex Henrie
2021-07-20  0:40             ` Felipe Contreras
2021-07-21  0:45               ` ZheNing Hu
2021-07-21  2:50                 ` Felipe Contreras
2021-07-26 23:57             ` [PATCH] test-lib.sh: use GIT_TEST_COLUMNS over COLUMNS Ævar Arnfjörð Bjarmason
2021-07-27 17:38               ` Jeff King
2021-07-28  0:53                 ` Junio C Hamano [this message]
2021-08-02 13:46               ` [PATCH v2 0/3] " Ævar Arnfjörð Bjarmason
2021-08-02 13:46                 ` [PATCH v2 1/3] test-lib-functions.sh: rename test_must_fail_acceptable() Ævar Arnfjörð Bjarmason
2021-08-02 13:46                 ` [PATCH v2 2/3] test-lib-functions.sh: add a test_with_columns function Ævar Arnfjörð Bjarmason
2021-08-02 17:14                   ` SZEDER Gábor
2021-08-02 17:24                     ` Eric Sunshine
2021-08-02 13:46                 ` [PATCH v2 3/3] test-lib.sh: use GIT_TEST_COLUMNS over COLUMNS Ævar Arnfjörð Bjarmason
2021-08-04 23:05                 ` [PATCH v3 0/3] " Ævar Arnfjörð Bjarmason
2021-08-04 23:05                   ` [PATCH v3 1/3] test-lib-functions.sh: rename test_must_fail_acceptable() Ævar Arnfjörð Bjarmason
2021-08-04 23:05                   ` [PATCH v3 2/3] test-lib-functions.sh: add a test_with_columns function Ævar Arnfjörð Bjarmason
2021-08-04 23:05                   ` [PATCH v3 3/3] test-lib.sh: use GIT_TEST_COLUMNS over COLUMNS Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqzgu7b6of.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=alexhenrie24@gmail.com \
    --cc=avarab@gmail.com \
    --cc=fabian.stelzer@campoint.net \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=zbyszek@in.waw.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).