debian: new upstream point release
[git/debian.git] / t / t4213-log-tabexpand.sh
blob590fce95e90a8bd751daf13c0696d0a39b8f7d1b
1 #!/bin/sh
3 test_description='log/show --expand-tabs'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 HT=" "
9 title='tab indent at the beginning of the title line'
10 body='tab indent on a line in the body'
12 # usage: count_expand $indent $numSP $numHT @format_args
13 count_expand ()
15 expect=
16 count=$(( $1 + $2 )) ;# expected spaces
17 while test $count -gt 0
19 expect="$expect "
20 count=$(( $count - 1 ))
21 done
22 shift 2
23 count=$1 ;# expected tabs
24 while test $count -gt 0
26 expect="$expect$HT"
27 count=$(( $count - 1 ))
28 done
29 shift
31 # The remainder of the command line is "git show -s" options
32 case " $* " in
33 *' --pretty=short '*)
34 line=$title ;;
36 line=$body ;;
37 esac
39 # Prefix the output with the command line arguments, and
40 # replace SP with a dot both in the expected and actual output
41 # so that test_cmp would show the difference together with the
42 # breakage in a way easier to consume by the debugging user.
44 echo "git show -s $*"
45 echo "$expect$line"
46 } | sed -e 's/ /./g' >expect
49 echo "git show -s $*"
50 git show -s "$@" |
51 sed -n -e "/$line\$/p"
52 } | sed -e 's/ /./g' >actual
54 test_cmp expect actual
57 test_expand ()
59 fmt=$1
60 case "$fmt" in
61 *=raw | *=short | *=email)
62 default="0 1" ;;
64 default="8 0" ;;
65 esac
66 case "$fmt" in
67 *=email)
68 in=0 ;;
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
87 test_expect_success 'setup' '
88 test_tick &&
89 sed -e "s/Q/$HT/g" <<-EOF >msg &&
90 Q$title
92 Q$body
93 EOF
94 git commit --allow-empty -F msg
97 test_expand ""
98 test_expand --pretty
99 test_expand --pretty=short
100 test_expand --pretty=medium
101 test_expand --pretty=full
102 test_expand --pretty=fuller
103 test_expand --pretty=raw
104 test_expand --pretty=email
106 test_done