summaryrefslogtreecommitdiff
path: root/t/t4213-log-tabexpand.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-04-04 23:09:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-04-05 06:31:13 (GMT)
commit915c96df3822f968332f6bf3642e5195b52201c9 (patch)
treee86ca7897d7c43d8c9f08016298feb2edc7eb15f /t/t4213-log-tabexpand.sh
parentfe37a9c586a65943e1bca327a1bbe1ca4a3d3023 (diff)
downloadgit-915c96df3822f968332f6bf3642e5195b52201c9.zip
git-915c96df3822f968332f6bf3642e5195b52201c9.tar.gz
git-915c96df3822f968332f6bf3642e5195b52201c9.tar.bz2
pretty: test --expand-tabs
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>
Diffstat (limited to 't/t4213-log-tabexpand.sh')
-rwxr-xr-xt/t4213-log-tabexpand.sh105
1 files changed, 105 insertions, 0 deletions
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