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

[PATCH v2 1/3] t7004: drop hardcoded tag count for state verification

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Apr 21, 2026, 05:33 UTC
Message-ID
<20260421053334.5414-2-r.siddharth.shrimali@gmail.com>
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
Previous: Siddharth ShrimaliNext: Siddharth Shrimali
Message 9 of 12 in “t7004: cleanup and modernize brittle tests”
  1. 0/3 t7004: cleanup and modernize brittle testsSiddharth Shrimali, Apr 14, 2026
  2. 1/3 t7004: drop hardcoded tag count in invalid name testSiddharth Shrimali, Apr 14, 2026
  3. Junio C HamanoApr 14, 2026
  4. Patrick SteinhardtApr 20, 2026
  5. 2/3 t7004: dynamically grab expected state in testsSiddharth Shrimali, Apr 14, 2026
  6. Junio C HamanoApr 14, 2026
  7. 3/3 t7004: avoid subshells to capture git exit codesSiddharth Shrimali, Apr 14, 2026
  8. 0/3 t7004: cleanup and modernize brittle testsSiddharth Shrimali, Apr 21, 2026
  9. 1/3 t7004: drop hardcoded tag count for state verificationSiddharth Shrimali, Apr 21, 2026
  10. 2/3 t7004: dynamically grab expected state in testsSiddharth Shrimali, Apr 21, 2026
  11. 3/3 t7004: avoid subshells to capture git exit codesSiddharth Shrimali, Apr 21, 2026
  12. Patrick SteinhardtApr 21, 2026

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.