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

Re: [PATCH] test-lib.sh: use GIT_TEST_COLUMNS over COLUMNS

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 28, 2021, 00:53 UTC
Message-ID
<xmqqzgu7b6of.fsf@gitster.g>
In-Reply-To
<YQBEhj/Y6m0pqOth@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 21 quoted lines
>> 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.
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 16 of 26 in “progress test failure on fedora34”
  1. Fabian StelzerJul 14, 2021
  2. Ævar Arnfjörð BjarmasonJul 14, 2021
  3. Alex HenrieJul 14, 2021
  4. Ævar Arnfjörð BjarmasonJul 18, 2021
  5. Jeff KingJul 19, 2021
  6. Alex HenrieJul 19, 2021
  7. Alex HenrieJul 19, 2021
  8. Felipe ContrerasJul 19, 2021
  9. Felipe ContrerasJul 19, 2021
  10. Alex HenrieJul 19, 2021
  11. Felipe ContrerasJul 20, 2021
  12. ZheNing HuJul 21, 2021
  13. Felipe ContrerasJul 21, 2021
  14. test-lib.sh: use GIT_TEST_COLUMNS over COLUMNSÆvar Arnfjörð Bjarmason, Jul 26, 2021
  15. Jeff KingJul 27, 2021
  16. Junio C HamanoJul 28, 2021
  17. 0/3 test-lib.sh: use GIT_TEST_COLUMNS over COLUMNSÆvar Arnfjörð Bjarmason, Aug 2, 2021
  18. 1/3 test-lib-functions.sh: rename test_must_fail_acceptable()Ævar Arnfjörð Bjarmason, Aug 2, 2021
  19. 3/3 test-lib.sh: use GIT_TEST_COLUMNS over COLUMNSÆvar Arnfjörð Bjarmason, Aug 2, 2021
  20. 2/3 test-lib-functions.sh: add a test_with_columns functionÆvar Arnfjörð Bjarmason, Aug 2, 2021
  21. SZEDER GáborAug 2, 2021
  22. Eric SunshineAug 2, 2021
  23. 0/3 test-lib.sh: use GIT_TEST_COLUMNS over COLUMNSÆvar Arnfjörð Bjarmason, Aug 4, 2021
  24. 1/3 test-lib-functions.sh: rename test_must_fail_acceptable()Ævar Arnfjörð Bjarmason, Aug 4, 2021
  25. 3/3 test-lib.sh: use GIT_TEST_COLUMNS over COLUMNSÆvar Arnfjörð Bjarmason, Aug 4, 2021
  26. 2/3 test-lib-functions.sh: add a test_with_columns functionÆvar Arnfjörð Bjarmason, Aug 4, 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.