Skip to content

Commit 0a85ca1

Browse files
SiddharthShrimaligitster
authored andcommitted
t7004: dynamically grab expected state in tests
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6d0a3d9 commit 0a85ca1

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

t/t7004-tag.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ test_expect_success 'listing all tags if one exists should succeed' '
145145
'
146146

147147
test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
148-
cat >expect <<-\EOF &&
149-
mytag
150-
EOF
148+
git tag -l >expect &&
151149
git tag -l -l >actual &&
152150
test_cmp expect actual &&
153151
git tag --list --list >actual &&
@@ -223,12 +221,7 @@ test_expect_success 'trying to delete an unknown tag should fail' '
223221
'
224222

225223
test_expect_success 'trying to delete tags without params should succeed and do nothing' '
226-
cat >expect <<-\EOF &&
227-
myhead
228-
mytag
229-
EOF
230-
git tag -l >actual &&
231-
test_cmp expect actual &&
224+
git tag -l >expect &&
232225
git tag -d &&
233226
git tag -l >actual &&
234227
test_cmp expect actual

0 commit comments

Comments
 (0)