]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4213-log-tabexpand.sh
The seventh batch
[thirdparty/git.git] / t / t4213-log-tabexpand.sh
CommitLineData
915c96df
JH
1#!/bin/sh
2
3test_description='log/show --expand-tabs'
4
03267e86 5TEST_PASSES_SANITIZE_LEAK=true
915c96df
JH
6. ./test-lib.sh
7
8HT=" "
9title='tab indent at the beginning of the title line'
10body='tab indent on a line in the body'
11
12# usage: count_expand $indent $numSP $numHT @format_args
13count_expand ()
14{
15 expect=
16 count=$(( $1 + $2 )) ;# expected spaces
17 while test $count -gt 0
18 do
19 expect="$expect "
20 count=$(( $count - 1 ))
21 done
22 shift 2
23 count=$1 ;# expected tabs
24 while test $count -gt 0
25 do
26 expect="$expect$HT"
27 count=$(( $count - 1 ))
28 done
29 shift
30
31 # The remainder of the command line is "git show -s" options
32 case " $* " in
33 *' --pretty=short '*)
34 line=$title ;;
35 *)
36 line=$body ;;
37 esac
38
39 # Prefix the output with the command line arguments, and
7a40cf15 40 # replace SP with a dot both in the expected and actual output
64127575 41 # so that test_cmp would show the difference together with the
915c96df
JH
42 # breakage in a way easier to consume by the debugging user.
43 {
44 echo "git show -s $*"
45 echo "$expect$line"
46 } | sed -e 's/ /./g' >expect
47
48 {
49 echo "git show -s $*"
50 git show -s "$@" |
51 sed -n -e "/$line\$/p"
52 } | sed -e 's/ /./g' >actual
53
54 test_cmp expect actual
55}
56
57test_expand ()
58{
59 fmt=$1
60 case "$fmt" in
61 *=raw | *=short | *=email)
62 default="0 1" ;;
63 *)
64 default="8 0" ;;
65 esac
66 case "$fmt" in
67 *=email)
68 in=0 ;;
69 *)
70 in=4 ;;
71 esac
72 test_expect_success "expand/no-expand${fmt:+ for $fmt}" '
73 count_expand $in $default $fmt &&
74 count_expand $in 8 0 $fmt --expand-tabs &&
75 count_expand $in 8 0 --expand-tabs $fmt &&
76 count_expand $in 8 0 $fmt --expand-tabs=8 &&
77 count_expand $in 8 0 --expand-tabs=8 $fmt &&
78 count_expand $in 0 1 $fmt --no-expand-tabs &&
79 count_expand $in 0 1 --no-expand-tabs $fmt &&
80 count_expand $in 0 1 $fmt --expand-tabs=0 &&
81 count_expand $in 0 1 --expand-tabs=0 $fmt &&
82 count_expand $in 4 0 $fmt --expand-tabs=4 &&
83 count_expand $in 4 0 --expand-tabs=4 $fmt
84 '
85}
86
87test_expect_success 'setup' '
88 test_tick &&
89 sed -e "s/Q/$HT/g" <<-EOF >msg &&
90 Q$title
91
92 Q$body
93 EOF
94 git commit --allow-empty -F msg
95'
96
97test_expand ""
98test_expand --pretty
99test_expand --pretty=short
100test_expand --pretty=medium
101test_expand --pretty=full
102test_expand --pretty=fuller
103test_expand --pretty=raw
104test_expand --pretty=email
105
106test_done