Skip to content

Commit 0e99bf5

Browse files
committed
previewer: also print IDs when appropriate
This is to avoid a shift between previewing and actual result printing.
1 parent 06661c4 commit 0e99bf5

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

src/ReTest.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ include("hijack.jl")
4747
include("watch.jl")
4848
include("patterns.jl")
4949

50-
using .Testset: Testset, Format
50+
using .Testset: Testset, Format, print_id
5151

5252

5353
# * TestsetExpr
@@ -723,7 +723,7 @@ function retest(@nospecialize(args::ArgType...);
723723
printlock = ReentrantLock()
724724
previewchan =
725725
if stdout isa Base.TTY && (nthreads() > 1 && VERSION >= v"1.3" || nprocs() > 1)
726-
RemoteChannel(() -> Channel{Maybe{String}}(Inf))
726+
RemoteChannel(() -> Channel{Maybe{Tuple{Int64,String}}}(Inf))
727727
# needs to be "remote" in the case nprocs() == 2, as then nworkers() == 1,
728728
# which means the one remote worker will put descriptions on previewchan
729729
# (if nworkers() > 1, descriptions are not put because we can't predict
@@ -749,29 +749,35 @@ function retest(@nospecialize(args::ArgType...);
749749
align_overflow = 0
750750

751751
function take_latest!(previewchan)
752-
local desc
752+
local id_desc
753753
while isready(previewchan)
754754
# printer/previewer can't take! it, as we locked
755-
desc = take!(previewchan)
755+
id_desc = take!(previewchan)
756+
end
757+
if @isdefined(id_desc)
758+
something(id_desc, (Int64(0), nothing))
759+
else
760+
(Int64(0), "")
756761
end
757-
@isdefined(desc) ? desc : ""
758762
end
759763

760764
previewer = previewchan === nothing ? nothing :
761765
@async try
762766
timer = ['|', '/', '-', '\\']
763767
cursor = 0
764768
desc = ""
769+
id = Int64(0)
765770
finito = false
766771

767772
while !finito && !interrupted[]
768773
lock(printlock) do
769-
newdesc = take_latest!(previewchan)
774+
newid, newdesc = take_latest!(previewchan)
770775
if newdesc === nothing
771776
finito = true
772777
return # no need to sleep before looping
773778
elseif newdesc != ""
774779
desc = newdesc
780+
id = newid
775781
cursor = 0
776782
gotprinted = false
777783
elseif gotprinted
@@ -805,8 +811,9 @@ function retest(@nospecialize(args::ArgType...);
805811
# printer prints
806812
align_overflow =
807813
max(align_overflow, textwidth(description) - align)
808-
printstyled('\r',
809-
rpad("$description", align+align_overflow, " "),
814+
print('\r')
815+
print_id(id, maxidw[])
816+
printstyled(rpad("$description", align+align_overflow, " "),
810817
' ',
811818
timer[mod1(cursor, end)];
812819
style...)
@@ -857,7 +864,7 @@ function retest(@nospecialize(args::ArgType...);
857864
rts = take!(outchan)
858865
lock(printlock) do
859866
if previewchan !== nothing
860-
desc = take_latest!(previewchan)
867+
id, desc = take_latest!(previewchan)
861868
if desc === nothing
862869
# keep `nothing` in so that the previewer knows to terminate
863870
put!(previewchan, nothing)
@@ -967,7 +974,7 @@ function retest(@nospecialize(args::ArgType...);
967974
desc = "\0" * desc
968975
# even when nworkers() >= 2, we inform the previewer that
969976
# computation is gonna happen, so the wheel can start spinning
970-
put!(previewchan, desc)
977+
put!(previewchan, (ts.id, desc))
971978
end
972979

973980
chan = (out=outchan, compute=computechan, preview=previewchan)
@@ -1351,10 +1358,7 @@ function dryrun(mod::Module, ts::TestsetExpr, pat::Pattern, align::Int=0, parent
13511358

13521359
res = get(ts.pastresults, subject, nothing)
13531360
if show
1354-
if maxidw > 0 # width (ndigits) of max id; <= 0 means ids not printed
1355-
printstyled(lpad(ts.id, maxidw), "| ", color = :light_black, bold=true)
1356-
end
1357-
1361+
print_id(ts.id, maxidw)
13581362
printstyled(' '^align, desc, color = desc isa String ? :normal : Base.warn_color())
13591363

13601364
if repeated !== nothing

src/testset.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ end
320320

321321
anyfailed(ts::ReTestSet) = any(t -> t isa Union{Fail,Error}, ts.results)
322322

323+
print_id(id, maxidw) =
324+
if maxidw > 0 # width (ndigits) of max id; <= 0 means ids not printed
325+
if id != 0
326+
printstyled(lpad(id, maxidw), "| ", color = :light_black, bold=true)
327+
else
328+
print(' '^(maxidw+2))
329+
end
330+
end
331+
323332
# Recursive function that prints out the results at each level of
324333
# the tree of test sets
325334
function print_counts(ts::ReTestSet, fmt::Format, depth, align,
@@ -333,14 +342,7 @@ function print_counts(ts::ReTestSet, fmt::Format, depth, align,
333342
# the test results appear above each other
334343

335344
style = bold ? (bold=bold, color=:white) : NamedTuple()
336-
if maxidw > 0
337-
if ts.id != 0
338-
printstyled(lpad(ts.id, maxidw), "| ", color = :light_black, bold=true)
339-
else
340-
print(' '^(maxidw+2))
341-
end
342-
end
343-
345+
print_id(ts.id, maxidw)
344346
printstyled(rpad(string(" "^depth, ts.description), align, " "); style...)
345347

346348
np = passes + c_passes
@@ -498,7 +500,7 @@ function testset_beginend(mod::Module, isfinal::Bool, pat::Pattern, id::Int64, d
498500
if !$isfinal || matches($pat, ts.subject, ts)
499501
local ret
500502
if nworkers() == 1 && get_testset_depth() == 0 && $(chan.preview) !== nothing
501-
put!($(chan.preview), $desc)
503+
put!($(chan.preview), ($id, $desc))
502504
end
503505
push_testset(ts)
504506
# we reproduce the logic of guardseed, but this function
@@ -563,7 +565,7 @@ function testset_forloop(mod::Module, isfinal::Bool, pat::Pattern, id::Int64,
563565
end
564566
ts = ts0
565567
if nworkers() == 1 && get_testset_depth() == 0 && $(chan.preview) !== nothing
566-
put!($(chan.preview), ts.description)
568+
put!($(chan.preview), ($id, ts.description))
567569
end
568570
push_testset(ts)
569571
first_iteration = false

0 commit comments

Comments
 (0)