Skip to content

Commit 8ebd22e

Browse files
committed
previewer: fix alignment overflow
1 parent e44fe10 commit 8ebd22e

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/ReTest.jl

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ function retest(args::Union{Module,AbstractString,Regex}...;
395395
end
396396

397397
gotprinted = false
398+
align_overflow = 0
398399

399400
previewer = previewchan === nothing ? nothing :
400401
@async begin
@@ -418,6 +419,7 @@ function retest(args::Union{Module,AbstractString,Regex}...;
418419
elseif gotprinted
419420
desc = ""
420421
gotprinted = false
422+
align_overflow = 0
421423
elseif desc != ""
422424
align = format.desc_align
423425
if nworkers() > 1
@@ -434,7 +436,20 @@ function retest(args::Union{Module,AbstractString,Regex}...;
434436
description = " " * description
435437
end
436438
cursor += 1
437-
printstyled('\r', rpad("$description", align, " "), ' ',
439+
440+
# when verbose == 0, we still can print the currently run
441+
# testset, but then its description might be larger than
442+
# `align`, because it was not taken into account for computing
443+
# `align`;
444+
# `align_overflow` computes how many characters do overflow,
445+
# so that the printer can "erase" them later on;
446+
# once we overflow, we don't go back (leftwards) until the
447+
# printer prints
448+
align_overflow =
449+
max(align_overflow, textwidth(description) - align)
450+
printstyled('\r',
451+
rpad("$description", align+align_overflow, " "),
452+
' ',
438453
timer[mod1(cursor, end)];
439454
style...)
440455
end
@@ -453,12 +468,22 @@ function retest(args::Union{Module,AbstractString,Regex}...;
453468
if many || verbose == 0
454469
@assert endswith(module_ts.description, ':')
455470
module_ts.description = chop(module_ts.description, tail=1)
471+
clear_line()
456472
Testset.print_test_results(module_ts, format,
457473
bold=true, hasbroken=hasbroken)
458474
else
459475
nothing
460476
end
461477

478+
# if the previewer overflowed, we must clear the line, otherwise, if
479+
# what we print now isn't as large, leftovers from the previewer
480+
# will be seen
481+
clear_line() = if previewchan !== nothing
482+
# +2: for the final space before spinning wheel and the wheel
483+
print('\r' * ' '^(format.desc_align+align_overflow+2) * '\r')
484+
align_overflow = 0
485+
end
486+
462487
while !finito
463488
rts = take!(outchan)
464489
lock(printlock) do
@@ -470,8 +495,6 @@ function retest(args::Union{Module,AbstractString,Regex}...;
470495
end
471496
end
472497
gotprinted = true
473-
previewchan === nothing ||
474-
print('\r')
475498

476499
if rts === nothing
477500
errored || print_overall()
@@ -481,6 +504,7 @@ function retest(args::Union{Module,AbstractString,Regex}...;
481504
errored && return
482505

483506
if verbose > 0 || rts.anynonpass
507+
clear_line()
484508
Testset.print_test_results(
485509
rts, format;
486510
depth = Int(!rts.overall & isindented(verbose, overall, many)),

0 commit comments

Comments
 (0)