1
+#!/bin/sh
2
+
3
+test_description='progress display'
4
+
5
+. ./test-lib.sh
6
+
7
+show_cr () {
8
+ tr '\015' Q | sed -e "s/Q/<CR>\\$LF/g"
9
+}
10
+
11
+test_expect_success 'simple progress display' '
12
+ cat >expect <<-\EOF &&
13
+ Working hard: 1<CR>
14
+ Working hard: 2<CR>
15
+ Working hard: 5<CR>
16
+ Working hard: 5, done.
17
+ EOF
18
+
19
+ cat >in <<-\EOF &&
20
+ update
21
+ progress 1
22
+ update
23
+ progress 2
24
+ progress 3
25
+ progress 4
26
+ update
27
+ progress 5
28
+ EOF
29
+ test-tool progress "Working hard" <in 2>stderr &&
30
+
31
+ show_cr <stderr >out &&
32
+ test_i18ncmp expect out
33
+'
34
+
35
+test_expect_success 'progress display with total' '
36
+ cat >expect <<-\EOF &&
37
+ Working hard: 33% (1/3)<CR>
38
+ Working hard: 66% (2/3)<CR>
39
+ Working hard: 100% (3/3)<CR>
40
+ Working hard: 100% (3/3), done.
41
+ EOF
42
+
43
+ cat >in <<-\EOF &&
44
+ progress 1
45
+ progress 2
46
+ progress 3
47
+ EOF
48
+ test-tool progress --total=3 "Working hard" <in 2>stderr &&
49
+
50
+ show_cr <stderr >out &&
51
+ test_i18ncmp expect out
52
+'
53
+
54
+test_expect_success 'progress display breaks long lines #1' '
55
+ sed -e "s/Z$//" >expect <<\EOF &&
56
+Working hard.......2.........3.........4.........5.........6: 0% (100/100000)<CR>
57
+Working hard.......2.........3.........4.........5.........6: 1% (1000/100000)<CR>
58
+Working hard.......2.........3.........4.........5.........6: Z
59
+ 10% (10000/100000)<CR>
60
+ 100% (100000/100000)<CR>
61
+ 100% (100000/100000), done.
62
+EOF
63
+
64
+ cat >in <<-\EOF &&
65
+ progress 100
66
+ progress 1000
67
+ progress 10000
68
+ progress 100000
69
+ EOF
70
+ test-tool progress --total=100000 \
71
+ "Working hard.......2.........3.........4.........5.........6" \
72
+ <in 2>stderr &&
73
+
74
+ show_cr <stderr >out &&
75
+ test_i18ncmp expect out
76
+'
77
+
78
+test_expect_success 'progress display breaks long lines #2' '
79
+ # Note: we dont need that many spaces after the title to cover up
80
+ # the last line before breaking the progress line.
81
+ sed -e "s/Z$//" >expect <<\EOF &&
82
+Working hard.......2.........3.........4.........5.........6: 0% (1/100000)<CR>
83
+Working hard.......2.........3.........4.........5.........6: 0% (2/100000)<CR>
84
+Working hard.......2.........3.........4.........5.........6: Z
85
+ 10% (10000/100000)<CR>
86
+ 100% (100000/100000)<CR>
87
+ 100% (100000/100000), done.
88
+EOF
89
+
90
+ cat >in <<-\EOF &&
91
+ update
92
+ progress 1
93
+ update
94
+ progress 2
95
+ progress 10000
96
+ progress 100000
97
+ EOF
98
+ test-tool progress --total=100000 \
99
+ "Working hard.......2.........3.........4.........5.........6" \
100
+ <in 2>stderr &&
101
+
102
+ show_cr <stderr >out &&
103
+ test_i18ncmp expect out
104
+'
105
+
106
+test_expect_success 'progress display breaks long lines #3 - even the first is too long' '
107
+ # Note: we dont actually need any spaces at the end of the title
108
+ # line, because there is no previous progress line to cover up.
109
+ sed -e "s/Z$//" >expect <<\EOF &&
110
+Working hard.......2.........3.........4.........5.........6: Z
111
+ 25% (25000/100000)<CR>
112
+ 50% (50000/100000)<CR>
113
+ 75% (75000/100000)<CR>
114
+ 100% (100000/100000)<CR>
115
+ 100% (100000/100000), done.
116
+EOF
117
+
118
+ cat >in <<-\EOF &&
119
+ progress 25000
120
+ progress 50000
121
+ progress 75000
122
+ progress 100000
123
+ EOF
124
+ test-tool progress --total=100000 \
125
+ "Working hard.......2.........3.........4.........5.........6" \
126
+ <in 2>stderr &&
127
+
128
+ show_cr <stderr >out &&
129
+ test_i18ncmp expect out
130
+'
131
+
132
+test_expect_success 'progress display breaks long lines #4 - title line matches terminal width' '
133
+ cat >expect <<\EOF &&
134
+Working hard.......2.........3.........4.........5.........6.........7.........:
135
+ 25% (25000/100000)<CR>
136
+ 50% (50000/100000)<CR>
137
+ 75% (75000/100000)<CR>
138
+ 100% (100000/100000)<CR>
139
+ 100% (100000/100000), done.
140
+EOF
141
+
142
+ cat >in <<-\EOF &&
143
+ progress 25000
144
+ progress 50000
145
+ progress 75000
146
+ progress 100000
147
+ EOF
148
+ test-tool progress --total=100000 \
149
+ "Working hard.......2.........3.........4.........5.........6.........7........." \
150
+ <in 2>stderr &&
151
+
152
+ show_cr <stderr >out &&
153
+ test_i18ncmp expect out
154
+'
155
+
156
+# Progress counter goes backwards, this should not happen in practice.
157
+test_expect_success 'progress shortens - crazy caller' '
158
+ cat >expect <<-\EOF &&
159
+ Working hard: 10% (100/1000)<CR>
160
+ Working hard: 20% (200/1000)<CR>
161
+ Working hard: 0% (1/1000) <CR>
162
+ Working hard: 100% (1000/1000)<CR>
163
+ Working hard: 100% (1000/1000), done.
164
+ EOF
165
+
166
+ cat >in <<-\EOF &&
167
+ progress 100
168
+ progress 200
169
+ progress 1
170
+ progress 1000
171
+ EOF
172
+ test-tool progress --total=1000 "Working hard" <in 2>stderr &&
173
+
174
+ show_cr <stderr >out &&
175
+ test_i18ncmp expect out
176
+'
177
+
178
+test_expect_success 'progress display with throughput' '
179
+ cat >expect <<-\EOF &&
180
+ Working hard: 10<CR>
181
+ Working hard: 20, 200.00 KiB | 100.00 KiB/s<CR>
182
+ Working hard: 30, 300.00 KiB | 100.00 KiB/s<CR>
183
+ Working hard: 40, 400.00 KiB | 100.00 KiB/s<CR>
184
+ Working hard: 40, 400.00 KiB | 100.00 KiB/s, done.
185
+ EOF
186
+
187
+ cat >in <<-\EOF &&
188
+ throughput 102400 1000
189
+ update
190
+ progress 10
191
+ throughput 204800 2000
192
+ update
193
+ progress 20
194
+ throughput 307200 3000
195
+ update
196
+ progress 30
197
+ throughput 409600 4000
198
+ update
199
+ progress 40
200
+ EOF
201
+ test-tool progress "Working hard" <in 2>stderr &&
202
+
203
+ show_cr <stderr >out &&
204
+ test_i18ncmp expect out
205
+'
206
+
207
+test_expect_success 'progress display with throughput and total' '
208
+ cat >expect <<-\EOF &&
209
+ Working hard: 25% (10/40)<CR>
210
+ Working hard: 50% (20/40), 200.00 KiB | 100.00 KiB/s<CR>
211
+ Working hard: 75% (30/40), 300.00 KiB | 100.00 KiB/s<CR>
212
+ Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s<CR>
213
+ Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s, done.
214
+ EOF
215
+
216
+ cat >in <<-\EOF &&
217
+ throughput 102400 1000
218
+ progress 10
219
+ throughput 204800 2000
220
+ progress 20
221
+ throughput 307200 3000
222
+ progress 30
223
+ throughput 409600 4000
224
+ progress 40
225
+ EOF
226
+ test-tool progress --total=40 "Working hard" <in 2>stderr &&
227
+
228
+ show_cr <stderr >out &&
229
+ test_i18ncmp expect out
230
+'
231
+
232
+test_expect_success 'cover up after throughput shortens' '
233
+ cat >expect <<-\EOF &&
234
+ Working hard: 1<CR>
235
+ Working hard: 2, 800.00 KiB | 400.00 KiB/s<CR>
236
+ Working hard: 3, 1.17 MiB | 400.00 KiB/s <CR>
237
+ Working hard: 4, 1.56 MiB | 400.00 KiB/s<CR>
238
+ Working hard: 4, 1.56 MiB | 400.00 KiB/s, done.
239
+ EOF
240
+
241
+ cat >in <<-\EOF &&
242
+ throughput 409600 1000
243
+ update
244
+ progress 1
245
+ throughput 819200 2000
246
+ update
247
+ progress 2
248
+ throughput 1228800 3000
249
+ update
250
+ progress 3
251
+ throughput 1638400 4000
252
+ update
253
+ progress 4
254
+ EOF
255
+ test-tool progress "Working hard" <in 2>stderr &&
256
+
257
+ show_cr <stderr >out &&
258
+ test_i18ncmp expect out
259
+'
260
+
261
+test_expect_success 'cover up after throughput shortens a lot' '
262
+ cat >expect <<-\EOF &&
263
+ Working hard: 1<CR>
264
+ Working hard: 2, 1000.00 KiB | 1000.00 KiB/s<CR>
265
+ Working hard: 3, 3.00 MiB | 1.50 MiB/s <CR>
266
+ Working hard: 3, 3.00 MiB | 1024.00 KiB/s, done.
267
+ EOF
268
+
269
+ cat >in <<-\EOF &&
270
+ throughput 1 1000
271
+ update
272
+ progress 1
273
+ throughput 1024000 2000
274
+ update
275
+ progress 2
276
+ throughput 3145728 3000
277
+ update
278
+ progress 3
279
+ EOF
280
+ test-tool progress "Working hard" <in 2>stderr &&
281
+
282
+ show_cr <stderr >out &&
283
+ test_i18ncmp expect out
284
+'
285
+
286
+test_done