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

Re: [PATCH] tests: Introduce test_seq

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 3, 2012, 23:12 UTC
Message-ID
<7vfw83a7t5.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1344032464-14104-1-git-send-email-michal.kiedrowicz@gmail.com>

Tentatively I'll queue this one on top, but I am tempted to squash this in before merging the topic down.

-- >8 --
Subject: [PATCH] fixup! tests: Introduce test_seq

Complex chains of && and || are harder to read when used as replacement for if/else statements, but it is easy to rewrite it with a case/esac in this case.

Avoid using unnecessary variables $first and $last.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/test-lib-functions.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c8b4ae3..7dc70eb 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -532,7 +532,7 @@ test_cmp() {
 
 # Print a sequence of numbers or letters in increasing order.  This is
 # similar to GNU seq(1), but the latter might not be available
-# everywhere.  It may be used like:
+# everywhere (and does not do letters).  It may be used like:
 #
 #	for i in `test_seq 100`; do
 #		for j in `test_seq 10 20`; do
@@ -543,11 +543,12 @@ test_cmp() {
 #	done
 
 test_seq () {
-	test $# = 2 && { first=$1; shift; } || first=1
-	test $# = 1 ||
-	error "bug in the test script: not 1 or 2 parameters to test_seq"
-	last=$1
-	"$PERL_PATH" -le 'print for "$ARGV[0]".."$ARGV[1]"' "$first" "$last"
+	case $# in
+	1)	set 1 "$@" ;;
+	2)	;;
+	*)	error "bug in the test script: not 1 or 2 parameters to test_seq" ;;
+	esac
+	"$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' "$@"
 }
 
 # This function can be used to schedule some commands to be run
-- 
1.7.12.rc1.50.g3df08cf
Previous: Jeff KingNext: Michał Kiedrowicz
Message 21 of 34 in “Fix 'No newline...' annotation in rewrite diffs.”
  1. Fix 'No newline...' annotation in rewrite diffs.Adam Butcher, Aug 2, 2012
  2. Jeff KingAug 2, 2012
  3. Junio C HamanoAug 2, 2012
  4. Jeff KingAug 2, 2012
  5. Michał KiedrowiczAug 3, 2012
  6. Jeff KingAug 3, 2012
  7. Junio C HamanoAug 3, 2012
  8. Jeff KingAug 3, 2012
  9. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  10. Jeff KingAug 3, 2012
  11. Junio C HamanoAug 3, 2012
  12. Jeff KingAug 3, 2012
  13. Michał KiedrowiczAug 3, 2012
  14. Johannes SixtAug 4, 2012
  15. Junio C HamanoAug 4, 2012
  16. Michał KiedrowiczAug 6, 2012
  17. Jeff KingAug 6, 2012
  18. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  19. Junio C HamanoAug 3, 2012
  20. Jeff KingAug 3, 2012
  21. Junio C HamanoAug 3, 2012
  22. Michał KiedrowiczAug 4, 2012
  23. Adam ButcherAug 4, 2012
  24. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  25. Jeff KingAug 3, 2012
  26. Michał KiedrowiczAug 3, 2012
  27. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  28. Jeff KingAug 3, 2012
  29. Adam ButcherAug 2, 2012
  30. Junio C HamanoAug 2, 2012
  31. Adam ButcherAug 2, 2012
  32. Adam ButcherAug 4, 2012
  33. Junio C HamanoAug 5, 2012
  34. Fix '\ No newline...' annotation in rewrite diffsAdam Butcher, Aug 5, 2012

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.