t4150 (am): style fix

Place setup commands in test_expect_success blocks.  This makes the
rare event of the setup commands breaking on some platform easier to
diagnose, and more importantly, it visually distinguishes where
each test begins and ends.

Instead of running test -z against the result of "git diff" command
substitution, use "git diff --exit-code", to improve output when
running with the "-v" option.

Use test_cmp in place of "test $(foo) = $(bar)" for similar reasons.

Remove whitespace after the > and < redirection operators for
consistency with other tests.

The order of arguments to test_cmp is "test_cmp expected actual".

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder
2010-07-23 12:03:07 -05:00
committed by Junio C Hamano
parent 64fdc08dac
commit 800f11040d
2 changed files with 124 additions and 96 deletions

View File

@ -4,66 +4,71 @@ test_description='git am running'
. ./test-lib.sh . ./test-lib.sh
cat >msg <<EOF test_expect_success 'setup: messages' '
second cat >msg <<-\EOF &&
second
Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. vero eos et accusam et justo duo dolores et ea rebum.
Duis autem vel eum iriure dolor in hendrerit in vulputate velit EOF
esse molestie consequat, vel illum dolore eu feugiat nulla facilisis q_to_tab <<-\EOF >>msg &&
at vero eros et accumsan et iusto odio dignissim qui blandit QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
praesent luptatum zzril delenit augue duis dolore te feugait nulla Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
facilisi. Qat vero eros et accumsan et iusto odio dignissim qui blandit
Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
Qfacilisi.
EOF
cat >>msg <<-\EOF &&
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, git
consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut ---
laoreet dolore magna aliquam erat volutpat. +++
git Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
--- lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
+++ dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi.
EOF
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit cat >failmail <<-\EOF &&
lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure From foo@example.com Fri May 23 10:43:49 2008
dolor in hendrerit in vulputate velit esse molestie consequat, vel illum From: foo@example.com
dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio To: bar@example.com
dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te Subject: Re: [RFC/PATCH] git-foo.sh
feugait nulla facilisi. Date: Fri, 23 May 2008 05:23:42 +0200
EOF
cat >failmail <<EOF Sometimes we have to find out that there'\''s nothing left.
From foo@example.com Fri May 23 10:43:49 2008
From: foo@example.com
To: bar@example.com
Subject: Re: [RFC/PATCH] git-foo.sh
Date: Fri, 23 May 2008 05:23:42 +0200
Sometimes we have to find out that there's nothing left. EOF
EOF cat >pine <<-\EOF &&
From MAILER-DAEMON Fri May 23 10:43:49 2008
Date: 23 May 2008 05:23:42 +0200
From: Mail System Internal Data <MAILER-DAEMON@example.com>
Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
Message-ID: <foo-0001@example.com>
cat >pine <<EOF This text is part of the internal format of your mail folder, and is not
From MAILER-DAEMON Fri May 23 10:43:49 2008 a real message. It is created automatically by the mail system software.
Date: 23 May 2008 05:23:42 +0200 If deleted, important folder data will be lost, and it will be re-created
From: Mail System Internal Data <MAILER-DAEMON@example.com> with the data reset to initial values.
Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
Message-ID: <foo-0001@example.com>
This text is part of the internal format of your mail folder, and is not EOF
a real message. It is created automatically by the mail system software.
If deleted, important folder data will be lost, and it will be re-created
with the data reset to initial values.
EOF signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
'
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected
test_expect_success setup ' test_expect_success setup '
echo hello >file && echo hello >file &&
@ -71,11 +76,13 @@ test_expect_success setup '
test_tick && test_tick &&
git commit -m first && git commit -m first &&
git tag first && git tag first &&
echo world >>file && echo world >>file &&
git add file && git add file &&
test_tick && test_tick &&
git commit -s -F msg && git commit -s -F msg &&
git tag second && git tag second &&
git format-patch --stdout first >patch1 && git format-patch --stdout first >patch1 &&
{ {
echo "X-Fake-Field: Line One" && echo "X-Fake-Field: Line One" &&
@ -89,33 +96,37 @@ test_expect_success setup '
echo "X-Fake-Field: Line Three" && echo "X-Fake-Field: Line Three" &&
git format-patch --stdout first | sed -e "1d" git format-patch --stdout first | sed -e "1d"
} | append_cr >patch1-crlf.eml && } | append_cr >patch1-crlf.eml &&
sed -n -e "3,\$p" msg >file && sed -n -e "3,\$p" msg >file &&
git add file && git add file &&
test_tick && test_tick &&
git commit -m third && git commit -m third &&
git format-patch --stdout first >patch2 && git format-patch --stdout first >patch2 &&
git checkout -b lorem && git checkout -b lorem &&
sed -n -e "11,\$p" msg >file && sed -n -e "11,\$p" msg >file &&
head -n 9 msg >>file && head -n 9 msg >>file &&
test_tick && test_tick &&
git commit -a -m "moved stuff" && git commit -a -m "moved stuff" &&
echo goodbye >another && echo goodbye >another &&
git add another && git add another &&
test_tick && test_tick &&
git commit -m "added another file" && git commit -m "added another file" &&
git format-patch --stdout master >lorem-move.patch
'
# reset time git format-patch --stdout master >lorem-move.patch &&
unset test_tick # reset time
test_tick unset test_tick &&
test_tick
'
test_expect_success 'am applies patch correctly' ' test_expect_success 'am applies patch correctly' '
git checkout first && git checkout first &&
test_tick && test_tick &&
git am <patch1 && git am <patch1 &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff second)" && git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
' '
@ -124,7 +135,7 @@ test_expect_success 'am applies patch e-mail not in a mbox' '
git checkout first && git checkout first &&
git am patch1.eml && git am patch1.eml &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff second)" && git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
' '
@ -133,20 +144,23 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
git checkout first && git checkout first &&
git am patch1-crlf.eml && git am patch1-crlf.eml &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff second)" && git diff --exit-code second &&
test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
' '
GIT_AUTHOR_NAME="Another Thor" test_expect_success 'setup: new author and committer' '
GIT_AUTHOR_EMAIL="a.thor@example.com" GIT_AUTHOR_NAME="Another Thor" &&
GIT_COMMITTER_NAME="Co M Miter" GIT_AUTHOR_EMAIL="a.thor@example.com" &&
GIT_COMMITTER_EMAIL="c.miter@example.com" GIT_COMMITTER_NAME="Co M Miter" &&
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_EMAIL="c.miter@example.com" &&
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
'
compare () { compare () {
test "$(git cat-file commit "$2" | grep "^$1 ")" = \ a=$(git cat-file commit "$2" | grep "^$1 ") &&
"$(git cat-file commit "$3" | grep "^$1 ")" b=$(git cat-file commit "$3" | grep "^$1 ") &&
test "$a" = "$b"
} }
test_expect_success 'am changes committer and keeps author' ' test_expect_success 'am changes committer and keeps author' '
@ -155,8 +169,8 @@ test_expect_success 'am changes committer and keeps author' '
git am patch2 && git am patch2 &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" && test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
test -z "$(git diff master..HEAD)" && git diff --exit-code master..HEAD &&
test -z "$(git diff master^..HEAD^)" && git diff --exit-code master^..HEAD^ &&
compare author master HEAD && compare author master HEAD &&
compare author master^ HEAD^ && compare author master^ HEAD^ &&
test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \ test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
@ -166,16 +180,19 @@ test_expect_success 'am changes committer and keeps author' '
test_expect_success 'am --signoff adds Signed-off-by: line' ' test_expect_success 'am --signoff adds Signed-off-by: line' '
git checkout -b master2 first && git checkout -b master2 first &&
git am --signoff <patch2 && git am --signoff <patch2 &&
printf "%s\n" "$signoff" >expected &&
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
git cat-file commit HEAD^ | grep "Signed-off-by:" >actual && git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
test_cmp actual expected && test_cmp expected actual &&
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected && echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
git cat-file commit HEAD | grep "Signed-off-by:" >actual && git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
test_cmp actual expected test_cmp expected actual
' '
test_expect_success 'am stays in branch' ' test_expect_success 'am stays in branch' '
test "refs/heads/master2" = "$(git symbolic-ref HEAD)" echo refs/heads/master2 >expected &&
git symbolic-ref HEAD >actual &&
test_cmp expected actual
' '
test_expect_success 'am --signoff does not add Signed-off-by: line if already there' ' test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
@ -183,19 +200,22 @@ test_expect_success 'am --signoff does not add Signed-off-by: line if already th
sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
git checkout HEAD^ && git checkout HEAD^ &&
git am --signoff patch4 && git am --signoff patch4 &&
test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1 git cat-file commit HEAD >actual &&
test $(grep -c "^Signed-off-by:" actual) -eq 1
' '
test_expect_success 'am without --keep removes Re: and [PATCH] stuff' ' test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
test "$(git rev-parse HEAD)" = "$(git rev-parse master2)" git rev-parse HEAD >expected &&
git rev-parse master2 >actual &&
test_cmp expected actual
' '
test_expect_success 'am --keep really keeps the subject' ' test_expect_success 'am --keep really keeps the subject' '
git checkout HEAD^ && git checkout HEAD^ &&
git am --keep patch4 && git am --keep patch4 &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
git cat-file commit HEAD | git cat-file commit HEAD >actual &&
fgrep "Re: Re: Re: [PATCH 1/5 v2] third" grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual
' '
test_expect_success 'am -3 falls back to 3-way merge' ' test_expect_success 'am -3 falls back to 3-way merge' '
@ -207,7 +227,7 @@ test_expect_success 'am -3 falls back to 3-way merge' '
git commit -m "copied stuff" && git commit -m "copied stuff" &&
git am -3 lorem-move.patch && git am -3 lorem-move.patch &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff lorem)" git diff --exit-code lorem
' '
test_expect_success 'am -3 -q is quiet' ' test_expect_success 'am -3 -q is quiet' '
@ -217,7 +237,7 @@ test_expect_success 'am -3 -q is quiet' '
git add file && git add file &&
test_tick && test_tick &&
git commit -m "copied stuff" && git commit -m "copied stuff" &&
git am -3 -q lorem-move.patch > output.out 2>&1 && git am -3 -q lorem-move.patch >output.out 2>&1 &&
! test -s output.out ! test -s output.out
' '
@ -228,13 +248,15 @@ test_expect_success 'am pauses on conflict' '
' '
test_expect_success 'am --skip works' ' test_expect_success 'am --skip works' '
echo goodbye >expected &&
git am --skip && git am --skip &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff lorem2^^ -- file)" && git diff --exit-code lorem2^^ -- file &&
test goodbye = "$(cat another)" test_cmp expected another
' '
test_expect_success 'am --resolved works' ' test_expect_success 'am --resolved works' '
echo goodbye >expected &&
git checkout lorem2^^ && git checkout lorem2^^ &&
test_must_fail git am lorem-move.patch && test_must_fail git am lorem-move.patch &&
test -d .git/rebase-apply && test -d .git/rebase-apply &&
@ -242,14 +264,14 @@ test_expect_success 'am --resolved works' '
git add file && git add file &&
git am --resolved && git am --resolved &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test goodbye = "$(cat another)" test_cmp expected another
' '
test_expect_success 'am takes patches from a Pine mailbox' ' test_expect_success 'am takes patches from a Pine mailbox' '
git checkout first && git checkout first &&
cat pine patch1 | git am && cat pine patch1 | git am &&
! test -d .git/rebase-apply && ! test -d .git/rebase-apply &&
test -z "$(git diff master^..HEAD)" git diff --exit-code master^..HEAD
' '
test_expect_success 'am fails on mail without patch' ' test_expect_success 'am fails on mail without patch' '
@ -272,7 +294,7 @@ test_expect_success 'am works from stdin in subdirectory' '
cd subdir && cd subdir &&
git am <../patch1 git am <../patch1
) && ) &&
test -z "$(git diff second)" git diff --exit-code second
' '
test_expect_success 'am works from file (relative path given) in subdirectory' ' test_expect_success 'am works from file (relative path given) in subdirectory' '
@ -283,7 +305,7 @@ test_expect_success 'am works from file (relative path given) in subdirectory' '
cd subdir && cd subdir &&
git am ../patch1 git am ../patch1
) && ) &&
test -z "$(git diff second)" git diff --exit-code second
' '
test_expect_success 'am works from file (absolute path given) in subdirectory' ' test_expect_success 'am works from file (absolute path given) in subdirectory' '
@ -295,7 +317,7 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
cd subdir && cd subdir &&
git am "$P/patch1" git am "$P/patch1"
) && ) &&
test -z "$(git diff second)" git diff --exit-code second
' '
test_expect_success 'am --committer-date-is-author-date' ' test_expect_success 'am --committer-date-is-author-date' '
@ -303,9 +325,9 @@ test_expect_success 'am --committer-date-is-author-date' '
test_tick && test_tick &&
git am --committer-date-is-author-date patch1 && git am --committer-date-is-author-date patch1 &&
git cat-file commit HEAD | sed -e "/^\$/q" >head1 && git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
at=$(sed -ne "/^author /s/.*> //p" head1) && sed -ne "/^author /s/.*> //p" head1 >at &&
ct=$(sed -ne "/^committer /s/.*> //p" head1) && sed -ne "/^committer /s/.*> //p" head1 >ct &&
test "$at" = "$ct" test_cmp at ct
' '
test_expect_success 'am without --committer-date-is-author-date' ' test_expect_success 'am without --committer-date-is-author-date' '
@ -313,9 +335,9 @@ test_expect_success 'am without --committer-date-is-author-date' '
test_tick && test_tick &&
git am patch1 && git am patch1 &&
git cat-file commit HEAD | sed -e "/^\$/q" >head1 && git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
at=$(sed -ne "/^author /s/.*> //p" head1) && sed -ne "/^author /s/.*> //p" head1 >at &&
ct=$(sed -ne "/^committer /s/.*> //p" head1) && sed -ne "/^committer /s/.*> //p" head1 >ct &&
test "$at" != "$ct" ! test_cmp at ct
' '
# This checks for +0000 because TZ is set to UTC and that should # This checks for +0000 because TZ is set to UTC and that should
@ -327,37 +349,39 @@ test_expect_success 'am --ignore-date' '
test_tick && test_tick &&
git am --ignore-date patch1 && git am --ignore-date patch1 &&
git cat-file commit HEAD | sed -e "/^\$/q" >head1 && git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
at=$(sed -ne "/^author /s/.*> //p" head1) && sed -ne "/^author /s/.*> //p" head1 >at &&
echo "$at" | grep "+0000" grep "+0000" at
' '
test_expect_success 'am into an unborn branch' ' test_expect_success 'am into an unborn branch' '
git rev-parse first^{tree} >expected &&
rm -fr subdir && rm -fr subdir &&
mkdir -p subdir && mkdir subdir &&
git format-patch --numbered-files -o subdir -1 first && git format-patch --numbered-files -o subdir -1 first &&
( (
cd subdir && cd subdir &&
git init && git init &&
git am 1 git am 1
) && ) &&
result=$( (
cd subdir && git rev-parse HEAD^{tree} cd subdir &&
git rev-parse HEAD^{tree} >../actual
) && ) &&
test "z$result" = "z$(git rev-parse first^{tree})" test_cmp expected actual
' '
test_expect_success 'am newline in subject' ' test_expect_success 'am newline in subject' '
git checkout first && git checkout first &&
test_tick && test_tick &&
sed -e "s/second/second \\\n foo/" patch1 > patchnl && sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
git am < patchnl > output.out 2>&1 && git am <patchnl >output.out 2>&1 &&
grep "^Applying: second \\\n foo$" output.out grep "^Applying: second \\\n foo$" output.out
' '
test_expect_success 'am -q is quiet' ' test_expect_success 'am -q is quiet' '
git checkout first && git checkout first &&
test_tick && test_tick &&
git am -q < patch1 > output.out 2>&1 && git am -q <patch1 >output.out 2>&1 &&
! test -s output.out ! test -s output.out
' '

View File

@ -257,6 +257,10 @@ q_to_cr () {
tr Q '\015' tr Q '\015'
} }
q_to_tab () {
tr Q '\011'
}
append_cr () { append_cr () {
sed -e 's/$/Q/' | tr Q '\015' sed -e 's/$/Q/' | tr Q '\015'
} }