diff mbox series

[10/22] mailmap tests: get rid of overly complex blame fuzzing

Message ID 20210112201806.13284-11-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series shortlog: remove unused(?) "repo-abbrev" feature | expand

Commit Message

Ævar Arnfjörð Bjarmason Jan. 12, 2021, 8:17 p.m. UTC
Change a test that used a custom fuzzing function since
bfdfa3d414 (t4203 (mailmap): stop hardcoding commit ids and dates,
2010-10-15) to just use the "blame --porcelain" output instead.

We could use the same pattern as 0ba9c9a0fb (t8008: rely on
rev-parse'd HEAD instead of sha1 value, 2017-07-26) does to do this,
but there wouldn't be any point. We're not trying to test "blame"
output here in general, just that "blame" pays attention to the
mailmap.

So it's sufficient to get the blamed line(s) and authors from the
output, which is much easier with the "--porcelain" option.

It would still be possible for there to be a bug in "blame" such that
it uses the mailmap for its "--porcelain" output, but not the regular
output. Let's test for that simply by checking if specifying the
mailmap changes the output.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t4203-mailmap.sh | 50 +++++++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

Comments

Junio C Hamano Jan. 12, 2021, 10:34 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> +	6 6 1
> +	Santa Claus
> +	7 7 1
> +	CTO
> +	EOF
> +
> +	git blame --porcelain one >actual.blame &&
> +	grep -E \
> +		-e "[0-9]+ [0-9]+ [0-9]+$" \
> +		-e "^author .*$" \
> +		actual.blame >actual.grep &&
> +	cut -d " " -f2-4 <actual.grep >actual.fuzz &&

An approach along the lines of ...

	NUM="[0-9][0-9]*"
	sed -n -e "s/^author //p" \
	-e "s/^$OID_REGEX \($NUM $NUM $NUM\)$/\1/p"

... would allow you to drop "cut" and also not assume that names do
not have more than 3 tokens.
Junio C Hamano Jan. 14, 2021, 8:21 p.m. UTC | #2
Junio C Hamano <gitster@pobox.com> writes:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> +	6 6 1
>> +	Santa Claus
>> +	7 7 1
>> +	CTO
>> +	EOF
>> +
>> +	git blame --porcelain one >actual.blame &&
>> +	grep -E \
>> +		-e "[0-9]+ [0-9]+ [0-9]+$" \
>> +		-e "^author .*$" \
>> +		actual.blame >actual.grep &&
>> +	cut -d " " -f2-4 <actual.grep >actual.fuzz &&
>
> An approach along the lines of ...
>
> 	NUM="[0-9][0-9]*"
> 	sed -n -e "s/^author //p" \
> 	-e "s/^$OID_REGEX \($NUM $NUM $NUM\)$/\1/p"
>
> ... would allow you to drop "cut" and also not assume that names do
> not have more than 3 tokens.

Trying to lead by example..., here is the suggestion in a follow-up
patch form that can be applied on top of the series.

----- >8 ----- ----- >8 ----- ----- >8 ----- ----- >8 ----- ----- >8 -----
Subject: [PATCH] t4203: make blame output massaging more robust

In the "git blame --porcelain" output, lines that ends with three
integers may not be the line that shows a commit object with line
numbers and block length (the contents from the blamed file or the
summary field can have a line that happens to match).  Also, the
names of the author may have more than three SP separated tokens
("git blame -L242,+1 cf6de18aabf7 Documentation/SubmittingPatches"
gives an example).  The existing "grep -E | cut" pipeline is a bit
too loose on these two points.

While they can be assumed on the test data, it is not so hard to
use the right pattern from the documented format, so let's do so.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t4203-mailmap.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git c/t/t4203-mailmap.sh i/t/t4203-mailmap.sh
index 89cb300f28..d4a6e73736 100755
--- c/t/t4203-mailmap.sh
+++ i/t/t4203-mailmap.sh
@@ -739,11 +739,11 @@ test_expect_success 'Blame --porcelain output (complex mapping)' '
 	EOF
 
 	git blame --porcelain one >actual.blame &&
-	grep -E \
-		-e "[0-9]+ [0-9]+ [0-9]+$" \
-		-e "^author .*$" \
-		actual.blame >actual.grep &&
-	cut -d " " -f2-4 <actual.grep >actual.fuzz &&
+
+	NUM="[0-9][0-9]*" &&
+	sed -n <actual.blame >actual.fuzz \
+		-e "s/^author //p" \
+		-e "s/^$OID_REGEX \\($NUM $NUM $NUM\\)$/\\1/p"  &&
 	test_cmp expect actual.fuzz
 '
diff mbox series

Patch

diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh
index 78d56e0566..a42b454756 100755
--- a/t/t4203-mailmap.sh
+++ b/t/t4203-mailmap.sh
@@ -4,14 +4,6 @@  test_description='.mailmap configurations'
 
 . ./test-lib.sh
 
-fuzz_blame () {
-	sed "
-		s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g
-		s/$_x05[0-9a-f][0-9a-f]/OBJI/g
-		s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
-	" "$@"
-}
-
 test_expect_success 'setup commits and contacts file' '
 	echo one >one &&
 	git add one &&
@@ -630,24 +622,42 @@  test_expect_success 'Only grep replaced author with --use-mailmap' '
 	test_must_be_empty actual
 '
 
-test_expect_success 'Blame output (complex mapping)' '
+test_expect_success 'Blame --porcelain output (complex mapping)' '
 	test_config mailmap.file complex.map &&
 
 	cat >expect <<-EOF &&
-	^OBJI ($GIT_AUTHOR_NAME     DATE 1) one
-	OBJID (Some Dude    DATE 2) two
-	OBJID (Other Author DATE 3) three
-	OBJID (Other Author DATE 4) four
-	OBJID (Santa Claus  DATE 5) five
-	OBJID (Santa Claus  DATE 6) six
-	OBJID (CTO          DATE 7) seven
-	EOF
-
-	git blame one >actual &&
-	fuzz_blame actual >actual.fuzz &&
+	1 1 1
+	A U Thor
+	2 2 1
+	Some Dude
+	3 3 1
+	Other Author
+	4 4 1
+	Other Author
+	5 5 1
+	Santa Claus
+	6 6 1
+	Santa Claus
+	7 7 1
+	CTO
+	EOF
+
+	git blame --porcelain one >actual.blame &&
+	grep -E \
+		-e "[0-9]+ [0-9]+ [0-9]+$" \
+		-e "^author .*$" \
+		actual.blame >actual.grep &&
+	cut -d " " -f2-4 <actual.grep >actual.fuzz &&
 	test_cmp expect actual.fuzz
 '
 
+test_expect_success 'Blame output (complex mapping)' '
+	git -c mailmap.file=complex.map blame one >a &&
+	git blame one >b &&
+	test_file_not_empty a &&
+	! cmp a b
+'
+
 test_expect_success 'commit --author honors mailmap' '
 	test_config mailmap.file complex.map &&