]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t7004: replace wc -l with modern test helpers
authorSiddharth Shrimali <r.siddharth.shrimali@gmail.com>
Wed, 1 Apr 2026 06:20:29 +0000 (11:50 +0530)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Apr 2026 18:45:25 +0000 (11:45 -0700)
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>
t/t7004-tag.sh

index ce2ff2a28abaa37e7fe95f422c4faa64980339b6..faf7d97fc487d301d27f7346cbf2b83c4e289f77 100755 (executable)
@@ -33,8 +33,10 @@ test_expect_success 'listing all tags in an empty tree should succeed' '
 '
 
 test_expect_success 'listing all tags in an empty tree should output nothing' '
-       test $(git tag -l | wc -l) -eq 0 &&
-       test $(git tag | wc -l) -eq 0
+       git tag -l >actual &&
+       test_must_be_empty actual &&
+       git tag >actual &&
+       test_must_be_empty actual
 '
 
 test_expect_success 'sort tags, ignore case' '
@@ -178,7 +180,8 @@ test_expect_success 'listing tags using a non-matching pattern should succeed' '
 '
 
 test_expect_success 'listing tags using a non-matching pattern should output nothing' '
-       test $(git tag -l xxx | wc -l) -eq 0
+       git tag -l xxx >actual &&
+       test_must_be_empty actual
 '
 
 # special cases for creating tags:
@@ -188,13 +191,15 @@ test_expect_success 'trying to create a tag with the name of one existing should
 '
 
 test_expect_success 'trying to create a tag with a non-valid name should fail' '
-       test $(git tag -l | wc -l) -eq 1 &&
+       git tag -l >actual &&
+       test_line_count = 1 actual &&
        test_must_fail git tag "" &&
        test_must_fail git tag .othertag &&
        test_must_fail git tag "other tag" &&
        test_must_fail git tag "othertag^" &&
        test_must_fail git tag "other~tag" &&
-       test $(git tag -l | wc -l) -eq 1
+       git tag -l >actual &&
+       test_line_count = 1 actual
 '
 
 test_expect_success 'creating a tag using HEAD directly should succeed' '