Codebase list golang-github-vbauerster-mpb / 7db018c
remove obsolete tests Vladimir Bauer 3 years ago
1 changed file(s) with 0 addition(s) and 84 deletion(s). Raw diff Collapse all Expand all
55 "fmt"
66 "io"
77 "strings"
8 "sync/atomic"
98 "testing"
109 "time"
1110 "unicode/utf8"
198197 }
199198 }
200199
201 func TestBarPanicBeforeComplete(t *testing.T) {
202 var buf bytes.Buffer
203 p := mpb.New(
204 mpb.WithWidth(80),
205 mpb.WithDebugOutput(&buf),
206 mpb.WithOutput(io.Discard),
207 )
208
209 total := 100
210 panicMsg := "Upps!!!"
211 var pCount uint32
212 bar := p.AddBar(int64(total),
213 mpb.PrependDecorators(panicDecorator(panicMsg,
214 func(st decor.Statistics) bool {
215 if st.Current >= 42 {
216 atomic.AddUint32(&pCount, 1)
217 return true
218 }
219 return false
220 },
221 )),
222 )
223
224 bar.IncrBy(total)
225
226 p.Wait()
227
228 if pCount != 1 {
229 t.Errorf("Decorator called after panic %d times, expected 1\n", pCount)
230 }
231
232 barStr := buf.String()
233 if !strings.Contains(barStr, panicMsg) {
234 t.Errorf("%q doesn't contain %q\n", barStr, panicMsg)
235 }
236 }
237
238 func TestBarPanicAfterComplete(t *testing.T) {
239 var buf bytes.Buffer
240 p := mpb.New(
241 mpb.WithWidth(80),
242 mpb.WithDebugOutput(&buf),
243 mpb.WithOutput(io.Discard),
244 )
245
246 total := 100
247 panicMsg := "Upps!!!"
248 var pCount uint32
249 bar := p.AddBar(int64(total),
250 mpb.PrependDecorators(panicDecorator(panicMsg,
251 func(st decor.Statistics) bool {
252 if st.Completed {
253 atomic.AddUint32(&pCount, 1)
254 return true
255 }
256 return false
257 },
258 )),
259 )
260
261 bar.IncrBy(total)
262
263 p.Wait()
264
265 if pCount != 1 {
266 t.Errorf("Decorator called after panic %d times, expected 1\n", pCount)
267 }
268
269 barStr := buf.String()
270 if !strings.Contains(barStr, panicMsg) {
271 t.Errorf("%q doesn't contain %q\n", barStr, panicMsg)
272 }
273 }
274
275200 func TestDecorStatisticsAvailableWidth(t *testing.T) {
276201 var called [2]bool
277202 td1 := func(s decor.Statistics) string {
314239 }
315240 }
316241 }
317
318 func panicDecorator(panicMsg string, cond func(decor.Statistics) bool) decor.Decorator {
319 return decor.Any(func(st decor.Statistics) string {
320 if cond(st) {
321 panic(panicMsg)
322 }
323 return ""
324 })
325 }