Re: [PATCH v3 12/35] userdiff tests: change setup loop to individual test setup

2 messages, 2 authors, 2021-02-25 · open the first message on its own page

Re: [PATCH v3 12/35] userdiff tests: change setup loop to individual test setup

From: Junio C Hamano <hidden>
Date: 2021-02-25 02:53:27

Ævar Arnfjörð Bjarmason  [off-list ref] writes:
+# check each individual file
+for i in $(git -C t4018 ls-files)
+do
+	test_expect_success "setup hunk header: $i" "
+		grep -v '^t4018' \"t4018/$i\" >\"t4018/$i.content\" &&
+		sed -n -e 's/^t4018 header: //p' <\"t4018/$i\" >\"t4018/$i.header\" &&
+		cp \"t4018/$i.content\" \"$i\" &&
 
 		# add test file to the index
-		git add "$i" &&
+		git add \"$i\" &&
 		# place modified file in the worktree
-		sed -e "s/ChangeMe/IWasChanged/" <"t4018/$i.content" >"$i" || return 1
-	done
-'
+		sed -e 's/ChangeMe/IWasChanged/' <\"t4018/$i.content\" >\"$i\"
+	"
Please use '' around the second argument (i.e. test body) of the
test_expect_success, and use "" inside it.  "$i" that is used in the
loop is visible perfectly fine inside the test body when it is
eval'ed, and we won't have to count ugly backslashes that way.
 
-# check each individual file
-for i in $(git ls-files)
-do
 	test_expect_success "hunk header: $i" "
 		git diff -U1 $i >diff &&
 		sed -n -e 's/^.*@@$//p' -e 's/^.*@@ //p' <diff >ctx &&

Re: [PATCH v3 12/35] userdiff tests: change setup loop to individual test setup

From: Johannes Sixt <hidden>
Date: 2021-02-25 18:29:35

Am 25.02.21 um 03:52 schrieb Junio C Hamano:
Ævar Arnfjörð Bjarmason  [off-list ref] writes:
quoted
+# check each individual file
+for i in $(git -C t4018 ls-files)
+do
+	test_expect_success "setup hunk header: $i" "
+		grep -v '^t4018' \"t4018/$i\" >\"t4018/$i.content\" &&
+		sed -n -e 's/^t4018 header: //p' <\"t4018/$i\" >\"t4018/$i.header\" &&
+		cp \"t4018/$i.content\" \"$i\" &&
 
 		# add test file to the index
-		git add "$i" &&
+		git add \"$i\" &&
 		# place modified file in the worktree
-		sed -e "s/ChangeMe/IWasChanged/" <"t4018/$i.content" >"$i" || return 1
-	done
-'
+		sed -e 's/ChangeMe/IWasChanged/' <\"t4018/$i.content\" >\"$i\"
+	"
Please use '' around the second argument (i.e. test body) of the
test_expect_success, and use "" inside it.  "$i" that is used in the
loop is visible perfectly fine inside the test body when it is
eval'ed, and we won't have to count ugly backslashes that way.
If we do that, then we better be sure that the implementation of
test_expect_success does not clobber $i. Looks like we are OK at this time.

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help