summaryrefslogtreecommitdiff
path: root/t/t4052-stat-output.sh
blob: babd2ead88182e7b212486d0ae753f51d5deac76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/bin/sh
#
# Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
#

test_description='test --stat output of various commands'

. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh

# 120 character name
name=aaaaaaaaaa
name=$name$name$name$name$name$name$name$name$name$name$name$name
test_expect_success 'preparation' '
	>"$name" &&
	git add "$name" &&
	git commit -m message &&
	echo a >"$name" &&
	git commit -m message "$name"
'

while read cmd args
do
	cat >expect <<-'EOF'
	 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
	EOF
	test_expect_success "$cmd: small change with long name gives more space to the name" '
		git $cmd $args >output &&
		grep " | " output >actual &&
		test_cmp expect actual
	'

	cat >expect <<-'EOF'
	 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
	EOF
	test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
		git $cmd $args --stat=40 >output &&
		grep " | " output >actual &&
		test_cmp expect actual
	'

	test_expect_success "$cmd --stat-width=width with long name" '
		git $cmd $args --stat-width=40 >output &&
		grep " | " output >actual &&
		test_cmp expect actual
	'

	cat >expect <<-'EOF'
	 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
	EOF
	test_expect_success "$cmd --stat=...,name-width with long name" '
		git $cmd $args --stat=60,30 >output &&
		grep " | " output >actual &&
		test_cmp expect actual
	'

	test_expect_success "$cmd --stat-name-width with long name" '
		git $cmd $args --stat-name-width=30 >output &&
		grep " | " output >actual &&
		test_cmp expect actual
	'
done <<\EOF
format-patch -1 --stdout
diff HEAD^ HEAD --stat
show --stat
log -1 --stat
EOF


test_expect_success 'preparation for big change tests' '
	>abcd &&
	git add abcd &&
	git commit -m message &&
	i=0 &&
	while test $i -lt 1000
	do
		echo $i && i=$(($i + 1))
	done >abcd &&
	git commit -m message abcd
'

cat >expect80 <<'EOF'
 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
cat >expect80-graph <<'EOF'
|  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
cat >expect200 <<'EOF'
 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
cat >expect200-graph <<'EOF'
|  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
while read verb expect cmd args
do
	test_expect_success "$cmd $verb COLUMNS (big change)" '
		COLUMNS=200 git $cmd $args >output
		grep " | " output >actual &&
		test_cmp "$expect" actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
		COLUMNS=200 git $cmd $args --graph >output
		grep " | " output >actual &&
		test_cmp "$expect-graph" actual
	'
done <<\EOF
ignores expect80 format-patch -1 --stdout
respects expect200 diff HEAD^ HEAD --stat
respects expect200 show --stat
respects expect200 log -1 --stat
EOF

cat >expect40 <<'EOF'
 abcd | 1000 ++++++++++++++++++++++++++
EOF
cat >expect40-graph <<'EOF'
|  abcd | 1000 ++++++++++++++++++++++++
EOF
while read verb expect cmd args
do
	test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
		COLUMNS=40 git $cmd $args >output
		grep " | " output >actual &&
		test_cmp "$expect" actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
		COLUMNS=40 git $cmd $args --graph >output
		grep " | " output >actual &&
		test_cmp "$expect-graph" actual
	'
done <<\EOF
ignores expect80 format-patch -1 --stdout
respects expect40 diff HEAD^ HEAD --stat
respects expect40 show --stat
respects expect40 log -1 --stat
EOF

cat >expect40 <<'EOF'
 abcd | 1000 ++++++++++++++++++++++++++
EOF
cat >expect40-graph <<'EOF'
|  abcd | 1000 ++++++++++++++++++++++++++
EOF
while read verb expect cmd args
do
	test_expect_success "$cmd $verb statGraphWidth config" '
		git -c diff.statGraphWidth=26 $cmd $args >output
		grep " | " output >actual &&
		test_cmp "$expect" actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success "$cmd --graph $verb statGraphWidth config" '
		git -c diff.statGraphWidth=26 $cmd $args --graph >output
		grep " | " output >actual &&
		test_cmp "$expect-graph" actual
	'
done <<\EOF
ignores expect80 format-patch -1 --stdout
respects expect40 diff HEAD^ HEAD --stat
respects expect40 show --stat
respects expect40 log -1 --stat
EOF


