[PATCH 3/4] shortlog tests: rewrite to get rid of --abbrev=35 hardcoding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rewrite much of the test logic introduced in 600372497c (shortlog:
Document and test --format option, 2010-05-03), this allows us to get
rid of the now-unused $_x35 variable in test-lib.sh

There was a minimal migration of this test to SHA-256 in
2ece6ad281 (t: switch $_x40 to $OID_REGEX, 2018-05-13), but actually
we can just get rid of all the assumptions about hashing here, and
make this easier to understand and maintain while we're at it.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
---
 t/t4201-shortlog.sh | 92 +++++++++++++++++++++++++--------------------
 t/test-lib.sh       |  5 +--
 2 files changed, 54 insertions(+), 43 deletions(-)

diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
index 3095b1b2ff..3ef17c06e4 100755
--- a/t/t4201-shortlog.sh
+++ b/t/t4201-shortlog.sh
@@ -19,82 +19,94 @@ test_expect_success 'setup' '
 	commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
 	git update-ref HEAD "$commit" &&
 
+	echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" >message &&
+
+	sed "s/i/1234/g" <message >tmp &&
+	tr 1234 "\360\235\204\236" <tmp >message.2 &&
+
+	sed "s/i/1234/g" <message >tmp &&
+	tr 1234 "\370\235\204\236" <tmp >message.3 &&
+
+	echo "a								12	34	56	78" >message.4 &&
+	echo "Commit by someone else" >message.5 &&
+
 	echo 2 >a1 &&
-	git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
+	git commit --quiet -F message a1 &&
 
 	# test if the wrapping is still valid
 	# when replacing all is by treble clefs.
 	echo 3 >a1 &&
-	git commit --quiet -m "$(
-		echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
-		sed "s/i/1234/g" |
-		tr 1234 "\360\235\204\236")" a1 &&
+	git commit --quiet -F message.2 a1 &&
 
 	# now fsck up the utf8
 	git config i18n.commitencoding non-utf-8 &&
 	echo 4 >a1 &&
-	git commit --quiet -m "$(
-		echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
-		sed "s/i/1234/g" |
-		tr 1234 "\370\235\204\236")" a1 &&
+	git commit --quiet -F message.3 a1 &&
 
 	echo 5 >a1 &&
-	git commit --quiet -m "a								12	34	56	78" a1 &&
+	git commit --quiet -F message.4 a1 &&
 
 	echo 6 >a1 &&
-	git commit --quiet -m "Commit by someone else" \
+	git commit --quiet -F message.5  \
 		--author="Someone else <not!me>" a1 &&
 
-	cat >expect.template <<-\EOF
+	cat >expect.default <<-EOF
 	A U Thor (5):
-	      SUBJECT
-	      SUBJECT
-	      SUBJECT
-	      SUBJECT
-	      SUBJECT
+	      Test
+	      $(cat message)
+	      $(cat message.2)
+	      $(cat message.3)
+	      $(cat message.4)
 
 	Someone else (1):
-	      SUBJECT
+	      $(cat message.5)
 
 	EOF
 '
 
-fuzz() {
-	file=$1 &&
-	sed "
-			s/$OID_REGEX/OBJECT_NAME/g
-			s/$_x35/OBJID/g
-			s/^ \{6\}[CTa].*/      SUBJECT/g
-			s/^ \{8\}[^ ].*/        CONTINUATION/g
-		" <"$file" >"$file.fuzzy" &&
-	sed "/CONTINUATION/ d" <"$file.fuzzy"
-}
-
 test_expect_success 'default output format' '
 	git shortlog HEAD >log &&
-	fuzz log >log.predictable &&
-	test_cmp expect.template log.predictable
+	test_cmp expect.default log
 '
 
 test_expect_success 'pretty format' '
-	sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
+	cat >expect <<-EOF &&
+	A U Thor (5):
+	      $(git rev-parse HEAD~5)
+	      $(git rev-parse HEAD~4)
+	      $(git rev-parse HEAD~3)
+	      $(git rev-parse HEAD~2)
+	      $(git rev-parse HEAD~1)
+
+	Someone else (1):
+	      $(git rev-parse HEAD~0)
+
+	EOF
 	git shortlog --format="%H" HEAD >log &&
-	fuzz log >log.predictable &&
-	test_cmp expect log.predictable
+	test_cmp expect log
 '
 
 test_expect_success '--abbrev' '
-	sed s/SUBJECT/OBJID/ expect.template >expect &&
+	cut -c 1-41 <expect >expect.abbrev &&
 	git shortlog --format="%h" --abbrev=35 HEAD >log &&
-	fuzz log >log.predictable &&
-	test_cmp expect log.predictable
+	test_cmp expect.abbrev log
 '
 
 test_expect_success 'output from user-defined format is re-wrapped' '
-	sed "s/SUBJECT/two lines/" expect.template >expect &&
+	cat >expect <<-EOF &&
+	A U Thor (5):
+	      two lines
+	      two lines
+	      two lines
+	      two lines
+	      two lines
+
+	Someone else (1):
+	      two lines
+
+	EOF
 	git shortlog --format="two%nlines" HEAD >log &&
-	fuzz log >log.predictable &&
-	test_cmp expect log.predictable
+	test_cmp expect log
 '
 
 test_expect_success !MINGW 'shortlog wrapping' '
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 5f2ad2fd81..4d5ba558d3 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -511,7 +511,7 @@ SQ=\'
 # when case-folding filenames
 u200c=$(printf '\342\200\214')
 
-export _x05 _x35 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX
+export _x05 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX
 
 # Each test should start with something like this, after copyright notices:
 #
@@ -1381,9 +1381,8 @@ then
 fi
 
 # Convenience
-# A regexp to match 5 and 35 hexdigits
+# A regexp to match 5 hexdigits
 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-_x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
 
 test_oid_init
 
-- 
2.31.0.rc1.213.gbfdb770ff55




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux