Browse Source

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 <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Denton Liu 6 years ago committed by Junio C Hamano
parent
commit
6bd26f58ea
  1. 35
      t/t4014-format-patch.sh

35
t/t4014-format-patch.sh

@ -60,23 +60,23 @@ test_expect_success setup '


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


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


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


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


test_expect_success 'format-patch result applies' ' test_expect_success 'format-patch result applies' '
git checkout -b rebuild-0 master && git checkout -b rebuild-0 master &&
git am -3 patch0 && git am -3 patch0 &&
cnt=$(git rev-list master.. | wc -l) && git rev-list master.. >list &&
test $cnt = 2 test_line_count = 2 list
' '


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


test_expect_success 'commit did not screw up the log message' ' 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' '


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


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


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


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

Loading…
Cancel
Save