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