t7004: replace wc -l with modern test helpers
Pipelines of the form "test $(git tag | wc -l) -eq 0" suppress git's exit code. This means a crash or unexpected failure from git tag would go undetected. Additionally, the use of $(...) creates a subshell for each check, which adds unnecessary overhead. Replace these patterns with test_must_be_empty and test_line_count. These helpers check the output of git directly from a file, ensuring git's exit code is captured properly via the preceding "&&" chain. They also provide better diagnostics on failure by printing the contents of the file when a check does not pass. Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Siddharth Shrimali committed
Apr 1, 2026 at 11:50 UTC
42148dafdf74f8458e7a710dcb982c0be0e40566
1 file changed
+10
-5
t/t7004-tag.sh
+10
-5
@@ -33,8 +33,10 @@ test_expect_success 'listing all tags in an empty tree should succeed' '
33
'
34
35
test_expect_success 'listing all tags in an empty tree should output nothing' '
36
- test $(git tag -l | wc -l) -eq 0 &&
37
- test $(git tag | wc -l) -eq 0
36
+ git tag -l >actual &&
37
+ test_must_be_empty actual &&
38
+ git tag >actual &&
39
+ test_must_be_empty actual
40
'
41
42
test_expect_success 'sort tags, ignore case' '
@@ -178,7 +180,8 @@ test_expect_success 'listing tags using a non-matching pattern should succeed' '
180
'
181
182
test_expect_success 'listing tags using a non-matching pattern should output nothing' '
181
- test $(git tag -l xxx | wc -l) -eq 0
183
+ git tag -l xxx >actual &&
184
+ test_must_be_empty actual
185
'
186
187
# special cases for creating tags:
@@ -188,13 +191,15 @@ test_expect_success 'trying to create a tag with the name of one existing should
191
'
192
193
test_expect_success 'trying to create a tag with a non-valid name should fail' '
191
- test $(git tag -l | wc -l) -eq 1 &&
194
+ git tag -l >actual &&
195
+ test_line_count = 1 actual &&
196
test_must_fail git tag "" &&
197
test_must_fail git tag .othertag &&
198
test_must_fail git tag "other tag" &&
199
test_must_fail git tag "othertag^" &&
200
test_must_fail git tag "other~tag" &&
197
- test $(git tag -l | wc -l) -eq 1
201
+ git tag -l >actual &&
202
+ test_line_count = 1 actual
203
'
204
205
test_expect_success 'creating a tag using HEAD directly should succeed' '