summaryrefslogtreecommitdiff
path: root/t/t0500-progress-display.sh
blob: 1ed1df351cb178562d21ab204f2b5c85d3206ba2 (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
#!/bin/sh

test_description='progress display'

. ./test-lib.sh

show_cr () {
	tr '\015' Q | sed -e "s/Q/<CR>\\$LF/g"
}

test_expect_success 'simple progress display' '
	cat >expect <<-\EOF &&
	Working hard: 1<CR>
	Working hard: 2<CR>
	Working hard: 5<CR>
	Working hard: 5, done.
	EOF

	cat >in <<-\EOF &&
	update
	progress 1
	update
	progress 2
	progress 3
	progress 4
	update
	progress 5
	EOF
	test-tool progress "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display with total' '
	cat >expect <<-\EOF &&
	Working hard:  33% (1/3)<CR>
	Working hard:  66% (2/3)<CR>
	Working hard: 100% (3/3)<CR>
	Working hard: 100% (3/3), done.
	EOF

	cat >in <<-\EOF &&
	progress 1
	progress 2
	progress 3
	EOF
	test-tool progress --total=3 "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display breaks long lines #1' '
	sed -e "s/Z$//" >expect <<\EOF &&
Working hard.......2.........3.........4.........5.........6:   0% (100/100000)<CR>
Working hard.......2.........3.........4.........5.........6:   1% (1000/100000)<CR>
Working hard.......2.........3.........4.........5.........6:                   Z
   10% (10000/100000)<CR>
  100% (100000/100000)<CR>
  100% (100000/100000), done.
EOF

	cat >in <<-\EOF &&
	progress 100
	progress 1000
	progress 10000
	progress 100000
	EOF
	test-tool progress --total=100000 \
		"Working hard.......2.........3.........4.........5.........6" \
		<in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display breaks long lines #2' '
	# Note: we do not need that many spaces after the title to cover up
	# the last line before breaking the progress line.
	sed -e "s/Z$//" >expect <<\EOF &&
Working hard.......2.........3.........4.........5.........6:   0% (1/100000)<CR>
Working hard.......2.........3.........4.........5.........6:   0% (2/100000)<CR>
Working hard.......2.........3.........4.........5.........6:                   Z
   10% (10000/100000)<CR>
  100% (100000/100000)<CR>
  100% (100000/100000), done.
EOF

	cat >in <<-\EOF &&
	update
	progress 1
	update
	progress 2
	progress 10000
	progress 100000
	EOF
	test-tool progress --total=100000 \
		"Working hard.......2.........3.........4.........5.........6" \
		<in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display breaks long lines #3 - even the first is too long' '
	# Note: we do not actually need any spaces at the end of the title
	# line, because there is no previous progress line to cover up.
	sed -e "s/Z$//" >expect <<\EOF &&
Working hard.......2.........3.........4.........5.........6:                   Z
   25% (25000/100000)<CR>
   50% (50000/100000)<CR>
   75% (75000/100000)<CR>
  100% (100000/100000)<CR>
  100% (100000/100000), done.
EOF

	cat >in <<-\EOF &&
	progress 25000
	progress 50000
	progress 75000
	progress 100000
	EOF
	test-tool progress --total=100000 \
		"Working hard.......2.........3.........4.........5.........6" \
		<in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display breaks long lines #4 - title line matches terminal width' '
	cat >expect <<\EOF &&
Working hard.......2.........3.........4.........5.........6.........7.........:
   25% (25000/100000)<CR>
   50% (50000/100000)<CR>
   75% (75000/100000)<CR>
  100% (100000/100000)<CR>
  100% (100000/100000), done.
EOF

	cat >in <<-\EOF &&
	progress 25000
	progress 50000
	progress 75000
	progress 100000
	EOF
	test-tool progress --total=100000 \
		"Working hard.......2.........3.........4.........5.........6.........7........." \
		<in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

# Progress counter goes backwards, this should not happen in practice.
test_expect_success 'progress shortens - crazy caller' '
	cat >expect <<-\EOF &&
	Working hard:  10% (100/1000)<CR>
	Working hard:  20% (200/1000)<CR>
	Working hard:   0% (1/1000)  <CR>
	Working hard: 100% (1000/1000)<CR>
	Working hard: 100% (1000/1000), done.
	EOF

	cat >in <<-\EOF &&
	progress 100
	progress 200
	progress 1
	progress 1000
	EOF
	test-tool progress --total=1000 "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display with throughput' '
	cat >expect <<-\EOF &&
	Working hard: 10<CR>
	Working hard: 20, 200.00 KiB | 100.00 KiB/s<CR>
	Working hard: 30, 300.00 KiB | 100.00 KiB/s<CR>
	Working hard: 40, 400.00 KiB | 100.00 KiB/s<CR>
	Working hard: 40, 400.00 KiB | 100.00 KiB/s, done.
	EOF

	cat >in <<-\EOF &&
	throughput 102400 1000
	update
	progress 10
	throughput 204800 2000
	update
	progress 20
	throughput 307200 3000
	update
	progress 30
	throughput 409600 4000
	update
	progress 40
	EOF
	test-tool progress "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress display with throughput and total' '
	cat >expect <<-\EOF &&
	Working hard:  25% (10/40)<CR>
	Working hard:  50% (20/40), 200.00 KiB | 100.00 KiB/s<CR>
	Working hard:  75% (30/40), 300.00 KiB | 100.00 KiB/s<CR>
	Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s<CR>
	Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s, done.
	EOF

	cat >in <<-\EOF &&
	throughput 102400 1000
	progress 10
	throughput 204800 2000
	progress 20
	throughput 307200 3000
	progress 30
	throughput 409600 4000
	progress 40
	EOF
	test-tool progress --total=40 "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'cover up after throughput shortens' '
	cat >expect <<-\EOF &&
	Working hard: 1<CR>
	Working hard: 2, 800.00 KiB | 400.00 KiB/s<CR>
	Working hard: 3, 1.17 MiB | 400.00 KiB/s  <CR>
	Working hard: 4, 1.56 MiB | 400.00 KiB/s<CR>
	Working hard: 4, 1.56 MiB | 400.00 KiB/s, done.
	EOF

	cat >in <<-\EOF &&
	throughput 409600 1000
	update
	progress 1
	throughput 819200 2000
	update
	progress 2
	throughput 1228800 3000
	update
	progress 3
	throughput 1638400 4000
	update
	progress 4
	EOF
	test-tool progress "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'cover up after throughput shortens a lot' '
	cat >expect <<-\EOF &&
	Working hard: 1<CR>
	Working hard: 2, 1000.00 KiB | 1000.00 KiB/s<CR>
	Working hard: 3, 3.00 MiB | 1.50 MiB/s      <CR>
	Working hard: 3, 3.00 MiB | 1024.00 KiB/s, done.
	EOF

	cat >in <<-\EOF &&
	throughput 1 1000
	update
	progress 1
	throughput 1024000 2000
	update
	progress 2
	throughput 3145728 3000
	update
	progress 3
	EOF
	test-tool progress "Working hard" <in 2>stderr &&

	show_cr <stderr >out &&
	test_i18ncmp expect out
'

test_expect_success 'progress generates traces' '
	cat >in <<-\EOF &&
	throughput 102400 1000
	update
	progress 10
	throughput 204800 2000
	update
	progress 20
	throughput 307200 3000
	update
	progress 30
	throughput 409600 4000
	update
	progress 40
	EOF

	GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress --total=40 \
		"Working hard" <in 2>stderr &&

	# t0212/parse_events.perl intentionally omits regions and data.
	grep -e "region_enter" -e "\"category\":\"progress\"" trace.event &&
	grep -e "region_leave" -e "\"category\":\"progress\"" trace.event &&
	grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event &&
	grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event
'

test_done