Skip to content

Commit 46106a4

Browse files
SiddharthShrimaligitster
authored andcommitted
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>
1 parent 0a85ca1 commit 46106a4

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

t/t7004-tag.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ test_expect_success 'Multiple -l or --list options are equivalent to one -l opti
155155
'
156156

157157
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
160162
'
161163

162164
# pattern matching:
@@ -166,11 +168,15 @@ test_expect_success 'listing a tag using a matching pattern should succeed' '
166168
'
167169

168170
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
170174
'
171175

172176
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
174180
'
175181

176182
test_expect_success 'listing tags using a non-matching pattern should succeed' '
@@ -427,8 +433,12 @@ test_expect_success 'listing tags -n in column with column.ui ignored' '
427433

428434
test_expect_success 'a non-annotated tag created without parameters should point to HEAD' '
429435
git tag non-annotated-tag &&
430-
test $(git cat-file -t non-annotated-tag) = commit &&
431-
test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
436+
echo commit >expect &&
437+
git cat-file -t non-annotated-tag >actual &&
438+
test_cmp expect actual &&
439+
git rev-parse HEAD >expect &&
440+
git rev-parse non-annotated-tag >actual &&
441+
test_cmp expect actual
432442
'
433443

434444
test_expect_success 'trying to verify an unknown tag should fail' '
@@ -1517,11 +1527,11 @@ test_expect_success GPG 'verify signed tag fails when public key is not present'
15171527
'
15181528

15191529
test_expect_success 'git tag -a fails if tag annotation is empty' '
1520-
! (GIT_EDITOR=cat git tag -a initial-comment)
1530+
test_must_fail env GIT_EDITOR=cat git tag -a initial-comment
15211531
'
15221532

15231533
test_expect_success 'message in editor has initial comment' '
1524-
! (GIT_EDITOR=cat git tag -a initial-comment >actual)
1534+
test_must_fail env GIT_EDITOR=cat git tag -a initial-comment >actual
15251535
'
15261536

15271537
test_expect_success 'message in editor has initial comment: first line' '

0 commit comments

Comments
 (0)