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

[PATCH v2 2/3] t7004: dynamically grab expected state in tests

From
Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
Date
Apr 21, 2026, 05:33 UTC
Message-ID
<20260421053334.5414-3-r.siddharth.shrimali@gmail.com>
In-Reply-To
<20260421053334.5414-1-r.siddharth.shrimali@gmail.com>

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(-)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 77a7a9777d..bef7618da2 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 &&
@@ -226,12 +224,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
-- 
2.51.2
Previous: Siddharth ShrimaliNext: Siddharth Shrimali
Message 10 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.