t4104: modernize and simplify quoting

Drop whitespace in the value of `$test_description` and in a test body
and use `test_write_lines`.

Stop defining `$u` with a trailing space just so that we can tuck it in
like `git foo $u$more...` and get minimal whitespace in the command:
`git foo $u $more...` is more readable at the "cost" of an empty `$u`
yielding `git foo  something...`.

Finally, avoid using single quotes within the test scripts to repeatedly
close and reopen the quotes that wrap the test scripts (see the previous
commit). This "unnecessary" quoting does mean that the verbose test
output shows the interpolated values, i.e., the shell code we're
running. But the downside is that the source of the script does *not*
show the shell code we're eventually executing, leaving the reader to
reason about what we really do and whether there are any quoting issues.
(There aren't.)

Where we run through loops to generate several "identical but different"
tests, the test message contains the interpolated variables we're
looping on, meaning one can always identify exactly which instance has
failed, even if the verbose test output shows the exact same test body
several times.

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Martin Ågren 2020-08-06 22:08:54 +02:00 committed by Junio C Hamano
parent c76b84a121
commit 289218de2b
1 changed files with 15 additions and 42 deletions

View File

@ -3,80 +3,55 @@
# Copyright (c) 2005 Junio C Hamano # Copyright (c) 2005 Junio C Hamano
# #


test_description='git apply boundary tests test_description='git apply boundary tests'


'
. ./test-lib.sh . ./test-lib.sh


L="c d e f g h i j k l m n o p q r s t u v w x" L="c d e f g h i j k l m n o p q r s t u v w x"


test_expect_success setup ' test_expect_success setup '
for i in b '"$L"' y test_write_lines b $L y >victim &&
do
echo $i
done >victim &&
cat victim >original && cat victim >original &&
git update-index --add victim && git update-index --add victim &&


# add to the head # add to the head
for i in a b '"$L"' y test_write_lines a b $L y >victim &&
do
echo $i
done >victim &&
cat victim >add-a-expect && cat victim >add-a-expect &&
git diff victim >add-a-patch.with && git diff victim >add-a-patch.with &&
git diff --unified=0 >add-a-patch.without && git diff --unified=0 >add-a-patch.without &&


# insert at line two # insert at line two
for i in b a '"$L"' y test_write_lines b a $L y >victim &&
do
echo $i
done >victim &&
cat victim >insert-a-expect && cat victim >insert-a-expect &&
git diff victim >insert-a-patch.with && git diff victim >insert-a-patch.with &&
git diff --unified=0 >insert-a-patch.without && git diff --unified=0 >insert-a-patch.without &&


# modify at the head # modify at the head
for i in a '"$L"' y test_write_lines a $L y >victim &&
do
echo $i
done >victim &&
cat victim >mod-a-expect && cat victim >mod-a-expect &&
git diff victim >mod-a-patch.with && git diff victim >mod-a-patch.with &&
git diff --unified=0 >mod-a-patch.without && git diff --unified=0 >mod-a-patch.without &&


# remove from the head # remove from the head
for i in '"$L"' y test_write_lines $L y >victim &&
do
echo $i
done >victim &&
cat victim >del-a-expect && cat victim >del-a-expect &&
git diff victim >del-a-patch.with && git diff victim >del-a-patch.with &&
git diff --unified=0 >del-a-patch.without && git diff --unified=0 >del-a-patch.without &&


# add to the tail # add to the tail
for i in b '"$L"' y z test_write_lines b $L y z >victim &&
do
echo $i
done >victim &&
cat victim >add-z-expect && cat victim >add-z-expect &&
git diff victim >add-z-patch.with && git diff victim >add-z-patch.with &&
git diff --unified=0 >add-z-patch.without && git diff --unified=0 >add-z-patch.without &&


# modify at the tail # modify at the tail
for i in b '"$L"' z test_write_lines b $L z >victim &&
do
echo $i
done >victim &&
cat victim >mod-z-expect && cat victim >mod-z-expect &&
git diff victim >mod-z-patch.with && git diff victim >mod-z-patch.with &&
git diff --unified=0 >mod-z-patch.without && git diff --unified=0 >mod-z-patch.without &&


# remove from the tail # remove from the tail
for i in b '"$L"' test_write_lines b $L >victim &&
do
echo $i
done >victim &&
cat victim >del-z-expect && cat victim >del-z-expect &&
git diff victim >del-z-patch.with && git diff victim >del-z-patch.with &&
git diff --unified=0 >del-z-patch.without git diff --unified=0 >del-z-patch.without
@ -88,15 +63,15 @@ for with in with without
do do
case "$with" in case "$with" in
with) u= ;; with) u= ;;
without) u='--unidiff-zero ' ;; without) u=--unidiff-zero ;;
esac esac
for kind in add-a add-z insert-a mod-a mod-z del-a del-z for kind in add-a add-z insert-a mod-a mod-z del-a del-z
do do
test_expect_success "apply $kind-patch $with context" ' test_expect_success "apply $kind-patch $with context" '
cat original >victim && cat original >victim &&
git update-index victim && git update-index victim &&
git apply --index '"$u$kind-patch.$with"' && git apply --index $u "$kind-patch.$with" &&
test_cmp '"$kind"'-expect victim test_cmp "$kind-expect" victim
' '
done done
done done
@ -110,13 +85,12 @@ do
test_expect_success "apply non-git $kind-patch without context" ' test_expect_success "apply non-git $kind-patch without context" '
cat original >victim && cat original >victim &&
git update-index victim && git update-index victim &&
git apply --unidiff-zero --index '"$kind-ng.without"' && git apply --unidiff-zero --index "$kind-ng.without" &&
test_cmp '"$kind"'-expect victim test_cmp "$kind-expect" victim
' '
done done


test_expect_success 'two lines' ' test_expect_success 'two lines' '

>file && >file &&
git add file && git add file &&
echo aaa >file && echo aaa >file &&
@ -125,11 +99,10 @@ test_expect_success 'two lines' '
echo bbb >file && echo bbb >file &&
git add file && git add file &&
test_must_fail git apply --check patch test_must_fail git apply --check patch

' '


test_expect_success 'apply patch with 3 context lines matching at end' ' test_expect_success 'apply patch with 3 context lines matching at end' '
{ echo a; echo b; echo c; echo d; } >file && test_write_lines a b c d >file &&
git add file && git add file &&
echo e >>file && echo e >>file &&
git diff >patch && git diff >patch &&