Git development
 help / color / mirror / Atom feed
From: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, ps@pks.im, abdobngad@gmail.com,
	bence@ferdinandy.com, john.a.passaro@gmail.com,
	r.siddharth.shrimali@gmail.com
Subject: [PATCH v2 1/3] t7004: drop hardcoded tag count for state verification
Date: Tue, 21 Apr 2026 11:03:32 +0530	[thread overview]
Message-ID: <20260421053334.5414-2-r.siddharth.shrimali@gmail.com> (raw)
In-Reply-To: <20260421053334.5414-1-r.siddharth.shrimali@gmail.com>

The test 'trying to create a tag with a non-valid name should fail',
checked that exactly one tag existed in the repository before and after
attempting to create invalid tags.

As pointed out by Junio, this makes the test brittle by relying on a
specific global tag count. If future tests are added or removed before
this test, the expected state changes and this test would break for
completely unrelated reasons.

Modernize the test by taking a snapshot of the existing tags before the
failure attempts and comparing it to a snapshot taken after.
This provides a "belt-and-suspenders" approach: we verify that
'git tag' both exits with the expected error code and leaves the
repository state untouched, without being brittle to the specific
number of tags present.

This replaces the hardcoded 'test_line_count = 1' checks with 'test_cmp'
to ensure the tag list remains identical.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
 t/t7004-tag.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index faf7d97fc4..77a7a9777d 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -191,15 +191,14 @@ test_expect_success 'trying to create a tag with the name of one existing should
 '
 
 test_expect_success 'trying to create a tag with a non-valid name should fail' '
-	git tag -l >actual &&
-	test_line_count = 1 actual &&
+	git tag -l >tags-before &&
 	test_must_fail git tag "" &&
 	test_must_fail git tag .othertag &&
 	test_must_fail git tag "other tag" &&
 	test_must_fail git tag "othertag^" &&
 	test_must_fail git tag "other~tag" &&
-	git tag -l >actual &&
-	test_line_count = 1 actual
+	git tag -l >tags-after &&
+	test_cmp tags-before tags-after
 '
 
 test_expect_success 'creating a tag using HEAD directly should succeed' '
-- 
2.51.2


  reply	other threads:[~2026-04-21  5:33 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
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   ` Siddharth Shrimali [this message]
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=20260421053334.5414-2-r.siddharth.shrimali@gmail.com \
    --to=r.siddharth.shrimali@gmail.com \
    --cc=abdobngad@gmail.com \
    --cc=bence@ferdinandy.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=john.a.passaro@gmail.com \
    --cc=ps@pks.im \
    /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