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