git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Eric Sunshine <ericsunshine@gmail.com>
Subject: [PATCH 15/19] tests: simplify by dropping unnecessary `for` loops
Date: Thu,  9 Dec 2021 00:11:11 -0500	[thread overview]
Message-ID: <20211209051115.52629-16-sunshine@sunshineco.com> (raw)
In-Reply-To: <20211209051115.52629-1-sunshine@sunshineco.com>

Rather than manually looping over a set of items and plugging those
items into a template string which is printed repeatedly, achieve the
same effect by taking advantage of `printf` which loops over its
arguments automatically.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/t3005-ls-files-relative.sh      | 10 ++--------
 t/t3600-rm.sh                     |  5 +----
 t/t4025-hunk-header.sh            | 10 ++--------
 t/t4125-apply-ws-fuzz.sh          |  5 +----
 t/t6416-recursive-corner-cases.sh | 30 ++++++------------------------
 t/t7110-reset-merge.sh            |  2 +-
 t/t9400-git-cvsserver-server.sh   |  2 +-
 7 files changed, 14 insertions(+), 50 deletions(-)

diff --git a/t/t3005-ls-files-relative.sh b/t/t3005-ls-files-relative.sh
index 6ba8b589cd..fbfa210a50 100755
--- a/t/t3005-ls-files-relative.sh
+++ b/t/t3005-ls-files-relative.sh
@@ -39,10 +39,7 @@ test_expect_success 'ls-files with mixed levels' '
 test_expect_success 'ls-files -c' '
 	(
 		cd top/sub &&
-		for f in ../y*
-		do
-			echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
-		done >expect.err &&
+		printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../y* >expect.err &&
 		echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
 		ls ../x* >expect.out &&
 		test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err &&
@@ -54,10 +51,7 @@ test_expect_success 'ls-files -c' '
 test_expect_success 'ls-files -o' '
 	(
 		cd top/sub &&
-		for f in ../x*
-		do
-			echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git"
-		done >expect.err &&
+		printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../x* >expect.err &&
 		echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err &&
 		ls ../y* >expect.out &&
 		test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err &&
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index ed3952eb98..e74a318ac3 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -274,10 +274,7 @@ test_expect_success 'Resolving by removal is not a warning-worthy event' '
 	git reset -q --hard &&
 	test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
 	blob=$(echo blob | git hash-object -w --stdin) &&
-	for stage in 1 2 3
-	do
-		echo "100644 $blob $stage	blob"
-	done | git update-index --index-info &&
+	printf "100644 $blob %d\tblob\n" 1 2 3 | git update-index --index-info &&
 	git rm blob >msg 2>&1 &&
 	test_i18ngrep ! "needs merge" msg &&
 	test_must_fail git ls-files -s --error-unmatch blob
diff --git a/t/t4025-hunk-header.sh b/t/t4025-hunk-header.sh
index 6356961de4..5397cb7d42 100755
--- a/t/t4025-hunk-header.sh
+++ b/t/t4025-hunk-header.sh
@@ -14,15 +14,9 @@ test_expect_success setup '
 
 	(
 		echo "A $NS" &&
-		for c in B C D E F G H I J K
-		do
-			echo "  $c"
-		done &&
+		printf "  %s\n" B C D E F G H I J K &&
 		echo "L  $NS" &&
-		for c in M N O P Q R S T U V
-		do
-			echo "  $c"
-		done
+		printf "  %s\n" M N O P Q R S T U V
 	) >file &&
 	git add file &&
 
diff --git a/t/t4125-apply-ws-fuzz.sh b/t/t4125-apply-ws-fuzz.sh
index 9671de7999..090987c89b 100755
--- a/t/t4125-apply-ws-fuzz.sh
+++ b/t/t4125-apply-ws-fuzz.sh
@@ -10,10 +10,7 @@ test_expect_success setup '
 	git add file &&
 
 	# file-0 is full of whitespace breakages
-	for l in a bb c d eeee f ggg h
-	do
-		echo "$l "
-	done >file-0 &&
+	printf "%s \n" a bb c d eeee f ggg h >file-0 &&
 
 	# patch-0 creates a whitespace broken file
 	cat file-0 >file &&
diff --git a/t/t6416-recursive-corner-cases.sh b/t/t6416-recursive-corner-cases.sh
index 84f5082366..690c8482b1 100755
--- a/t/t6416-recursive-corner-cases.sh
+++ b/t/t6416-recursive-corner-cases.sh
@@ -24,14 +24,8 @@ test_expect_success 'setup basic criss-cross + rename with no modifications' '
 		cd basic-rename &&
 
 		ten="0 1 2 3 4 5 6 7 8 9" &&
-		for i in $ten
-		do
-			echo line $i in a sample file
-		done >one &&
-		for i in $ten
-		do
-			echo line $i in another sample file
-		done >two &&
+		printf "line %d in a sample file\n" $ten >one &&
+		printf "line %d in another sample file\n" $ten >two &&
 		git add one two &&
 		test_tick && git commit -m initial &&
 
@@ -96,14 +90,8 @@ test_expect_success 'setup criss-cross + rename merges with basic modification'
 		cd rename-modify &&
 
 		ten="0 1 2 3 4 5 6 7 8 9" &&
-		for i in $ten
-		do
-			echo line $i in a sample file
-		done >one &&
-		for i in $ten
-		do
-			echo line $i in another sample file
-		done >two &&
+		printf "line %d in a sample file\n" $ten >one &&
+		printf "line %d in another sample file\n" $ten >two &&
 		git add one two &&
 		test_tick && git commit -m initial &&
 
@@ -1588,10 +1576,7 @@ test_expect_success 'setup nested conflicts' '
 		cd nested_conflicts &&
 
 		# Create some related files now
-		for i in $(test_seq 1 10)
-		do
-			echo Random base content line $i
-		done >initial &&
+		printf "Random base content line %d\n" $(test_seq 1 10) >initial &&
 
 		cp initial b_L1 &&
 		cp initial b_R1 &&
@@ -1777,10 +1762,7 @@ test_expect_success 'setup virtual merge base with nested conflicts' '
 		cd virtual_merge_base_has_nested_conflicts &&
 
 		# Create some related files now
-		for i in $(test_seq 1 10)
-		do
-			echo Random base content line $i
-		done >content &&
+		printf "Random base content line %d\n" $(test_seq 1 10) >content &&
 
 		# Setup original commit
 		git add content &&
diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh
index a82a07a04a..3d62e10b53 100755
--- a/t/t7110-reset-merge.sh
+++ b/t/t7110-reset-merge.sh
@@ -8,7 +8,7 @@ test_description='Tests for "git reset" with "--merge" and "--keep" options'
 . ./test-lib.sh
 
 test_expect_success setup '
-    for i in 1 2 3; do echo line $i; done >file1 &&
+    printf "line %d\n" 1 2 3 >file1 &&
     cat file1 >file2 &&
     git add file1 file2 &&
     test_tick &&
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index a6a73effde..a60fe2e19f 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -591,7 +591,7 @@ test_expect_success 'cvs annotate' '
     cd cvswork &&
     GIT_CONFIG="$git_config" cvs annotate merge >../out &&
     sed -e "s/ .*//" ../out >../actual &&
-    for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
+    printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect &&
     test_cmp ../expect ../actual
 '
 
-- 
2.34.1.307.g9b7440fafd


  parent reply	other threads:[~2021-12-09  5:12 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-09  5:10 [PATCH 00/19] tests: fix broken &&-chains & abort loops on error Eric Sunshine
2021-12-09  5:10 ` [PATCH 01/19] t/lib-pager: use sane_unset() to avoid breaking &&-chain Eric Sunshine
2021-12-09  5:10 ` [PATCH 02/19] t1010: fix unnoticed failure on Windows Eric Sunshine
2021-12-09 16:27   ` Elijah Newren
2021-12-09 16:45     ` Eric Sunshine
2021-12-09  5:10 ` [PATCH 03/19] t1020: avoid aborting entire test script when one test fails Eric Sunshine
2021-12-09  5:11 ` [PATCH 04/19] t4202: clarify intent by creating expected content less cleverly Eric Sunshine
2021-12-10  9:09   ` Jeff King
2021-12-09  5:11 ` [PATCH 05/19] t5516: drop unnecessary subshell and command invocation Eric Sunshine
2021-12-10  9:10   ` Jeff King
2021-12-09  5:11 ` [PATCH 06/19] t6300: make `%(raw:size) --shell` test more robust Eric Sunshine
2021-12-10  9:14   ` Jeff King
2021-12-09  5:11 ` [PATCH 07/19] t9107: use shell parameter expansion to avoid breaking &&-chain Eric Sunshine
2021-12-09  5:11 ` [PATCH 08/19] tests: simplify construction of large blocks of text Eric Sunshine
2021-12-09  5:11 ` [PATCH 09/19] tests: use test_write_lines() to generate line-oriented output Eric Sunshine
2021-12-10  9:22   ` Jeff King
2021-12-11  6:59     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 10/19] tests: fix broken &&-chains in compound statements Eric Sunshine
2021-12-09  5:11 ` [PATCH 11/19] tests: fix broken &&-chains in `$(...)` command substitutions Eric Sunshine
2021-12-09 16:44   ` Elijah Newren
2021-12-09 16:53     ` Eric Sunshine
2021-12-09 16:57       ` Elijah Newren
2021-12-10  9:27       ` Jeff King
2021-12-09  5:11 ` [PATCH 12/19] tests: fix broken &&-chains in `{...}` groups Eric Sunshine
2021-12-10  9:29   ` Jeff King
2021-12-11  7:14     ` Eric Sunshine
2021-12-10  9:38   ` Fabian Stelzer
2021-12-11  7:32     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 13/19] tests: apply modern idiom for signaling test failure Eric Sunshine
2021-12-10  9:32   ` Jeff King
2021-12-11  7:47     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 14/19] tests: apply modern idiom for exiting loop upon failure Eric Sunshine
2021-12-10  9:36   ` Jeff King
2021-12-09  5:11 ` Eric Sunshine [this message]
2021-12-09 16:50   ` [PATCH 15/19] tests: simplify by dropping unnecessary `for` loops Elijah Newren
2021-12-09  5:11 ` [PATCH 16/19] t0000-t3999: detect and signal failure within loop Eric Sunshine
2021-12-09  5:11 ` [PATCH 17/19] t4000-t4999: " Eric Sunshine
2021-12-10  9:53   ` Fabian Stelzer
2021-12-11  8:06     ` Eric Sunshine
2021-12-09  5:11 ` [PATCH 18/19] t5000-t5999: " Eric Sunshine
2021-12-09  5:11 ` [PATCH 19/19] t6000-t9999: " Eric Sunshine
2021-12-09 17:02 ` [PATCH 00/19] tests: fix broken &&-chains & abort loops on error Elijah Newren
2021-12-09 19:17   ` Eric Sunshine
2021-12-10  9:38     ` Jeff King
2021-12-10  9:57       ` Fabian Stelzer
2021-12-11  8:16         ` Eric Sunshine
2021-12-11  9:58 ` [PATCH v1.1 2/19] t1010: fix unnoticed failure on Windows Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211209051115.52629-16-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=ericsunshine@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).