t7004: avoid subshells to capture git exit codes

Several tests in t7004 use the 'test$(git ...) = ...' or the '! (git ...)' subshell pattern. This swallows git's exit code. If git crashes (e.g. segmentation fault) the crash would go undetected, and the test would fail due to a mismatch or an inverted exit code. Modernize these tests by directly writing output to files(actual) and verifying them with 'test_cmp' or 'test_grep'. Replace subshell negations with 'test_must_fail'. This way, if git crashes, the test fails immediately and clearly instead of hiding the error behind a string mismatch. Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Siddharth Shrimali committed Apr 21, 2026 at 11:03 UTC ef85286e511b4cebfdce0c4bffc7c8985274f142
1 file changed +18 -8
t/t7004-tag.sh
+18 -8
@@ -155,8 +155,10 @@ test_expect_success 'Multiple -l or --list options are equivalent to one -l opti
155 '
156
157 test_expect_success 'listing all tags if one exists should output that tag' '
158 - test $(git tag -l) = mytag &&
159 - test $(git tag) = mytag
158 + git tag -l >actual &&
159 + test_grep "^mytag$" actual &&
160 + git tag >actual &&
161 + test_grep "^mytag$" actual
162 '
163
164 # pattern matching:
@@ -166,11 +168,15 @@ test_expect_success 'listing a tag using a matching pattern should succeed' '
168 '
169
170 test_expect_success 'listing a tag with --ignore-case' '
169 - test $(git tag -l --ignore-case MYTAG) = mytag
171 + echo mytag >expect &&
172 + git tag -l --ignore-case MYTAG >actual &&
173 + test_cmp expect actual
174 '
175
176 test_expect_success 'listing a tag using a matching pattern should output that tag' '
173 - test $(git tag -l mytag) = mytag
177 + echo mytag >expect &&
178 + git tag -l mytag >actual &&
179 + test_cmp expect actual
180 '
181
182 test_expect_success 'listing tags using a non-matching pattern should succeed' '
@@ -430,8 +436,12 @@ test_expect_success 'listing tags -n in column with column.ui ignored' '
436
437 test_expect_success 'a non-annotated tag created without parameters should point to HEAD' '
438 git tag non-annotated-tag &&
433 - test $(git cat-file -t non-annotated-tag) = commit &&
434 - test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
439 + echo commit >expect &&
440 + git cat-file -t non-annotated-tag >actual &&
441 + test_cmp expect actual &&
442 + git rev-parse HEAD >expect &&
443 + git rev-parse non-annotated-tag >actual &&
444 + test_cmp expect actual
445 '
446
447 test_expect_success 'trying to verify an unknown tag should fail' '
@@ -1520,11 +1530,11 @@ test_expect_success GPG 'verify signed tag fails when public key is not present'
1530 '
1531
1532 test_expect_success 'git tag -a fails if tag annotation is empty' '
1523 - ! (GIT_EDITOR=cat git tag -a initial-comment)
1533 + test_must_fail env GIT_EDITOR=cat git tag -a initial-comment
1534 '
1535
1536 test_expect_success 'message in editor has initial comment' '
1527 - ! (GIT_EDITOR=cat git tag -a initial-comment >actual)
1537 + test_must_fail env GIT_EDITOR=cat git tag -a initial-comment >actual
1538 '
1539
1540 test_expect_success 'message in editor has initial comment: first line' '