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

Re: [PATCH v2] tests: modernize the test script t0010-racy-git.sh

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 29, 2024, 23:14 UTC
Message-ID
<xmqqle72c17i.fsf@gitster.g>
In-Reply-To
<pull.1675.v2.git.1709243831190.gitgitgadget@gmail.com>
"Aryan Gupta via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Aryan Gupta <garyan447@gmail.com>
>
> Modernize the formatting of the test script to align with current
> standards and improve its overall readability.
OK.
Show 9 quoted lines
> diff --git a/t/t0010-racy-git.sh b/t/t0010-racy-git.sh
> index 837c8b7228b..2ceac06c9c2 100755
> --- a/t/t0010-racy-git.sh
> +++ b/t/t0010-racy-git.sh
> @@ -1,6 +1,6 @@
>  #!/bin/sh
>  
> -test_description='racy GIT'
> +test_description='racy git'

This does not look like updating formatting to the current standard, or improving readability, though.

Show 14 quoted lines
> -	test_expect_success \
> -	"Racy GIT trial #$trial part A" \
> -	'test "" != "$files"'
> +	test_expect_success "Racy git trial #$trial part A" '
> +		test "" != "$files"
> +	'
> ...
> -	test_expect_success \
> -	"Racy GIT trial #$trial part B" \
> -	'test "" != "$files"'
> -
> +	test_expect_success "Racy git trial #$trial part B" '
> +		test "" != "$files"
> +	'

These are not wrong per-se, but if we are updating, I wonder if we want to get rid of statements outside the test_expect_success block, not just the formatting of individual test_expect_success tests.

Looking at an iteration of the loop, the executable statements from here ...

                rm -f .git/index
                echo frotz >infocom
                git update-index --add infocom
                echo xyzzy >infocom
                files=$(git diff-files -p)
... to here is what we would make part of one test, namely ...
                test_expect_success \
                "Racy GIT trial #$trial part A" \
                'test "" != "$files"'
... this one.  Then
                sleep 1

is a cricial delay to have before the next test, which we may want to have outside to make it clear what is going on to readers. But the following parts ...

                echo xyzzy >cornerstone
                git update-index --add cornerstone
                files=$(git diff-files -p)
... up to here, we would make part of the next test ...
                test_expect_success \
                "Racy GIT trial #$trial part B" \
                'test "" != "$files"'
... in the modern style.
So, we may want to do it more like this, perhaps?
	test_expect_success "Racy GIT trial #$trial part A" '
		rm -f .git/index &&
		echo frotz >infocom &&
		git update-index --add infocom &&
		echo xyzzy >infocom &&
		files=$(git diff-files -p) &&
                test "" != "$files"
	'
	sleep 1
	test_expect_success "Racy GIT trial #$trial part B" '
		echo xyzzy >cornerstone &&
		git update-index --add cornerstone &&
		files=$(git diff-files -p) &&
		test "" != "$files"
	'

An added benefit of the more modern style to place as much as possible to &&-chain in test_expect_success block is that we would catch breakage in "git update-index" and other things used to set-up the test as well. With the original loop, breakages in things outside the test_expect_success blocks will go unchecked.

Previous: Eric SunshineNext: Eric Sunshine
Message 5 of 18 in “tests: modernize the test script t0010-racy-git.sh”
  1. tests: modernize the test script t0010-racy-git.shAryan Gupta via GitGitGadget, Feb 29, 2024
  2. Eric SunshineFeb 29, 2024
  3. tests: modernize the test script t0010-racy-git.shAryan Gupta via GitGitGadget, Feb 29, 2024
  4. Eric SunshineFeb 29, 2024
  5. Junio C HamanoFeb 29, 2024
  6. Eric SunshineFeb 29, 2024
  7. Junio C HamanoFeb 29, 2024
  8. Eric SunshineFeb 29, 2024
  9. Eric SunshineMar 1, 2024
  10. Junio C HamanoMar 1, 2024
  11. tests: modernize the test script t0010-racy-git.shAryan Gupta via GitGitGadget, Mar 5, 2024
  12. Junio C HamanoMar 5, 2024
  13. tests: modernize the test script t0010-racy-git.shAryan Gupta via GitGitGadget, Mar 6, 2024
  14. Christian CouderMar 7, 2024
  15. Aryan GuptaMar 7, 2024
  16. Junio C HamanoMar 7, 2024
  17. Junio C HamanoMar 7, 2024
  18. Aryan GuptaMar 7, 2024

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.