mailmap tests: modernize syntax & test idioms

Refactor the mailmap tests to:

 * Setup "actual" test files in the body of "test_expect_success"

 * Don't have X of "test_expect_success X Y" be an unquoted string.

 * Not to carry over test config between tests, and instead use
   "test_config".

 * Replace various "echo" a line-at-a-time patterns with here-docs.

 * Change a case of "log.mailmap=False" to use the lower-case
   "false". Both work, but this ends up in git-config's boolean
   parsing and these atypical values are tested for elsewhere. Let's
   use the lower-case to not draw the reader's attention to this
   abnormality.

 * Remove commentary asserting that things work a given way in favor
   of simply testing for it, i.e. in the case of a .mailmap file
   outside of the repository.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2021-01-12 21:17:50 +01:00
committed by Junio C Hamano
parent 9aaeac9cf7
commit e9931ace4f

View File

@ -12,7 +12,7 @@ fuzz_blame () {
" "$@" " "$@"
} }
test_expect_success setup ' test_expect_success 'setup commits and contacts file' '
cat >contacts <<-EOF && cat >contacts <<-EOF &&
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
nick1 <bugs@company.xx> nick1 <bugs@company.xx>
@ -66,7 +66,8 @@ test_expect_success 'check-mailmap bogus contact' '
test_must_fail git check-mailmap bogus test_must_fail git check-mailmap bogus
' '
cat >expect << EOF test_expect_success 'No mailmap' '
cat >expect <<-EOF &&
$GIT_AUTHOR_NAME (1): $GIT_AUTHOR_NAME (1):
initial initial
@ -74,13 +75,21 @@ nick1 (1):
second second
EOF EOF
test_expect_success 'No mailmap' '
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect <<\EOF test_expect_success 'setup default .mailmap' '
cat >default.map <<-EOF
Repo Guy <$GIT_AUTHOR_EMAIL>
EOF
'
test_expect_success 'test default .mailmap' '
test_when_finished "rm .mailmap" &&
cp default.map .mailmap &&
cat >expect <<-\EOF &&
Repo Guy (1): Repo Guy (1):
initial initial
@ -88,16 +97,20 @@ nick1 (1):
second second
EOF EOF
test_expect_success 'default .mailmap' '
echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap &&
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
# Using a mailmap file in a subdirectory of the repo here, but test_expect_success 'mailmap.file set' '
# could just as well have been a file outside of the repository test_when_finished "rm .mailmap" &&
cat >expect <<\EOF cp default.map .mailmap &&
test_config mailmap.file internal.map &&
cat >internal.map <<-\EOF &&
Internal Guy <bugs@company.xx>
EOF
cat >expect <<-\EOF &&
Internal Guy (1): Internal Guy (1):
second second
@ -105,15 +118,30 @@ Repo Guy (1):
initial initial
EOF EOF
test_expect_success 'mailmap.file set' '
mkdir -p internal_mailmap &&
echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
git config mailmap.file internal_mailmap/.mailmap &&
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual &&
# The internal_mailmap/.mailmap file is an a subdirectory, but
# as shown here it can also be outside the repository
test_when_finished "rm -rf sub-repo" &&
git clone . sub-repo &&
(
cd sub-repo &&
cp ../.mailmap . &&
git config mailmap.file ../internal.map &&
git shortlog HEAD >actual &&
test_cmp ../expect actual
)
' '
cat >expect <<\EOF test_expect_success 'mailmap.file override' '
test_config mailmap.file internal.map &&
cat >internal.map <<-EOF &&
Internal Guy <bugs@company.xx>
External Guy <$GIT_AUTHOR_EMAIL>
EOF
cat >expect <<-\EOF &&
External Guy (1): External Guy (1):
initial initial
@ -121,14 +149,15 @@ Internal Guy (1):
second second
EOF EOF
test_expect_success 'mailmap.file override' '
echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap &&
git config mailmap.file internal_mailmap/.mailmap &&
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect <<\EOF test_expect_success 'mailmap.file non-existent' '
test_when_finished "rm .mailmap" &&
cp default.map .mailmap &&
cat >expect <<-\EOF &&
Repo Guy (1): Repo Guy (1):
initial initial
@ -136,32 +165,21 @@ nick1 (1):
second second
EOF EOF
test_expect_success 'mailmap.file non-existent' '
rm internal_mailmap/.mailmap &&
rmdir internal_mailmap &&
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect <<\EOF
Internal Guy (1):
second
Repo Guy (1):
initial
EOF
test_expect_success 'name entry after email entry' ' test_expect_success 'name entry after email entry' '
mkdir -p internal_mailmap && test_when_finished "rm .mailmap" &&
echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap && cp default.map .mailmap &&
echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
git shortlog HEAD >actual &&
test_cmp expect actual
'
cat >expect <<\EOF test_config mailmap.file internal.map &&
cat >internal.map <<-\EOF &&
<bugs@company.xy> <bugs@company.xx>
Internal Guy <bugs@company.xx>
EOF
cat >expect <<-\EOF &&
Internal Guy (1): Internal Guy (1):
second second
@ -170,15 +188,35 @@ Repo Guy (1):
EOF EOF
test_expect_success 'name entry after email entry, case-insensitive' '
mkdir -p internal_mailmap &&
echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect << EOF test_expect_success 'name entry after email entry, case-insensitive' '
test_when_finished "rm .mailmap" &&
cp default.map .mailmap &&
test_config mailmap.file internal.map &&
cat >internal.map <<-\EOF &&
<bugs@company.xy> <bugs@company.xx>
Internal Guy <BUGS@Company.xx>
EOF
cat >expect <<-\EOF &&
Internal Guy (1):
second
Repo Guy (1):
initial
EOF
git shortlog HEAD >actual &&
test_cmp expect actual
'
test_expect_success 'No mailmap files, but configured' '
cat >expect <<-EOF &&
$GIT_AUTHOR_NAME (1): $GIT_AUTHOR_NAME (1):
initial initial
@ -186,8 +224,6 @@ nick1 (1):
second second
EOF EOF
test_expect_success 'No mailmap files, but configured' '
rm -f .mailmap internal_mailmap/.mailmap &&
git shortlog HEAD >actual && git shortlog HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -205,11 +241,16 @@ test_expect_success 'setup mailmap blob tests' '
printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline && printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
git add just-bugs both no-newline && git add just-bugs both no-newline &&
git commit -m "my mailmaps" && git commit -m "my mailmaps" &&
echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap &&
echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map cat >internal.map <<-EOF
Internal Guy <$GIT_AUTHOR_EMAIL>
EOF
' '
test_expect_success 'mailmap.blob set' ' test_expect_success 'mailmap.blob set' '
test_when_finished "rm .mailmap" &&
cp default.map .mailmap &&
cat >expect <<-\EOF && cat >expect <<-\EOF &&
Blob Guy (1): Blob Guy (1):
second second
@ -223,6 +264,9 @@ test_expect_success 'mailmap.blob set' '
' '
test_expect_success 'mailmap.blob overrides .mailmap' ' test_expect_success 'mailmap.blob overrides .mailmap' '
test_when_finished "rm .mailmap" &&
cp default.map .mailmap &&
cat >expect <<-\EOF && cat >expect <<-\EOF &&
Blob Guy (2): Blob Guy (2):
initial initial
@ -250,6 +294,9 @@ test_expect_success 'mailmap.file overrides mailmap.blob' '
' '
test_expect_success 'mailmap.blob can be missing' ' test_expect_success 'mailmap.blob can be missing' '
test_when_finished "rm .mailmap" &&
cp default.map .mailmap &&
cat >expect <<-\EOF && cat >expect <<-\EOF &&
Repo Guy (1): Repo Guy (1):
initial initial
@ -267,11 +314,15 @@ test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
( (
cd non-bare && cd non-bare &&
test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" && test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
echo " 1 Fake Name" >expect && cat >expect <<-\EOF &&
1 Fake Name
EOF
git shortlog -ns HEAD >actual && git shortlog -ns HEAD >actual &&
test_cmp expect actual && test_cmp expect actual &&
rm .mailmap && rm .mailmap &&
echo " 1 $GIT_AUTHOR_NAME" >expect && cat >expect <<-EOF &&
1 $GIT_AUTHOR_NAME
EOF
git shortlog -ns HEAD >actual && git shortlog -ns HEAD >actual &&
test_cmp expect actual test_cmp expect actual
) )
@ -281,7 +332,9 @@ test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
git clone --bare non-bare bare && git clone --bare non-bare bare &&
( (
cd bare && cd bare &&
echo " 1 Fake Name" >expect && cat >expect <<-\EOF &&
1 Fake Name
EOF
git shortlog -ns HEAD >actual && git shortlog -ns HEAD >actual &&
test_cmp expect actual test_cmp expect actual
) )
@ -300,50 +353,46 @@ test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'cleanup after mailmap.blob tests' '
rm -f .mailmap
'
test_expect_success 'single-character name' ' test_expect_success 'single-character name' '
echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect &&
echo " 1 nick1 <bugs@company.xx>" >>expect &&
echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap &&
test_when_finished "rm .mailmap" && test_when_finished "rm .mailmap" &&
cat >.mailmap <<-EOF &&
A <$GIT_AUTHOR_EMAIL>
EOF
cat >expect <<-EOF &&
1 A <$GIT_AUTHOR_EMAIL>
1 nick1 <bugs@company.xx>
EOF
git shortlog -es HEAD >actual && git shortlog -es HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'preserve canonical email case' ' test_expect_success 'preserve canonical email case' '
echo " 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>" >expect &&
echo " 1 nick1 <bugs@company.xx>" >>expect &&
echo "<AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>" >.mailmap &&
test_when_finished "rm .mailmap" && test_when_finished "rm .mailmap" &&
cat >.mailmap <<-EOF &&
<AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>
EOF
cat >expect <<-EOF &&
1 $GIT_AUTHOR_NAME <AUTHOR@example.com>
1 nick1 <bugs@company.xx>
EOF
git shortlog -es HEAD >actual && git shortlog -es HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
# Extended mailmap configurations should give us the following output for shortlog test_expect_success 'Shortlog output (complex mapping)' '
cat >expect << EOF test_config mailmap.file complex.map &&
$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1): cat >complex.map <<-EOF &&
initial Committed <$GIT_COMMITTER_EMAIL>
<cto@company.xx> <cto@coompany.xx>
CTO <cto@company.xx> (1): Some Dude <some@dude.xx> nick1 <bugs@company.xx>
seventh Other Author <other@author.xx> nick2 <bugs@company.xx>
Other Author <other@author.xx> <nick2@company.xx>
Other Author <other@author.xx> (2): Santa Claus <santa.claus@northpole.xx> <me@company.xx>
third Santa Claus <santa.claus@northpole.xx> <me@company.xx>
fourth
Santa Claus <santa.claus@northpole.xx> (2):
fifth
sixth
Some Dude <some@dude.xx> (1):
second
EOF EOF
test_expect_success 'Shortlog output (complex mapping)' '
echo three >>one && echo three >>one &&
git add one && git add one &&
test_tick && test_tick &&
@ -369,22 +418,35 @@ test_expect_success 'Shortlog output (complex mapping)' '
test_tick && test_tick &&
git commit --author "CTO <cto@coompany.xx>" -m seventh && git commit --author "CTO <cto@coompany.xx>" -m seventh &&
mkdir -p internal_mailmap && cat >expect <<-EOF &&
echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap && $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap && initial
echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap && CTO <cto@company.xx> (1):
echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap && seventh
echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap && Other Author <other@author.xx> (2):
third
fourth
Santa Claus <santa.claus@northpole.xx> (2):
fifth
sixth
Some Dude <some@dude.xx> (1):
second
EOF
git shortlog -e HEAD >actual && git shortlog -e HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
# git log with --pretty format which uses the name and email mailmap placemarkers test_expect_success 'Log output (complex mapping)' '
cat >expect << EOF test_config mailmap.file complex.map &&
cat >expect <<-EOF &&
Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx> Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
@ -407,12 +469,12 @@ Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHO
Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL> Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
EOF EOF
test_expect_success 'Log output (complex mapping)' '
git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect << EOF test_expect_success 'Log output (local-part email address)' '
cat >expect <<-EOF &&
Author email cto@coompany.xx has local-part cto Author email cto@coompany.xx has local-part cto
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
@ -435,12 +497,14 @@ Author email author@example.com has local-part author
Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
EOF EOF
test_expect_success 'Log output (local-part email address)' '
git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual && git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect << EOF test_expect_success 'Log output with --use-mailmap' '
test_config mailmap.file complex.map &&
cat >expect <<-EOF &&
Author: CTO <cto@company.xx> Author: CTO <cto@company.xx>
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
@ -450,12 +514,14 @@ Author: Some Dude <some@dude.xx>
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
EOF EOF
test_expect_success 'Log output with --use-mailmap' '
git log --use-mailmap | grep Author >actual && git log --use-mailmap | grep Author >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect << EOF test_expect_success 'Log output with log.mailmap' '
test_config mailmap.file complex.map &&
cat >expect <<-EOF &&
Author: CTO <cto@company.xx> Author: CTO <cto@company.xx>
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
@ -465,7 +531,6 @@ Author: Some Dude <some@dude.xx>
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
EOF EOF
test_expect_success 'Log output with log.mailmap' '
git -c log.mailmap=True log | grep Author >actual && git -c log.mailmap=True log | grep Author >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -480,7 +545,7 @@ test_expect_success 'log.mailmap=false disables mailmap' '
Author: nick1 <bugs@company.xx> Author: nick1 <bugs@company.xx>
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
EOF EOF
git -c log.mailmap=False log | grep Author >actual && git -c log.mailmap=false log | grep Author >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -498,37 +563,45 @@ test_expect_success '--no-use-mailmap disables mailmap' '
test_cmp expect actual test_cmp expect actual
' '
cat >expect <<\EOF test_expect_success 'Grep author with --use-mailmap' '
test_config mailmap.file complex.map &&
cat >expect <<-\EOF &&
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
EOF EOF
test_expect_success 'Grep author with --use-mailmap' '
git log --use-mailmap --author Santa | grep Author >actual && git log --use-mailmap --author Santa | grep Author >actual &&
test_cmp expect actual test_cmp expect actual
' '
cat >expect <<\EOF
test_expect_success 'Grep author with log.mailmap' '
test_config mailmap.file complex.map &&
cat >expect <<-\EOF &&
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
Author: Santa Claus <santa.claus@northpole.xx> Author: Santa Claus <santa.claus@northpole.xx>
EOF EOF
test_expect_success 'Grep author with log.mailmap' '
git -c log.mailmap=True log --author Santa | grep Author >actual && git -c log.mailmap=True log --author Santa | grep Author >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'log.mailmap is true by default these days' ' test_expect_success 'log.mailmap is true by default these days' '
test_config mailmap.file complex.map &&
git log --author Santa | grep Author >actual && git log --author Santa | grep Author >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'Only grep replaced author with --use-mailmap' ' test_expect_success 'Only grep replaced author with --use-mailmap' '
test_config mailmap.file complex.map &&
git log --use-mailmap --author "<cto@coompany.xx>" >actual && git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
test_must_be_empty actual test_must_be_empty actual
' '
# git blame test_expect_success 'Blame output (complex mapping)' '
cat >expect <<EOF test_config mailmap.file complex.map &&
cat >expect <<-EOF &&
^OBJI ($GIT_AUTHOR_NAME DATE 1) one ^OBJI ($GIT_AUTHOR_NAME DATE 1) one
OBJID (Some Dude DATE 2) two OBJID (Some Dude DATE 2) two
OBJID (Other Author DATE 3) three OBJID (Other Author DATE 3) three
@ -537,17 +610,19 @@ OBJID (Santa Claus DATE 5) five
OBJID (Santa Claus DATE 6) six OBJID (Santa Claus DATE 6) six
OBJID (CTO DATE 7) seven OBJID (CTO DATE 7) seven
EOF EOF
test_expect_success 'Blame output (complex mapping)' '
git blame one >actual && git blame one >actual &&
fuzz_blame actual >actual.fuzz && fuzz_blame actual >actual.fuzz &&
test_cmp expect actual.fuzz test_cmp expect actual.fuzz
' '
cat >expect <<\EOF test_expect_success 'commit --author honors mailmap' '
test_config mailmap.file complex.map &&
cat >expect <<-\EOF &&
Some Dude <some@dude.xx> Some Dude <some@dude.xx>
EOF EOF
test_expect_success 'commit --author honors mailmap' '
test_must_fail git commit --author "nick" --allow-empty -meight && test_must_fail git commit --author "nick" --allow-empty -meight &&
git commit --author "Some Dude" --allow-empty -meight && git commit --author "Some Dude" --allow-empty -meight &&
git show --pretty=format:"%an <%ae>%n" >actual && git show --pretty=format:"%an <%ae>%n" >actual &&