cat >expect <<'EOF'
 abcd | 1000 ++++++++++++++++++++++++++
EOF
cat >expect-graph <<'EOF'
|  abcd | 1000 ++++++++++++++++++++++++++
EOF
while read cmd args
do
	test_expect_success "$cmd --stat=width with big change" '
		git $cmd $args --stat=40 >output
		grep " | " output >actual &&
		test_cmp expect actual
	'

	test_expect_success "$cmd --stat-width=width with big change" '
		git $cmd $args --stat-width=40 >output
		grep " | " output >actual &&
		test_cmp expect actual
	'

	test_expect_success "$cmd --stat-graph-width with big change" '
		git $cmd $args --stat-graph-width=26 >output
		grep " | " output >actual &&
		test_cmp expect actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success "$cmd --stat-width=width --graph with big change" '
		git $cmd $args --stat-width=40 --graph >output
		grep " | " output >actual &&
		test_cmp expect-graph actual
	'

	test_expect_success "$cmd --stat-graph-width --graph with big change" '
		git $cmd $args --stat-graph-width=26 --graph >output
		grep " | " output >actual &&
		test_cmp expect-graph actual
	'
done <<\EOF
format-patch -1 --stdout
diff HEAD^ HEAD --stat
show --stat
log -1 --stat
EOF

test_expect_success 'preparation for long filename tests' '
	cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
	git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
	git commit -m message
'

cat >expect <<'EOF'
 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
EOF
cat >expect-graph <<'EOF'
|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
EOF
while read cmd args
do
	test_expect_success "$cmd --stat=width with big change is more balanced" '
		git $cmd $args --stat-width=60 >output &&
		grep " | " output >actual &&
		test_cmp expect actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success "$cmd --stat=width --graph with big change is balanced" '
		git $cmd $args --stat-width=60 --graph >output &&
		grep " | " output >actual &&
		test_cmp expect-graph actual
	'
done <<\EOF
format-patch -1 --stdout
diff HEAD^ HEAD --stat
show --stat
log -1 --stat
EOF

cat >expect80 <<'EOF'
 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
EOF
cat >expect80-graph <<'EOF'
|  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++
EOF
cat >expect200 <<'EOF'
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
cat >expect200-graph <<'EOF'
|  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
while read verb expect cmd args
do
	test_expect_success "$cmd $verb COLUMNS (long filename)" '
		COLUMNS=200 git $cmd $args >output
		grep " | " output >actual &&
		test_cmp "$expect" actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
		COLUMNS=200 git $cmd $args --graph >output
		grep " | " output >actual &&
		test_cmp "$expect-graph" actual
	'
done <<\EOF
ignores expect80 format-patch -1 --stdout
respects expect200 diff HEAD^ HEAD --stat
respects expect200 show --stat
respects expect200 log -1 --stat
EOF

cat >expect1 <<'EOF'
 ...aaaaaaa | 1000 ++++++
EOF
cat >expect1-graph <<'EOF'
|  ...aaaaaaa | 1000 ++++++
EOF
while read verb expect cmd args
do
	test_expect_success COLUMNS_CAN_BE_1 \
		"$cmd $verb prefix greater than COLUMNS (big change)" '
		COLUMNS=1 git $cmd $args >output
		grep " | " output >actual &&
		test_cmp "$expect" actual
	'

	case "$cmd" in diff|show) continue;; esac

	test_expect_success COLUMNS_CAN_BE_1 \
		"$cmd --graph $verb prefix greater than COLUMNS (big change)" '
		COLUMNS=1 git $cmd $args --graph >output
		grep " | " output >actual &&
		test_cmp "$expect-graph" actual
	'
done <<\EOF
ignores expect80 format-patch -1 --stdout
respects expect1 diff HEAD^ HEAD --stat
respects expect1 show --stat
respects expect1 log -1 --stat
EOF

cat >expect <<'EOF'
 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
test_expect_success 'merge --stat respects COLUMNS (big change)' '
	git checkout -b branch HEAD^^ &&
	COLUMNS=100 git merge --stat --no-ff master^ >output &&
	grep " | " output >actual
	test_cmp expect actual
'

cat >expect <<'EOF'
 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
EOF
test_expect_success 'merge --stat respects COLUMNS (long filename)' '
	COLUMNS=100 git merge --stat --no-ff master >output &&
	grep " | " output >actual
	test_cmp expect actual
'

test_done