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

Re: [PATCH v5 7/8] t7004: use single quotes instead of double quotes

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 8, 2024, 15:36 UTC
Message-ID
<xmqqed6zkowv.fsf@gitster.g>
In-Reply-To
<20240807130259.28381-8-abdobngad@gmail.com>
AbdAlRahman Gad <abdobngad@gmail.com> writes:
Show 7 quoted lines
> Some test bodies and test description are surrounded with double
> quotes instead of single quotes, violating our coding style.
>
> Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
> ---
>  t/t7004-tag.sh | 70 +++++++++++++++++++++++++-------------------------
>  1 file changed, 35 insertions(+), 35 deletions(-)

The conversion in this step can cause unintended breakage and needs to be carefully done, so I checked with "git show -W" (I probably should have done -U999 instead of just -W).

Show 11 quoted lines
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> index 2b15ede1f3..046a5bd9bc 100755
> --- a/t/t7004-tag.sh
> +++ b/t/t7004-tag.sh
> @@ -1583,7 +1583,7 @@ test_expect_success 'creating third commit without tag' '
>  
>  # simple linear checks of --continue
>  
> -test_expect_success 'checking that first commit is in all tags (hash)' "
> +test_expect_success 'checking that first commit is in all tags (hash)' '
>  	hash3=$(git rev-parse HEAD) &&

The original used to resolve "HEAD" while formulating the command line of test_expect_success. Now we resolve "HEAD" as the first thing the body given to test_expect_success is run. As HEAD does not move between these two points in time, hash3 would get the same value either way.

Show 8 quoted lines
>  	cat >expected <<-\EOF &&
>  	v0.2.1
> @@ -1594,10 +1594,10 @@ test_expect_success 'checking that first commit is in all tags (hash)' "
>  	EOF
>  	git tag -l --contains $hash1 v* >actual &&
>  	test_cmp expected actual
> -"
> +'

The argument to the "--contains" option was interpolated while the command line of test_expect_success was formulated. If the body of this test_expect_success modified the value of $hash1, this conversion would have changed what the tested command did, but because nobody assigns to $hash1 after it gets assigned (and this is true for other $hash[0-9] variables), this conversion is OK.

Show 16 quoted lines
>  for option in --contains --with --no-contains --without --merged --no-merged --points-at
>  do
> -	test_expect_success "mixing incompatible modes with $option is forbidden" "
> +	test_expect_success "mixing incompatible modes with $option is forbidden" '
>  		test_must_fail git tag -d $option HEAD &&
>  		test_must_fail git tag -d $option HEAD some-tag &&
>  		test_must_fail git tag -v $option HEAD
> -	"
> -	test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
> +	'
> +	test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" '
>  		git tag -n $option HEAD HEAD &&
>  		git tag $option HEAD HEAD &&
>  		git tag $option
> -	"
> +	'
Likewise.

The value of $option of course changes for each iteration of the loop, and the original interpolated it into the tested scripts while test_expect_success command lines were formulated in the original. Now the variable $option is used just like any other variable while the body is run, and the tested scripts behave identically either way.

Looks good.  Thanks.
Previous: AbdAlRahman GadNext: AbdAlRahman Gad
Message 9 of 12 in “[Newcomer] t7004: modernize the style”
  1. 0/8 [Newcomer] t7004: modernize the styleAbdAlRahman Gad, Aug 7, 2024
  2. 1/8 t7004: remove space after redirect operatorsAbdAlRahman Gad, Aug 7, 2024
  3. 2/8 t7004: one command per lineAbdAlRahman Gad, Aug 7, 2024
  4. 4/8 t7004: use indented here-docAbdAlRahman Gad, Aug 7, 2024
  5. 3/8 t7004: do not prepare things outside test_expect_successAbdAlRahman Gad, Aug 7, 2024
  6. 5/8 t7004: description on the same line as test_expect_successAbdAlRahman Gad, Aug 7, 2024
  7. 6/8 t7004: test description and test body seperated with backslashAbdAlRahman Gad, Aug 7, 2024
  8. 7/8 t7004: use single quotes instead of double quotesAbdAlRahman Gad, Aug 7, 2024
  9. Junio C HamanoAug 8, 2024
  10. 8/8 t7004: make use of write_scriptAbdAlRahman Gad, Aug 7, 2024
  11. Junio C HamanoAug 8, 2024
  12. AbdAlRahman GadAug 8, 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.