Thread (1 message) 1 message, 1 author, 2021-02-25

Re: [PATCH v3 11/35] userdiff tests: match full hunk headers

From: Junio C Hamano <hidden>
Date: 2021-02-25 02:48:10

Ævar Arnfjörð Bjarmason  [off-list ref] writes:
quoted hunk
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
index 9aec9f8e6de..15dcbe735ca 100755
--- a/t/t4018-diff-funcname.sh
+++ b/t/t4018-diff-funcname.sh
@@ -70,16 +70,20 @@ test_expect_success 'setup hunk header tests' '
 		echo "$i-* diff=$i"
 	done > .gitattributes &&
 
-	# add all test files to the index
-	(
-		cd "$TEST_DIRECTORY"/t4018 &&
-		git --git-dir="$TRASH_DIRECTORY/.git" add .
-	) &&
-
-	# place modified files in the worktree
-	for i in $(git ls-files)
+	cp -R "$TEST_DIRECTORY"/t4018 . &&
Is this because otherwise we'll mix leftover cruft in the source
directory?  I guess this is OK as it is just once per t4018 test
run.
quoted hunk
+	git init t4018 &&
+	git -C t4018 add . &&
+
+	for i in $(git -C t4018 ls-files)
 	do
-		sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
+		grep -v "^t4018" "t4018/$i" >"t4018/$i.content" &&
+		sed -n -e "s/^t4018 header: //p" <"t4018/$i" >"t4018/$i.header" &&
For now this would do, but I am assuming that the "t4018" prefix
(which by the way is a way to make it harder to renumber these
tests) was invented so that we can add more magic than just
"header:" in the futhre (either in this series or later).  I am not
sure if we want to run one invocation of "sed" for each new magic we
invent---perhaps the plan is that we'd keep the framework simple for
now (while we have only one "magic") and then revamp it when we gain
the second one, in which case I am perfectly fine with it.
quoted hunk
+		cp "t4018/$i.content" "$i" &&
+
+		# add test file to the index
+		git add "$i" &&
+		# place modified file in the worktree
+		sed -e "s/ChangeMe/IWasChanged/" <"t4018/$i.content" >"$i" || return 1
OK.
quoted hunk
 	done
 '
 
@@ -87,8 +91,9 @@ test_expect_success 'setup hunk header tests' '
 for i in $(git ls-files)
 do
 	test_expect_success "hunk header: $i" "
-		git diff -U1 $i >actual &&
-		grep '@@ .* @@.*RIGHT' actual
+		git diff -U1 $i >diff &&
+		sed -n -e 's/^.*@@$//p' -e 's/^.*@@ //p' <diff >ctx &&
The original was already loose but this makes it even looser.  Can
we tighten the pattern to strip the line number information from the
hunk header to something more like like this, please?

	/^@@[-+0-9, ]*@@/

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