]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4052-stat-output.sh
hashmap: use *_entry APIs for iteration
[thirdparty/git.git] / t / t4052-stat-output.sh
CommitLineData
31c2373d
JH
1#!/bin/sh
2#
3# Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
4#
5
6test_description='test --stat output of various commands'
7
8. ./test-lib.sh
9. "$TEST_DIRECTORY"/lib-terminal.sh
10
11# 120 character name
12name=aaaaaaaaaa
13name=$name$name$name$name$name$name$name$name$name$name$name$name
14test_expect_success 'preparation' '
15 >"$name" &&
16 git add "$name" &&
17 git commit -m message &&
18 echo a >"$name" &&
19 git commit -m message "$name"
20'
21
071dd0ba
NTND
22cat >expect72 <<-'EOF'
23 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
24EOF
25test_expect_success "format-patch: small change with long name gives more space to the name" '
26 git format-patch -1 --stdout >output &&
27 grep " | " output >actual &&
28 test_cmp expect72 actual
29'
30
31c2373d
JH
31while read cmd args
32do
071dd0ba 33 cat >expect80 <<-'EOF'
dc801e71 34 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
31c2373d 35 EOF
1b058bc3 36 test_expect_success "$cmd: small change with long name gives more space to the name" '
31c2373d
JH
37 git $cmd $args >output &&
38 grep " | " output >actual &&
071dd0ba 39 test_cmp expect80 actual
31c2373d 40 '
071dd0ba
NTND
41done <<\EOF
42diff HEAD^ HEAD --stat
43show --stat
44log -1 --stat
45EOF
31c2373d 46
284aeb7e
NTND
47cat >expect.60 <<-'EOF'
48 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
49EOF
50cat >expect.6030 <<-'EOF'
51 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
52EOF
53cat >expect2.60 <<-'EOF'
54 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
55 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
56EOF
57cat >expect2.6030 <<-'EOF'
58 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
59 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
60EOF
61while read expect cmd args
071dd0ba 62do
1b058bc3 63 test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
31c2373d
JH
64 git $cmd $args --stat=40 >output &&
65 grep " | " output >actual &&
284aeb7e 66 test_cmp $expect.60 actual
31c2373d
JH
67 '
68
69 test_expect_success "$cmd --stat-width=width with long name" '
70 git $cmd $args --stat-width=40 >output &&
71 grep " | " output >actual &&
284aeb7e 72 test_cmp $expect.60 actual
31c2373d
JH
73 '
74
31c2373d
JH
75 test_expect_success "$cmd --stat=...,name-width with long name" '
76 git $cmd $args --stat=60,30 >output &&
77 grep " | " output >actual &&
284aeb7e 78 test_cmp $expect.6030 actual
31c2373d
JH
79 '
80
81 test_expect_success "$cmd --stat-name-width with long name" '
82 git $cmd $args --stat-name-width=30 >output &&
83 grep " | " output >actual &&
284aeb7e 84 test_cmp $expect.6030 actual
31c2373d
JH
85 '
86done <<\EOF
284aeb7e
NTND
87expect2 format-patch --cover-letter -1 --stdout
88expect diff HEAD^ HEAD --stat
89expect show --stat
90expect log -1 --stat
31c2373d
JH
91EOF
92
93
94test_expect_success 'preparation for big change tests' '
95 >abcd &&
96 git add abcd &&
97 git commit -m message &&
98 i=0 &&
99 while test $i -lt 1000
100 do
101 echo $i && i=$(($i + 1))
102 done >abcd &&
103 git commit -m message abcd
104'
105
284aeb7e
NTND
106cat >expect72 <<'EOF'
107 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
109EOF
110test_expect_success "format-patch --cover-letter ignores COLUMNS (big change)" '
111 COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
112 grep " | " output >actual &&
113 test_cmp expect72 actual
114'
115
071dd0ba
NTND
116cat >expect72 <<'EOF'
117 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31c2373d 118EOF
071dd0ba
NTND
119cat >expect72-graph <<'EOF'
120| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8c188c74 121EOF
af9fedc1
ZJS
122cat >expect200 <<'EOF'
123 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124EOF
8c188c74 125cat >expect200-graph <<'EOF'
36dcc02c 126| abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8c188c74 127EOF
31c2373d
JH
128while read verb expect cmd args
129do
130 test_expect_success "$cmd $verb COLUMNS (big change)" '
60687de5 131 COLUMNS=200 git $cmd $args >output &&
31c2373d
JH
132 grep " | " output >actual &&
133 test_cmp "$expect" actual
134 '
8c188c74 135
695985f4 136 case "$cmd" in diff|show) continue;; esac
8c188c74
ZJS
137
138 test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
60687de5 139 COLUMNS=200 git $cmd $args --graph >output &&
8c188c74
ZJS
140 grep " | " output >actual &&
141 test_cmp "$expect-graph" actual
142 '
31c2373d 143done <<\EOF
071dd0ba 144ignores expect72 format-patch -1 --stdout
af9fedc1 145respects expect200 diff HEAD^ HEAD --stat
666c92a2 146respects expect200 show --stat
5e0ec15e 147respects expect200 log -1 --stat
31c2373d
JH
148EOF
149
c4432d55
ZJS
150cat >expect40 <<'EOF'
151 abcd | 1000 ++++++++++++++++++++++++++
152EOF
8c188c74 153cat >expect40-graph <<'EOF'
36dcc02c 154| abcd | 1000 ++++++++++++++++++++++++
8c188c74 155EOF
c4432d55
ZJS
156while read verb expect cmd args
157do
158 test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
60687de5 159 COLUMNS=40 git $cmd $args >output &&
c4432d55
ZJS
160 grep " | " output >actual &&
161 test_cmp "$expect" actual
162 '
df44483a 163
695985f4 164 case "$cmd" in diff|show) continue;; esac
8c188c74
ZJS
165
166 test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
60687de5 167 COLUMNS=40 git $cmd $args --graph >output &&
8c188c74
ZJS
168 grep " | " output >actual &&
169 test_cmp "$expect-graph" actual
170 '
36dcc02c 171done <<\EOF
071dd0ba 172ignores expect72 format-patch -1 --stdout
36dcc02c
LP
173respects expect40 diff HEAD^ HEAD --stat
174respects expect40 show --stat
175respects expect40 log -1 --stat
176EOF
177
178cat >expect40 <<'EOF'
179 abcd | 1000 ++++++++++++++++++++++++++
180EOF
181cat >expect40-graph <<'EOF'
182| abcd | 1000 ++++++++++++++++++++++++++
183EOF
184while read verb expect cmd args
185do
186 test_expect_success "$cmd $verb statGraphWidth config" '
60687de5 187 git -c diff.statGraphWidth=26 $cmd $args >output &&
36dcc02c
LP
188 grep " | " output >actual &&
189 test_cmp "$expect" actual
190 '
191
695985f4 192 case "$cmd" in diff|show) continue;; esac
8c188c74
ZJS
193
194 test_expect_success "$cmd --graph $verb statGraphWidth config" '
60687de5 195 git -c diff.statGraphWidth=26 $cmd $args --graph >output &&
8c188c74
ZJS
196 grep " | " output >actual &&
197 test_cmp "$expect-graph" actual
198 '
c4432d55 199done <<\EOF
071dd0ba 200ignores expect72 format-patch -1 --stdout
c4432d55
ZJS
201respects expect40 diff HEAD^ HEAD --stat
202respects expect40 show --stat
203respects expect40 log -1 --stat
204EOF
205
206
31c2373d
JH
207cat >expect <<'EOF'
208 abcd | 1000 ++++++++++++++++++++++++++
209EOF
8c188c74
ZJS
210cat >expect-graph <<'EOF'
211| abcd | 1000 ++++++++++++++++++++++++++
212EOF
31c2373d
JH
213while read cmd args
214do
215 test_expect_success "$cmd --stat=width with big change" '
60687de5 216 git $cmd $args --stat=40 >output &&
31c2373d
JH
217 grep " | " output >actual &&
218 test_cmp expect actual
219 '
220
221 test_expect_success "$cmd --stat-width=width with big change" '
60687de5 222 git $cmd $args --stat-width=40 >output &&
31c2373d
JH
223 grep " | " output >actual &&
224 test_cmp expect actual
969fe57b
ZJS
225 '
226
8c188c74 227 test_expect_success "$cmd --stat-graph-width with big change" '
60687de5 228 git $cmd $args --stat-graph-width=26 >output &&
969fe57b
ZJS
229 grep " | " output >actual &&
230 test_cmp expect actual
31c2373d 231 '
8c188c74 232
695985f4 233 case "$cmd" in diff|show) continue;; esac
8c188c74
ZJS
234
235 test_expect_success "$cmd --stat-width=width --graph with big change" '
60687de5 236 git $cmd $args --stat-width=40 --graph >output &&
8c188c74
ZJS
237 grep " | " output >actual &&
238 test_cmp expect-graph actual
239 '
240
241 test_expect_success "$cmd --stat-graph-width --graph with big change" '
60687de5 242 git $cmd $args --stat-graph-width=26 --graph >output &&
8c188c74
ZJS
243 grep " | " output >actual &&
244 test_cmp expect-graph actual
245 '
31c2373d
JH
246done <<\EOF
247format-patch -1 --stdout
248diff HEAD^ HEAD --stat
249show --stat
250log -1 --stat
251EOF
252
253test_expect_success 'preparation for long filename tests' '
254 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
255 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
256 git commit -m message
257'
258
259cat >expect <<'EOF'
1b058bc3 260 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
31c2373d 261EOF
8c188c74
ZJS
262cat >expect-graph <<'EOF'
263| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
264EOF
31c2373d
JH
265while read cmd args
266do
1b058bc3 267 test_expect_success "$cmd --stat=width with big change is more balanced" '
31c2373d
JH
268 git $cmd $args --stat-width=60 >output &&
269 grep " | " output >actual &&
270 test_cmp expect actual
271 '
8c188c74 272
695985f4 273 case "$cmd" in diff|show) continue;; esac
8c188c74
ZJS
274
275 test_expect_success "$cmd --stat=width --graph with big change is balanced" '
276 git $cmd $args --stat-width=60 --graph >output &&
277 grep " | " output >actual &&
278 test_cmp expect-graph actual
279 '
31c2373d
JH
280done <<\EOF
281format-patch -1 --stdout
282diff HEAD^ HEAD --stat
283show --stat
284log -1 --stat
285EOF
286
071dd0ba
NTND
287cat >expect72 <<'EOF'
288 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
31c2373d 289EOF
071dd0ba
NTND
290cat >expect72-graph <<'EOF'
291| ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
8c188c74 292EOF
af9fedc1 293cat >expect200 <<'EOF'
1b058bc3 294 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
af9fedc1 295EOF
8c188c74 296cat >expect200-graph <<'EOF'
36dcc02c 297| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8c188c74 298EOF
31c2373d
JH
299while read verb expect cmd args
300do
301 test_expect_success "$cmd $verb COLUMNS (long filename)" '
60687de5 302 COLUMNS=200 git $cmd $args >output &&
31c2373d
JH
303 grep " | " output >actual &&
304 test_cmp "$expect" actual
305 '
8c188c74 306
695985f4 307 case "$cmd" in diff|show) continue;; esac
8c188c74
ZJS
308
309 test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
60687de5 310 COLUMNS=200 git $cmd $args --graph >output &&
8c188c74
ZJS
311 grep " | " output >actual &&
312 test_cmp "$expect-graph" actual
313 '
31c2373d 314done <<\EOF
071dd0ba 315ignores expect72 format-patch -1 --stdout
af9fedc1 316respects expect200 diff HEAD^ HEAD --stat
666c92a2 317respects expect200 show --stat
5e0ec15e 318respects expect200 log -1 --stat
31c2373d
JH
319EOF
320
da79161d
LP
321cat >expect1 <<'EOF'
322 ...aaaaaaa | 1000 ++++++
323EOF
324cat >expect1-graph <<'EOF'
325| ...aaaaaaa | 1000 ++++++
326EOF
678c5741 327while read verb expect cmd args
da79161d 328do
bafa16e5
ZJS
329 test_expect_success COLUMNS_CAN_BE_1 \
330 "$cmd $verb prefix greater than COLUMNS (big change)" '
60687de5 331 COLUMNS=1 git $cmd $args >output &&
da79161d
LP
332 grep " | " output >actual &&
333 test_cmp "$expect" actual
334 '
335
695985f4 336 case "$cmd" in diff|show) continue;; esac
da79161d 337
bafa16e5
ZJS
338 test_expect_success COLUMNS_CAN_BE_1 \
339 "$cmd --graph $verb prefix greater than COLUMNS (big change)" '
60687de5 340 COLUMNS=1 git $cmd $args --graph >output &&
da79161d
LP
341 grep " | " output >actual &&
342 test_cmp "$expect-graph" actual
343 '
344done <<\EOF
071dd0ba 345ignores expect72 format-patch -1 --stdout
678c5741
LP
346respects expect1 diff HEAD^ HEAD --stat
347respects expect1 show --stat
348respects expect1 log -1 --stat
da79161d
LP
349EOF
350
31c2373d 351cat >expect <<'EOF'
7a7159ac 352 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31c2373d 353EOF
7a7159ac 354test_expect_success 'merge --stat respects COLUMNS (big change)' '
31c2373d
JH
355 git checkout -b branch HEAD^^ &&
356 COLUMNS=100 git merge --stat --no-ff master^ >output &&
60687de5 357 grep " | " output >actual &&
31c2373d
JH
358 test_cmp expect actual
359'
360
361cat >expect <<'EOF'
1b058bc3 362 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
31c2373d 363EOF
7a7159ac 364test_expect_success 'merge --stat respects COLUMNS (long filename)' '
31c2373d 365 COLUMNS=100 git merge --stat --no-ff master >output &&
60687de5 366 grep " | " output >actual &&
31c2373d
JH
367 test_cmp expect actual
368'
369
370test_done