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

Re: [PATCH v5 4/4] pretty: test --expand-tabs

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 5, 2016, 06:32 UTC
Message-ID
<xmqqbn5o4lca.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160405015234.GB29953@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 12 quoted lines
> On Mon, Apr 04, 2016 at 05:58:37PM -0700, Junio C Hamano wrote:
>
>> +count_expand ()
>> +{
>
> This function takes a lot of unnamed arguments that we process with
> "shift". It might be nice to give a brief comment describing them.
> ...
>> +test_expand --pretty=fuller
>> +test_expand --pretty=fuller
> ...
> Duplicated fuller?
Thanks.  Here is a replacement.

-- >8 -- The test prepares a simple commit with HT on its log message lines, and makes sure that

 - formats that should or should not expand tabs by default do or do
   not expand tabs respectively,
 - with explicit --expand-tabs=<N> and short-hands --expand-tabs
   (equivalent to --expand-tabs=8) and --no-expand-tabs (equivalent
   to --expand-tabs=0) before or after the explicit --pretty=$fmt,
   the tabs are expanded (or not expanded) accordingly.

The tests use the second line of the log message for formats other than --pretty=short, primarily because the first line of the email format is handled specially to add the [PATCH] prefix, etc. in a separate codepath (--pretty=short uses the first line because there is no other line to test).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t4213-log-tabexpand.sh | 105 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100755 t/t4213-log-tabexpand.sh
diff --git a/t/t4213-log-tabexpand.sh b/t/t4213-log-tabexpand.sh
new file mode 100755
index 0000000..e01a8f6
--- /dev/null
+++ b/t/t4213-log-tabexpand.sh
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+test_description='log/show --expand-tabs'
+
+. ./test-lib.sh
+
+HT="	"
+title='tab indent at the beginning of the title line'
+body='tab indent on a line in the body'
+
+# usage: count_expand $indent $numSP $numHT @format_args
+count_expand ()
+{
+	expect=
+	count=$(( $1 + $2 )) ;# expected spaces
+	while test $count -gt 0
+	do
+		expect="$expect "
+		count=$(( $count - 1 ))
+	done
+	shift 2
+	count=$1 ;# expected tabs
+	while test $count -gt 0
+	do
+		expect="$expect$HT"
+		count=$(( $count - 1 ))
+	done
+	shift
+
+	# The remainder of the command line is "git show -s" options
+	case " $* " in
+	*' --pretty=short '*)
+		line=$title ;;
+	*)
+		line=$body ;;
+	esac
+
+	# Prefix the output with the command line arguments, and
+	# replace SP with a dot both in the expecte and actual output
+	# so that test_cmp would show the differene together with the
+	# breakage in a way easier to consume by the debugging user.
+	{
+		echo "git show -s $*"
+		echo "$expect$line"
+	} | sed -e 's/ /./g' >expect
+
+	{
+		echo "git show -s $*"
+		git show -s "$@" |
+		sed -n -e "/$line\$/p"
+	} | sed -e 's/ /./g' >actual
+
+	test_cmp expect actual
+}
+
+test_expand ()
+{
+	fmt=$1
+	case "$fmt" in
+	*=raw | *=short | *=email)
+		default="0 1" ;;
+	*)
+		default="8 0" ;;
+	esac
+	case "$fmt" in
+	*=email)
+		in=0 ;;
+	*)
+		in=4 ;;
+	esac
+	test_expect_success "expand/no-expand${fmt:+ for $fmt}" '
+		count_expand $in $default $fmt &&
+		count_expand $in 8 0 $fmt --expand-tabs &&
+		count_expand $in 8 0 --expand-tabs $fmt &&
+		count_expand $in 8 0 $fmt --expand-tabs=8 &&
+		count_expand $in 8 0 --expand-tabs=8 $fmt &&
+		count_expand $in 0 1 $fmt --no-expand-tabs &&
+		count_expand $in 0 1 --no-expand-tabs $fmt &&
+		count_expand $in 0 1 $fmt --expand-tabs=0 &&
+		count_expand $in 0 1 --expand-tabs=0 $fmt &&
+		count_expand $in 4 0 $fmt --expand-tabs=4 &&
+		count_expand $in 4 0 --expand-tabs=4 $fmt
+	'
+}
+
+test_expect_success 'setup' '
+	test_tick &&
+	sed -e "s/Q/$HT/g" <<-EOF >msg &&
+	Q$title
+
+	Q$body
+	EOF
+	git commit --allow-empty -F msg
+'
+
+test_expand ""
+test_expand --pretty
+test_expand --pretty=short
+test_expand --pretty=medium
+test_expand --pretty=full
+test_expand --pretty=fuller
+test_expand --pretty=raw
+test_expand --pretty=email
+
+test_done
-- 
2.8.1-253-gd0f4798
Previous: Jeff KingNext: Perry Hutchison
Message 53 of 57 in “pretty-print: de-tabify indented logs to make things line up properly”
  1. pretty-print: de-tabify indented logs to make things line up properlyLinus Torvalds, Mar 16, 2016
  2. Linus TorvaldsMar 16, 2016
  3. Junio C HamanoMar 16, 2016
  4. Linus TorvaldsMar 16, 2016
  5. Junio C HamanoMar 16, 2016
  6. Junio C HamanoMar 16, 2016
  7. Linus TorvaldsMar 16, 2016
  8. Junio C HamanoMar 16, 2016
  9. Linus TorvaldsMar 16, 2016
  10. 1/4 pretty-print: de-tabify indented logs to make things line up properlyJunio C Hamano, Mar 17, 2016
  11. 2/4 pretty-print: simplify the interaction between pp_handle_indent() and its callerJunio C Hamano, Mar 17, 2016
  12. 3/4 pretty-print: further abstract out pp_handle_indent()Junio C Hamano, Mar 17, 2016
  13. 4/4 pretty-print: add --pretty=noexpandJunio C Hamano, Mar 17, 2016
  14. Linus TorvaldsMar 17, 2016
  15. Junio C HamanoMar 17, 2016
  16. Jeff KingMar 18, 2016
  17. Linus TorvaldsMar 18, 2016
  18. Jeff KingMar 18, 2016
  19. Junio C HamanoMar 18, 2016
  20. 0/5 Expanding tabs in "git log" outputJunio C Hamano, Mar 23, 2016
  21. 1/5 pretty-print: de-tabify indented logs to make things line up properlyJunio C Hamano, Mar 23, 2016
  22. 2/5 pretty-print: simplify the interaction between pp_handle_indent() and its callerJunio C Hamano, Mar 23, 2016
  23. 3/5 pretty-print: further abstract out pp_handle_indent()Junio C Hamano, Mar 23, 2016
  24. 4/5 pretty-print: limit expand-tabs to selected --pretty formatsJunio C Hamano, Mar 23, 2016
  25. 5/5 pretty-print: teach "--no-expand-tabs" option to "git log"Junio C Hamano, Mar 23, 2016
  26. Linus TorvaldsMar 23, 2016
  27. Jeff KingMar 24, 2016
  28. Junio C HamanoMar 24, 2016
  29. Torsten BögershausenMar 24, 2016
  30. Junio C HamanoMar 24, 2016
  31. Junio C HamanoMar 24, 2016
  32. Torsten BögershausenMar 25, 2016
  33. Torsten BögershausenMar 25, 2016
  34. Junio C HamanoMar 25, 2016
  35. Junio C HamanoMar 25, 2016
  36. 0/3 Expanding tabs in "git log" outputJunio C Hamano, Mar 29, 2016
  37. 1/3 pretty: expand tabs in indented logs to make things line up properlyJunio C Hamano, Mar 29, 2016
  38. Eric SunshineMar 30, 2016
  39. Junio C HamanoMar 30, 2016
  40. 2/3 pretty: enable --expand-tabs by default for selected pretty formatsJunio C Hamano, Mar 29, 2016
  41. Jeff KingMar 30, 2016
  42. Junio C HamanoMar 30, 2016
  43. 3/3 pretty: allow tweaking tabwidth in --expand-tabsJunio C Hamano, Mar 29, 2016
  44. 0/4 Expanding tabs in "git log" outputJunio C Hamano, Apr 5, 2016
  45. 1/4 pretty: expand tabs in indented logs to make things line up properlyJunio C Hamano, Apr 5, 2016
  46. 2/4 pretty: enable --expand-tabs by default for selected pretty formatsJunio C Hamano, Apr 5, 2016
  47. 3/4 pretty: allow tweaking tabwidth in --expand-tabsJunio C Hamano, Apr 5, 2016
  48. 4/4 pretty: test --expand-tabsJunio C Hamano, Apr 5, 2016
  49. Eric SunshineApr 5, 2016
  50. Jeff KingApr 5, 2016
  51. Junio C HamanoApr 5, 2016
  52. Jeff KingApr 5, 2016
  53. Junio C HamanoApr 5, 2016
  54. Perry HutchisonApr 5, 2016
  55. Jeff KingApr 5, 2016
  56. Linus TorvaldsMar 16, 2016
  57. Junio C HamanoMar 16, 2016

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.