about summary refs log tree commit diff
path: root/third_party/git/t/t4213-log-tabexpand.sh
blob: 7f90f58c03e6fff921e65f9b4138de9dcf972941 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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 difference 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