All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Cc: git@vger.kernel.org,  abdobngad@gmail.com,  ps@pks.im,
	bence@ferdinandy.com,  john.a.passaro@gmail.com
Subject: Re: [PATCH 2/3] t7004: dynamically grab expected state in tests
Date: Tue, 14 Apr 2026 10:00:47 -0700	[thread overview]
Message-ID: <xmqqik9tbhog.fsf@gitster.g> (raw)
In-Reply-To: <20260414141828.27576-3-r.siddharth.shrimali@gmail.com> (Siddharth Shrimali's message of "Tue, 14 Apr 2026 19:48:27 +0530")

Siddharth Shrimali <r.siddharth.shrimali@gmail.com> writes:

> The tests for 'Multiple -l or --list options' and 'trying to delete
> tags without params', hardcodes that exactly one or two specific tags
> ('myhead', 'mytag') exist in the repository.
>
> If other tests are added, modified, or removed earlier in the script,
> this expected global state will change, resulting in these tests to fail
> for completely unrelated reasons.
>
> Instead of hardcoding the expected tags, dynamically grab the state
> of the repository before running the commands under test ('git tag -l'
> and 'git tag -d'), and verify that the output matches or remains
> unchanged afterward. This keeps the tests independent from the script's
> overall state.
>
> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
> ---
>  t/t7004-tag.sh | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)

Excellent.  I agree with both reasoning above and execution below.

>
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> index 6ca5c75b57..4fdd47cd21 100755
> --- a/t/t7004-tag.sh
> +++ b/t/t7004-tag.sh
> @@ -145,9 +145,7 @@ test_expect_success 'listing all tags if one exists should succeed' '
>  '
>  
>  test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
> -	cat >expect <<-\EOF &&
> -	mytag
> -	EOF
> +	git tag -l >expect &&
>  	git tag -l -l >actual &&
>  	test_cmp expect actual &&
>  	git tag --list --list >actual &&
> @@ -223,12 +221,7 @@ test_expect_success 'trying to delete an unknown tag should fail' '
>  '
>  
>  test_expect_success 'trying to delete tags without params should succeed and do nothing' '
> -	cat >expect <<-\EOF &&
> -	myhead
> -	mytag
> -	EOF
> -	git tag -l >actual &&
> -	test_cmp expect actual &&
> +	git tag -l >expect &&
>  	git tag -d &&
>  	git tag -l >actual &&
>  	test_cmp expect actual

  reply	other threads:[~2026-04-14 17:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14 14:18 [PATCH 0/3] t7004: cleanup and modernize brittle tests Siddharth Shrimali
2026-04-14 14:18 ` [PATCH 1/3] t7004: drop hardcoded tag count in invalid name test Siddharth Shrimali
2026-04-14 16:54   ` Junio C Hamano
2026-04-20  7:13     ` Patrick Steinhardt
2026-04-14 14:18 ` [PATCH 2/3] t7004: dynamically grab expected state in tests Siddharth Shrimali
2026-04-14 17:00   ` Junio C Hamano [this message]
2026-04-14 14:18 ` [PATCH 3/3] t7004: avoid subshells to capture git exit codes Siddharth Shrimali
2026-04-21  5:33 ` [PATCH v2 0/3] t7004: cleanup and modernize brittle tests Siddharth Shrimali
2026-04-21  5:33   ` [PATCH v2 1/3] t7004: drop hardcoded tag count for state verification Siddharth Shrimali
2026-04-21  5:33   ` [PATCH v2 2/3] t7004: dynamically grab expected state in tests Siddharth Shrimali
2026-04-21  5:33   ` [PATCH v2 3/3] t7004: avoid subshells to capture git exit codes Siddharth Shrimali
2026-04-21  5:38   ` [PATCH v2 0/3] t7004: cleanup and modernize brittle tests Patrick Steinhardt

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=xmqqik9tbhog.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=abdobngad@gmail.com \
    --cc=bence@ferdinandy.com \
    --cc=git@vger.kernel.org \
    --cc=john.a.passaro@gmail.com \
    --cc=ps@pks.im \
    --cc=r.siddharth.shrimali@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.