clone_submodule: avoid using `access()` on directories
[git.git] / t / t0500-progress-display.sh
blob1eb3a8306ba15b3e782b940f605afa8ec551ec8c
1 #!/bin/sh
3 test_description='progress display'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 show_cr () {
9 tr '\015' Q | sed -e "s/Q/<CR>\\$LF/g"
12 test_expect_success 'simple progress display' '
13 cat >expect <<-\EOF &&
14 Working hard: 1<CR>
15 Working hard: 2<CR>
16 Working hard: 5<CR>
17 Working hard: 5, done.
18 EOF
20 cat >in <<-\EOF &&
21 start 0
22 update
23 progress 1
24 update
25 progress 2
26 progress 3
27 progress 4
28 update
29 progress 5
30 stop
31 EOF
32 test-tool progress <in 2>stderr &&
34 show_cr <stderr >out &&
35 test_cmp expect out
38 test_expect_success 'progress display with total' '
39 cat >expect <<-\EOF &&
40 Working hard: 33% (1/3)<CR>
41 Working hard: 66% (2/3)<CR>
42 Working hard: 100% (3/3)<CR>
43 Working hard: 100% (3/3), done.
44 EOF
46 cat >in <<-\EOF &&
47 start 3
48 progress 1
49 progress 2
50 progress 3
51 stop
52 EOF
53 test-tool progress <in 2>stderr &&
55 show_cr <stderr >out &&
56 test_cmp expect out
59 test_expect_success 'progress display breaks long lines #1' '
60 sed -e "s/Z$//" >expect <<\EOF &&
61 Working hard.......2.........3.........4.........5.........6: 0% (100/100000)<CR>
62 Working hard.......2.........3.........4.........5.........6: 1% (1000/100000)<CR>
63 Working hard.......2.........3.........4.........5.........6: Z
64 10% (10000/100000)<CR>
65 100% (100000/100000)<CR>
66 100% (100000/100000), done.
67 EOF
69 cat >in <<-\EOF &&
70 start 100000 Working hard.......2.........3.........4.........5.........6
71 progress 100
72 progress 1000
73 progress 10000
74 progress 100000
75 stop
76 EOF
77 test-tool progress <in 2>stderr &&
79 show_cr <stderr >out &&
80 test_cmp expect out
83 test_expect_success 'progress display breaks long lines #2' '
84 # Note: we do not need that many spaces after the title to cover up
85 # the last line before breaking the progress line.
86 sed -e "s/Z$//" >expect <<\EOF &&
87 Working hard.......2.........3.........4.........5.........6: 0% (1/100000)<CR>
88 Working hard.......2.........3.........4.........5.........6: 0% (2/100000)<CR>
89 Working hard.......2.........3.........4.........5.........6: Z
90 10% (10000/100000)<CR>
91 100% (100000/100000)<CR>
92 100% (100000/100000), done.
93 EOF
95 cat >in <<-\EOF &&
96 start 100000 Working hard.......2.........3.........4.........5.........6
97 update
98 progress 1
99 update
100 progress 2
101 progress 10000
102 progress 100000
103 stop
105 test-tool progress <in 2>stderr &&
107 show_cr <stderr >out &&
108 test_cmp expect out
111 test_expect_success 'progress display breaks long lines #3 - even the first is too long' '
112 # Note: we do not actually need any spaces at the end of the title
113 # line, because there is no previous progress line to cover up.
114 sed -e "s/Z$//" >expect <<\EOF &&
115 Working hard.......2.........3.........4.........5.........6: Z
116 25% (25000/100000)<CR>
117 50% (50000/100000)<CR>
118 75% (75000/100000)<CR>
119 100% (100000/100000)<CR>
120 100% (100000/100000), done.
123 cat >in <<-\EOF &&
124 start 100000 Working hard.......2.........3.........4.........5.........6
125 progress 25000
126 progress 50000
127 progress 75000
128 progress 100000
129 stop
131 test-tool progress <in 2>stderr &&
133 show_cr <stderr >out &&
134 test_cmp expect out
137 test_expect_success 'progress display breaks long lines #4 - title line matches terminal width' '
138 cat >expect <<\EOF &&
139 Working hard.......2.........3.........4.........5.........6.........7.........:
140 25% (25000/100000)<CR>
141 50% (50000/100000)<CR>
142 75% (75000/100000)<CR>
143 100% (100000/100000)<CR>
144 100% (100000/100000), done.
147 cat >in <<-\EOF &&
148 start 100000 Working hard.......2.........3.........4.........5.........6.........7.........
149 progress 25000
150 progress 50000
151 progress 75000
152 progress 100000
153 stop
155 test-tool progress <in 2>stderr &&
157 show_cr <stderr >out &&
158 test_cmp expect out
161 # Progress counter goes backwards, this should not happen in practice.
162 test_expect_success 'progress shortens - crazy caller' '
163 cat >expect <<-\EOF &&
164 Working hard: 10% (100/1000)<CR>
165 Working hard: 20% (200/1000)<CR>
166 Working hard: 0% (1/1000) <CR>
167 Working hard: 100% (1000/1000)<CR>
168 Working hard: 100% (1000/1000), done.
171 cat >in <<-\EOF &&
172 start 1000
173 progress 100
174 progress 200
175 progress 1
176 progress 1000
177 stop
179 test-tool progress <in 2>stderr &&
181 show_cr <stderr >out &&
182 test_cmp expect out
185 test_expect_success 'progress display with throughput' '
186 cat >expect <<-\EOF &&
187 Working hard: 10<CR>
188 Working hard: 20, 200.00 KiB | 100.00 KiB/s<CR>
189 Working hard: 30, 300.00 KiB | 100.00 KiB/s<CR>
190 Working hard: 40, 400.00 KiB | 100.00 KiB/s<CR>
191 Working hard: 40, 400.00 KiB | 100.00 KiB/s, done.
194 cat >in <<-\EOF &&
195 start 0
196 throughput 102400 1000
197 update
198 progress 10
199 throughput 204800 2000
200 update
201 progress 20
202 throughput 307200 3000
203 update
204 progress 30
205 throughput 409600 4000
206 update
207 progress 40
208 stop
210 test-tool progress <in 2>stderr &&
212 show_cr <stderr >out &&
213 test_cmp expect out
216 test_expect_success 'progress display with throughput and total' '
217 cat >expect <<-\EOF &&
218 Working hard: 25% (10/40)<CR>
219 Working hard: 50% (20/40), 200.00 KiB | 100.00 KiB/s<CR>
220 Working hard: 75% (30/40), 300.00 KiB | 100.00 KiB/s<CR>
221 Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s<CR>
222 Working hard: 100% (40/40), 400.00 KiB | 100.00 KiB/s, done.
225 cat >in <<-\EOF &&
226 start 40
227 throughput 102400 1000
228 progress 10
229 throughput 204800 2000
230 progress 20
231 throughput 307200 3000
232 progress 30
233 throughput 409600 4000
234 progress 40
235 stop
237 test-tool progress <in 2>stderr &&
239 show_cr <stderr >out &&
240 test_cmp expect out
243 test_expect_success 'cover up after throughput shortens' '
244 cat >expect <<-\EOF &&
245 Working hard: 1<CR>
246 Working hard: 2, 800.00 KiB | 400.00 KiB/s<CR>
247 Working hard: 3, 1.17 MiB | 400.00 KiB/s <CR>
248 Working hard: 4, 1.56 MiB | 400.00 KiB/s<CR>
249 Working hard: 4, 1.56 MiB | 400.00 KiB/s, done.
252 cat >in <<-\EOF &&
253 start 0
254 throughput 409600 1000
255 update
256 progress 1
257 throughput 819200 2000
258 update
259 progress 2
260 throughput 1228800 3000
261 update
262 progress 3
263 throughput 1638400 4000
264 update
265 progress 4
266 stop
268 test-tool progress <in 2>stderr &&
270 show_cr <stderr >out &&
271 test_cmp expect out
274 test_expect_success 'cover up after throughput shortens a lot' '
275 cat >expect <<-\EOF &&
276 Working hard: 1<CR>
277 Working hard: 2, 1000.00 KiB | 1000.00 KiB/s<CR>
278 Working hard: 3, 3.00 MiB | 1.50 MiB/s <CR>
279 Working hard: 3, 3.00 MiB | 1024.00 KiB/s, done.
282 cat >in <<-\EOF &&
283 start 0
284 throughput 1 1000
285 update
286 progress 1
287 throughput 1024000 2000
288 update
289 progress 2
290 throughput 3145728 3000
291 update
292 progress 3
293 stop
295 test-tool progress <in 2>stderr &&
297 show_cr <stderr >out &&
298 test_cmp expect out
301 test_expect_success 'progress generates traces' '
302 cat >in <<-\EOF &&
303 start 40
304 throughput 102400 1000
305 update
306 progress 10
307 throughput 204800 2000
308 update
309 progress 20
310 throughput 307200 3000
311 update
312 progress 30
313 throughput 409600 4000
314 update
315 progress 40
316 stop
319 GIT_TRACE2_EVENT="$(pwd)/trace.event" test-tool progress \
320 <in 2>stderr &&
322 # t0212/parse_events.perl intentionally omits regions and data.
323 test_region progress "Working hard" trace.event &&
324 grep "\"key\":\"total_objects\",\"value\":\"40\"" trace.event &&
325 grep "\"key\":\"total_bytes\",\"value\":\"409600\"" trace.event
328 test_expect_success 'progress generates traces: stop / start' '
329 cat >in <<-\EOF &&
330 start 0
331 stop
334 GIT_TRACE2_EVENT="$PWD/trace-startstop.event" test-tool progress \
335 <in 2>stderr &&
336 test_region progress "Working hard" trace-startstop.event
339 test_expect_success 'progress generates traces: start without stop' '
340 cat >in <<-\EOF &&
341 start 0
344 GIT_TRACE2_EVENT="$PWD/trace-start.event" \
345 LSAN_OPTIONS=detect_leaks=0 \
346 test-tool progress \
347 <in 2>stderr &&
348 grep region_enter.*progress trace-start.event &&
349 ! grep region_leave.*progress trace-start.event
352 test_expect_success 'progress generates traces: stop without start' '
353 cat >in <<-\EOF &&
354 stop
357 GIT_TRACE2_EVENT="$PWD/trace-stop.event" test-tool progress \
358 <in 2>stderr &&
359 ! grep region_enter.*progress trace-stop.event &&
360 ! grep region_leave.*progress trace-stop.event
363 test_expect_success 'progress generates traces: start with active progress bar (no stops)' '
364 cat >in <<-\EOF &&
365 start 0 One
366 start 0 Two
369 GIT_TRACE2_EVENT="$PWD/trace-2start.event" \
370 LSAN_OPTIONS=detect_leaks=0 \
371 test-tool progress \
372 <in 2>stderr &&
373 grep region_enter.*progress.*One trace-2start.event &&
374 grep region_enter.*progress.*Two trace-2start.event &&
375 ! grep region_leave trace-2start.event
378 test_done