Skip to content

Commit 6bd26f5

Browse files
Denton-Lgitster
authored andcommitted
t4014: use test_line_count() where possible
Convert all instances of `cnt=$(... | wc -l) && test $cnt = N` into uses of `test_line_count()`. While we're at it, convert one instance of a Git command upstream of a pipe into two commands. This prevents a failure of a Git command from being masked since only the return code of the last member of the pipe is shown. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c6ec6da commit 6bd26f5

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

t/t4014-format-patch.sh

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ test_expect_success setup '
6060

6161
test_expect_success 'format-patch --ignore-if-in-upstream' '
6262
git format-patch --stdout master..side >patch0 &&
63-
cnt=$(grep "^From " patch0 | wc -l) &&
64-
test $cnt = 3
63+
grep "^From " patch0 >from0 &&
64+
test_line_count = 3 from0
6565
'
6666

6767
test_expect_success 'format-patch --ignore-if-in-upstream' '
6868
git format-patch --stdout \
6969
--ignore-if-in-upstream master..side >patch1 &&
70-
cnt=$(grep "^From " patch1 | wc -l) &&
71-
test $cnt = 2
70+
grep "^From " patch1 >from1 &&
71+
test_line_count = 2 from1
7272
'
7373

7474
test_expect_success 'format-patch --ignore-if-in-upstream handles tags' '
7575
git tag -a v1 -m tag side &&
7676
git tag -a v2 -m tag master &&
7777
git format-patch --stdout --ignore-if-in-upstream v2..v1 >patch1 &&
78-
cnt=$(grep "^From " patch1 | wc -l) &&
79-
test $cnt = 2
78+
grep "^From " patch1 >from1 &&
79+
test_line_count = 2 from1
8080
'
8181

8282
test_expect_success "format-patch doesn't consider merge commits" '
@@ -90,22 +90,23 @@ test_expect_success "format-patch doesn't consider merge commits" '
9090
git checkout -b merger master &&
9191
test_tick &&
9292
git merge --no-ff slave &&
93-
cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) &&
94-
test $cnt = 3
93+
git format-patch -3 --stdout >patch &&
94+
grep "^From " patch >from &&
95+
test_line_count = 3 from
9596
'
9697

9798
test_expect_success 'format-patch result applies' '
9899
git checkout -b rebuild-0 master &&
99100
git am -3 patch0 &&
100-
cnt=$(git rev-list master.. | wc -l) &&
101-
test $cnt = 2
101+
git rev-list master.. >list &&
102+
test_line_count = 2 list
102103
'
103104

104105
test_expect_success 'format-patch --ignore-if-in-upstream result applies' '
105106
git checkout -b rebuild-1 master &&
106107
git am -3 patch1 &&
107-
cnt=$(git rev-list master.. | wc -l) &&
108-
test $cnt = 2
108+
git rev-list master.. >list &&
109+
test_line_count = 2 list
109110
'
110111

111112
test_expect_success 'commit did not screw up the log message' '
@@ -795,7 +796,8 @@ test_expect_success 'options no longer allowed for format-patch' '
795796

796797
test_expect_success 'format-patch --numstat should produce a patch' '
797798
git format-patch --numstat --stdout master..side >output &&
798-
test 5 = $(grep "^diff --git a/" output | wc -l)
799+
grep "^diff --git a/" output >diff &&
800+
test_line_count = 5 diff
799801
'
800802

801803
test_expect_success 'format-patch -- <path>' '
@@ -852,8 +854,8 @@ test_expect_success 'format-patch --signature --cover-letter' '
852854
git config --unset-all format.signature &&
853855
git format-patch --stdout --signature="my sig" --cover-letter \
854856
-1 >output &&
855-
grep "my sig" output &&
856-
test 2 = $(grep "my sig" output | wc -l)
857+
grep "my sig" output >sig &&
858+
test_line_count = 2 sig
857859
'
858860

859861
test_expect_success 'format.signature="" suppresses signatures' '
@@ -1591,7 +1593,8 @@ test_expect_success 'format-patch format.outputDirectory option' '
15911593
test_config format.outputDirectory patches &&
15921594
rm -fr patches &&
15931595
git format-patch master..side &&
1594-
test $(git rev-list master..side | wc -l) -eq $(ls patches | wc -l)
1596+
git rev-list master..side >list &&
1597+
test_line_count = $(ls patches | wc -l) list
15951598
'
15961599

15971600
test_expect_success 'format-patch -o overrides format.outputDirectory' '

0 commit comments

Comments
 (0)