@@ -21,7 +21,10 @@ use std::{
21
21
num:: NonZeroUsize ,
22
22
panic:: { AssertUnwindSafe , RefUnwindSafe } ,
23
23
path:: { Path , PathBuf } ,
24
- sync:: { atomic:: AtomicBool , Arc } ,
24
+ sync:: {
25
+ atomic:: { AtomicUsize , Ordering } ,
26
+ Arc ,
27
+ } ,
25
28
thread:: JoinHandle ,
26
29
time:: Duration ,
27
30
} ;
@@ -222,23 +225,31 @@ impl Text {
222
225
* done = true ;
223
226
let spinner = spinner. clone ( ) ;
224
227
228
+ let print = new_msg. is_some ( ) ;
229
+
225
230
if let Some ( new_msg) = new_msg {
226
231
spinner. finish_with_message ( new_msg) ;
227
- let parent = children[ "" ] . 0 . clone ( ) ;
228
- if !msg. is_empty ( ) {
229
- parent. inc ( 1 ) ;
230
- }
231
- if children. values ( ) . all ( |& ( _, done) | done) {
232
- bars. remove ( & parent) ;
232
+ } else {
233
+ spinner. finish ( ) ;
234
+ }
235
+ let parent = children[ "" ] . 0 . clone ( ) ;
236
+ if !msg. is_empty ( ) {
237
+ parent. inc ( 1 ) ;
238
+ }
239
+ if children. values ( ) . all ( |& ( _, done) | done) {
240
+ bars. remove ( & parent) ;
241
+ if print {
233
242
bars. println ( format ! (
234
243
"{} {}" ,
235
244
parent. prefix( ) ,
236
245
parent. message( )
237
246
) )
238
247
. unwrap ( ) ;
239
- for ( msg, ( child, _) ) in children. iter ( ) {
240
- if !msg. is_empty ( ) {
241
- bars. remove ( child) ;
248
+ }
249
+ for ( msg, ( child, _) ) in children. iter ( ) {
250
+ if !msg. is_empty ( ) {
251
+ bars. remove ( child) ;
252
+ if print {
242
253
bars. println ( format ! (
243
254
" {} {}" ,
244
255
child. prefix( ) ,
@@ -248,8 +259,6 @@ impl Text {
248
259
}
249
260
}
250
261
}
251
- } else {
252
- spinner. finish_and_clear ( ) ;
253
262
}
254
263
}
255
264
@@ -323,7 +332,8 @@ impl Text {
323
332
}
324
333
if let Some ( progress) = progress {
325
334
progress. tick ( ) ;
326
- assert ! ( progress. is_finished( ) ) ;
335
+ progress. finish ( ) ;
336
+ assert_eq ! ( Some ( progress. position( ) ) , progress. length( ) ) ;
327
337
}
328
338
} ) ;
329
339
Self {
@@ -369,14 +379,20 @@ struct TextTest {
369
379
parent : String ,
370
380
path : PathBuf ,
371
381
revision : String ,
372
- first : AtomicBool ,
382
+ /// Increased whenever a revision or sub-path is registered
383
+ /// Decreased whenever `done` is called
384
+ /// On increase from 0 to 1, adds 1 to the progress bar length
385
+ /// On decrease from 1 to 0, removes 1 from progress bar length
386
+ inc_counter : Arc < AtomicUsize > ,
373
387
style : RevisionStyle ,
374
388
}
375
389
376
390
impl TestStatus for TextTest {
377
391
fn done ( & self , result : & TestResult ) {
378
392
let new_leftover_msg = if self . text . is_quiet_output ( ) {
379
- self . text . sender . send ( Msg :: Inc ) . unwrap ( ) ;
393
+ if self . inc_counter . fetch_sub ( 1 , Ordering :: Relaxed ) == 1 {
394
+ self . text . sender . send ( Msg :: Inc ) . unwrap ( ) ;
395
+ }
380
396
None
381
397
} else {
382
398
let result = match result {
@@ -466,18 +482,16 @@ impl TestStatus for TextTest {
466
482
}
467
483
468
484
fn for_revision ( & self , revision : & str , style : RevisionStyle ) -> Box < dyn TestStatus > {
469
- if !self . first . swap ( false , std:: sync:: atomic:: Ordering :: Relaxed )
470
- && self . text . is_quiet_output ( )
471
- {
472
- self . text . sender . send ( Msg :: IncLength ) . unwrap ( ) ;
485
+ if self . text . is_quiet_output ( ) {
486
+ self . inc_counter . fetch_add ( 1 , Ordering :: Relaxed ) ;
473
487
}
474
488
475
489
let text = Self {
476
490
text : self . text . clone ( ) ,
477
491
path : self . path . clone ( ) ,
478
492
parent : self . parent . clone ( ) ,
479
493
revision : revision. to_owned ( ) ,
480
- first : AtomicBool :: new ( false ) ,
494
+ inc_counter : self . inc_counter . clone ( ) ,
481
495
style,
482
496
} ;
483
497
self . text
@@ -496,12 +510,16 @@ impl TestStatus for TextTest {
496
510
}
497
511
498
512
fn for_path ( & self , path : & Path ) -> Box < dyn TestStatus > {
513
+ if self . text . is_quiet_output ( ) {
514
+ self . inc_counter . fetch_add ( 1 , Ordering :: Relaxed ) ;
515
+ }
516
+
499
517
let text = Self {
500
518
text : self . text . clone ( ) ,
501
519
path : path. to_path_buf ( ) ,
502
520
parent : self . parent . clone ( ) ,
503
521
revision : String :: new ( ) ,
504
- first : AtomicBool :: new ( false ) ,
522
+ inc_counter : self . inc_counter . clone ( ) ,
505
523
style : RevisionStyle :: Show ,
506
524
} ;
507
525
@@ -530,7 +548,7 @@ impl StatusEmitter for Text {
530
548
parent : display ( & path) ,
531
549
path,
532
550
revision : String :: new ( ) ,
533
- first : AtomicBool :: new ( true ) ,
551
+ inc_counter : Default :: default ( ) ,
534
552
style : RevisionStyle :: Show ,
535
553
} )
536
554
}
0 commit comments