diff --stat: use the full terminal width
[git.git] / t / t4052-stat-output.sh
blob29c06e59a60eeb85d2ba1d876d1dee5e296c47a9
1 #!/bin/sh
3 # Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
6 test_description='test --stat output of various commands'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-terminal.sh
11 # 120 character name
12 name=aaaaaaaaaa
13 name=$name$name$name$name$name$name$name$name$name$name$name$name
14 test_expect_success 'preparation' '
15 >"$name" &&
16 git add "$name" &&
17 git commit -m message &&
18 echo a >"$name" &&
19 git commit -m message "$name"
22 while read cmd args
24 cat >expect <<-'EOF'
25 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
26 EOF
27 test_expect_success "$cmd: a short graph bar does not extend to the full width" '
28 git $cmd $args >output &&
29 grep " | " output >actual &&
30 test_cmp expect actual
33 cat >expect <<-'EOF'
34 ...aaaaaaaaaaaaaaaaaaaaaa | 1 +
35 EOF
36 test_expect_success "$cmd --stat=width: name is chopped to leave room to the right of a short bar" '
37 git $cmd $args --stat=40 >output &&
38 grep " | " output >actual &&
39 test_cmp expect actual
42 test_expect_success "$cmd --stat-width=width with long name" '
43 git $cmd $args --stat-width=40 >output &&
44 grep " | " output >actual &&
45 test_cmp expect actual
48 cat >expect <<-'EOF'
49 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
50 EOF
51 test_expect_success "$cmd --stat=...,name-width with long name" '
52 git $cmd $args --stat=60,30 >output &&
53 grep " | " output >actual &&
54 test_cmp expect actual
57 test_expect_success "$cmd --stat-name-width with long name" '
58 git $cmd $args --stat-name-width=30 >output &&
59 grep " | " output >actual &&
60 test_cmp expect actual
62 done <<\EOF
63 format-patch -1 --stdout
64 diff HEAD^ HEAD --stat
65 show --stat
66 log -1 --stat
67 EOF
70 test_expect_success 'preparation for big change tests' '
71 >abcd &&
72 git add abcd &&
73 git commit -m message &&
74 i=0 &&
75 while test $i -lt 1000
77 echo $i && i=$(($i + 1))
78 done >abcd &&
79 git commit -m message abcd
82 cat >expect80 <<'EOF'
83 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84 EOF
86 cat >expect200 <<'EOF'
87 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88 EOF
90 while read verb expect cmd args
92 test_expect_success "$cmd $verb COLUMNS (big change)" '
93 COLUMNS=200 git $cmd $args >output
94 grep " | " output >actual &&
95 test_cmp "$expect" actual
97 done <<\EOF
98 ignores expect80 format-patch -1 --stdout
99 respects expect200 diff HEAD^ HEAD --stat
100 ignores expect80 show --stat
101 ignores expect80 log -1 --stat
104 cat >expect <<'EOF'
105 abcd | 1000 ++++++++++++++++++++++++++
107 while read cmd args
109 test_expect_success "$cmd --stat=width with big change" '
110 git $cmd $args --stat=40 >output
111 grep " | " output >actual &&
112 test_cmp expect actual
115 test_expect_success "$cmd --stat-width=width with big change" '
116 git $cmd $args --stat-width=40 >output
117 grep " | " output >actual &&
118 test_cmp expect actual
120 done <<\EOF
121 format-patch -1 --stdout
122 diff HEAD^ HEAD --stat
123 show --stat
124 log -1 --stat
127 test_expect_success 'preparation for long filename tests' '
128 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
129 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
130 git commit -m message
133 cat >expect <<'EOF'
134 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++
136 while read cmd args
138 test_expect_success "$cmd --stat=width with big change and long name favors name part" '
139 git $cmd $args --stat-width=60 >output &&
140 grep " | " output >actual &&
141 test_cmp expect actual
143 done <<\EOF
144 format-patch -1 --stdout
145 diff HEAD^ HEAD --stat
146 show --stat
147 log -1 --stat
150 cat >expect80 <<'EOF'
151 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
153 cat >expect200 <<'EOF'
154 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156 while read verb expect cmd args
158 test_expect_success "$cmd $verb COLUMNS (long filename)" '
159 COLUMNS=200 git $cmd $args >output
160 grep " | " output >actual &&
161 test_cmp "$expect" actual
163 done <<\EOF
164 ignores expect80 format-patch -1 --stdout
165 respects expect200 diff HEAD^ HEAD --stat
166 ignores expect80 show --stat
167 ignores expect80 log -1 --stat
170 cat >expect <<'EOF'
171 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173 test_expect_success 'merge --stat ignores COLUMNS (big change)' '
174 git checkout -b branch HEAD^^ &&
175 COLUMNS=100 git merge --stat --no-ff master^ >output &&
176 grep " | " output >actual
177 test_cmp expect actual
180 cat >expect <<'EOF'
181 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
183 test_expect_success 'merge --stat ignores COLUMNS (long filename)' '
184 COLUMNS=100 git merge --stat --no-ff master >output &&
185 grep " | " output >actual
186 test_cmp expect actual
189 test_done