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

[PATCH 07/10] t4013: simplify magic parsing and drop "failure"

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 29, 2023, 07:25 UTC
Message-ID
<3b16c2cd7bd66c0eb56d33a6b91914500a1c24dd.1701242407.git.ps@pks.im>
In-Reply-To
<cover.1701242407.git.ps@pks.im>

In t14013, we have various different tests that verify whether certain diffs are generated as expected. As much of the logic is the same across many of the tests we some common code in there that generates the actual test cases for us.

As some diffs are more special than others depending on the command line parameters passed to git-diff(1), these tests need to adapt behaviour to the specific test case sometimes. This is done via colon-prefixed magic commands, of which we currently know "failure" and "noellipses". The logic to parse this magic is a bit convoluted though and hard to grasp, also due to the rather unnecessary nesting.

Un-nest the cases so that it becomes a bit more straightfoward. The logic is further simplified by removing support for the "failure" magic, which is not actually used anymore.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t4013-diff-various.sh | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 5cc17c2e0d..76b8619e2e 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -178,32 +178,29 @@ process_diffs () {
 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
 while read magic cmd
 do
-	status=success
 	case "$magic" in
 	'' | '#'*)
 		continue ;;
-	:*)
-		magic=${magic#:}
+	:noellipses)
+		magic=noellipses
 		label="$magic-$cmd"
-		case "$magic" in
-		noellipses) ;;
-		failure)
-			status=failure
-			magic=
-			label="$cmd" ;;
-		*)
-			BUG "unknown magic $magic" ;;
-		esac ;;
+		;;
+	:*)
+		BUG "unknown magic $magic"
+		;;
 	*)
-		cmd="$magic $cmd" magic=
-		label="$cmd" ;;
+		cmd="$magic $cmd"
+		magic=
+		label="$cmd"
+		;;
 	esac
+
 	test=$(echo "$label" | sed -e 's|[/ ][/ ]*|_|g')
 	pfx=$(printf "%04d" $test_count)
 	expect="$TEST_DIRECTORY/t4013/diff.$test"
 	actual="$pfx-diff.$test"
 
-	test_expect_$status "git $cmd # magic is ${magic:-(not used)}" '
+	test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
 		{
 			echo "$ git $cmd"
 			case "$magic" in
-- 
2.43.0
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 9 of 16 in “t: more compatibility fixes with reftables”
  1. 00/10 t: more compatibility fixes with reftablesPatrick Steinhardt, Nov 29, 2023
  2. 01/10 t0410: mark tests to require the reffiles backendPatrick Steinhardt, Nov 29, 2023
  3. Taylor BlauNov 29, 2023
  4. 02/10 t1400: split up generic reflog tests from the reffile-specific onesPatrick Steinhardt, Nov 29, 2023
  5. 03/10 t1401: stop treating FETCH_HEAD as real referencePatrick Steinhardt, Nov 29, 2023
  6. 04/10 t1410: use test-tool to create empty reflogPatrick Steinhardt, Nov 29, 2023
  7. 05/10 t1417: make `reflog --updateref` tests backend agnosticPatrick Steinhardt, Nov 29, 2023
  8. 06/10 t3310: stop checking for reference existence via `test -f`Patrick Steinhardt, Nov 29, 2023
  9. 07/10 t4013: simplify magic parsing and drop "failure"Patrick Steinhardt, Nov 29, 2023
  10. 08/10 t5401: speed up creation of many branchesPatrick Steinhardt, Nov 29, 2023
  11. Taylor BlauNov 29, 2023
  12. 09/10 t5551: stop writing packed-refs directlyPatrick Steinhardt, Nov 29, 2023
  13. Taylor BlauNov 29, 2023
  14. 10/10 t6301: write invalid object ID via `test-tool ref-store`Patrick Steinhardt, Nov 29, 2023
  15. Taylor BlauNov 29, 2023
  16. Patrick SteinhardtNov 30, 2023

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.