git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v10 3/5] t4205, t6006, t7102: make functions better readable

From
Alexey Shumkin <alex.crezoff@gmail.com>
Date
Jul 5, 2013, 12:01 UTC
Message-ID
<77116508da1bf88e6035cbd657c401cf96b08cbb.1373024281.git.Alex.Crezoff@gmail.com>
In-Reply-To
<cover.1373024281.git.Alex.Crezoff@gmail.com>

Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end.

Note, current code does not use this last parameter as far as there are no tests expected to fail. We can keep that for future use.

Also, reformat comments
Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com>
Improved-by: Johannes Sixt <j.sixt@viscovery.net>
---
 t/t4205-log-pretty-formats.sh |  3 ++-
 t/t6006-rev-list-format.sh    | 28 ++++++++--------------------
 t/t7102-reset.sh              | 10 ++++++----
 3 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index ef9770a..2933c63 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -8,7 +8,8 @@ test_description='Test pretty formats'
 . ./test-lib.sh
 
 commit_msg () {
-	# String "initial. initial" partly in German (translated with Google Translate),
+	# String "initial. initial" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
 	msg=$(printf "initial. anf\303\244nglich")
 	if test -n "$1"
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 4751d22..b32405a 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -9,8 +9,9 @@ test_description='git rev-list --pretty=format test'
 . "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_tick
-# String "added" in German (translated with Google Translate), encoded in UTF-8,
-# used as a commit log message below.
+# String "added" in German
+# (translated with Google Translate),
+# encoded in UTF-8, used as a commit log message below.
 added=$(printf "added (hinzugef\303\274gt) foo")
 added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1)
 # same but "changed"
@@ -35,26 +36,13 @@ test_expect_success 'setup' '
 	git config --unset i18n.commitEncoding
 '
 
-# usage: test_format [failure] name format_string <expected_output
+# usage: test_format name format_string [failure] <expected_output
 test_format () {
-	must_fail=0
-	# if parameters count is more than 2 then test must fail
-	if test $# -gt 2
-	then
-		must_fail=1
-		# remove first parameter which is flag for test failure
-		shift
-	fi
 	cat >expect.$1
-	name="format $1"
-	command="git rev-list --pretty=format:'$2' master >output.$1 &&
-		test_cmp expect.$1 output.$1"
-	if test $must_fail -eq 1
-	then
-		test_expect_failure "$name" "$command"
-	else
-		test_expect_success "$name" "$command"
-	fi
+	test_expect_${3:-success} "format $1" "
+		git rev-list --pretty=format:'$2' master >output.$1 &&
+		test_cmp expect.$1 output.$1
+	"
 }
 
 # Feed to --format to provide predictable colored sequences.
diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 2ef96e9..535e609 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -10,14 +10,16 @@ Documented tests for git reset'
 . ./test-lib.sh
 
 commit_msg () {
-	# String "modify 2nd file (changed)" partly in German(translated with Google Translate),
+	# String "modify 2nd file (changed)" partly in German
+	# (translated with Google Translate),
 	# encoded in UTF-8, used as a commit log message below.
-	msg=$(printf "modify 2nd file (ge\303\244ndert)")
+	msg="modify 2nd file (ge\303\244ndert)"
 	if test -n "$1"
 	then
-		msg=$(echo $msg | iconv -f utf-8 -t $1)
+		print "$msg" | iconv -f utf-8 -t "$1"
+	else
+		print "$msg"
 	fi
-	echo $msg
 }
 
 test_expect_success 'creating initial files and commits' '
-- 
1.8.3.2.16.gb1f0d63
Previous: Alexey ShumkinNext: Junio C Hamano
Message 4 of 8 in “Incremental updates against 'next' branch”
  1. 0/5 Incremental updates against 'next' branchAlexey Shumkin, Jul 5, 2013
  2. 1/5 t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1Alexey Shumkin, Jul 5, 2013
  3. 2/5 t4205 (log-pretty-formats): revert back single quotesAlexey Shumkin, Jul 5, 2013
  4. 3/5 t4205, t6006, t7102: make functions better readableAlexey Shumkin, Jul 5, 2013
  5. Junio C HamanoJul 5, 2013
  6. Junio C HamanoJul 5, 2013
  7. 4/5 t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not setAlexey Shumkin, Jul 5, 2013
  8. 5/5 t4205 (log-pretty-formats): avoid using `sed`Alexey Shumkin, Jul 5, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.