Skip to content

Commit ef85286

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 e325325 commit ef85286

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

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' '
@@ -430,8 +436,12 @@ test_expect_success 'listing tags -n in column with column.ui ignored' '
430436

431437
test_expect_success 'a non-annotated tag created without parameters should point to HEAD' '
432438
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
435445
'
436446

437447
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'
15201530
'
15211531

15221532
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
15241534
'
15251535

15261536
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
15281538
'
15291539

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

0 commit comments

Comments
 (0)