Skip to content

Commit e19e4f6

Browse files
committed
more precise alignment, when module header is not printed
1 parent 0eef038 commit e19e4f6

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/ReTest.jl

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -590,21 +590,18 @@ function retest(@nospecialize(args::ArgType...);
590590

591591
implicitmodules, modules, verbose = process_args(args; verbose=verbose, shuffle=shuffle,
592592
recursive=recursive, load=load)
593-
# overall: print header for each module, and "Overall" summary for all modules
593+
# overall: print header for each module, and probably "Overall" summary for all modules
594594
overall = length(modules) > 1
595-
moduleheader = overall | implicitmodules
595+
module_header = overall | implicitmodules
596596
root = Testset.ReTestSet(Main, "Overall", overall=true)
597597

598598
maxidw = Ref{Int}(0) # visual width for showing IDs (Ref for mutability in hack below)
599-
tests_descs_hasbrokens = fetchtests.(modules, verbose, moduleheader, Ref(maxidw);
599+
tests_descs_hasbrokens = fetchtests.(modules, verbose, module_header, Ref(maxidw);
600600
strict=strict, dup=dup, static=static)
601601
isempty(tests_descs_hasbrokens) &&
602602
throw(ArgumentError("no modules using ReTest could be found"))
603603

604604
alltests = first.(tests_descs_hasbrokens)
605-
descwidth = max(textwidth(root.description),
606-
maximum(x->x[2], tests_descs_hasbrokens))
607-
format = Format(stats, descwidth)
608605
hasbroken = any(last.(tests_descs_hasbrokens))
609606

610607
emptymods = findall(isempty, alltests)
@@ -623,6 +620,13 @@ function retest(@nospecialize(args::ArgType...);
623620
hasinteger(pat)
624621
end)
625622

623+
descwidth = maximum(x->x[2], tests_descs_hasbrokens)
624+
if nmodules > 1 # might be different to overall, if !isempty(emptymods)
625+
# this is the condition for printing "Overall" summary
626+
descwidth = max(descwidth, textwidth(root.description))
627+
end
628+
format = Format(stats, descwidth)
629+
626630
maxidw[] = id ? maxidw[] : 0
627631

628632
for imod in eachindex(modules)
@@ -634,13 +638,13 @@ function retest(@nospecialize(args::ArgType...);
634638
shuffle!(tests)
635639

636640
if dry
637-
if moduleheader
641+
if module_header
638642
imod > 1 && verbose > 0 &&
639643
println()
640644
printstyled(mod, '\n', bold=true)
641645
end
642646
if verbose > 0
643-
foreach(ts -> dryrun(mod, ts, pat, id ? 0 : moduleheader*2,
647+
foreach(ts -> dryrun(mod, ts, pat, id ? 0 : module_header*2,
644648
maxidw = id ? maxidw[] : 0),
645649
tests)
646650
end
@@ -756,7 +760,7 @@ function retest(@nospecialize(args::ArgType...);
756760
description = desc
757761
style = NamedTuple()
758762
end
759-
if isindented(verbose, moduleheader, many)
763+
if isindented(verbose, module_header, many)
760764
description = " " * description
761765
end
762766
cursor += 1
@@ -799,7 +803,7 @@ function retest(@nospecialize(args::ArgType...);
799803
finito = false
800804

801805
print_overall() =
802-
if many || verbose == 0
806+
if module_summary(verbose, many)
803807
@assert endswith(module_ts.description, ':')
804808
module_ts.description = chop(module_ts.description, tail=1)
805809
clear_line()
@@ -843,7 +847,7 @@ function retest(@nospecialize(args::ArgType...);
843847
Testset.print_test_results(
844848
rts, format;
845849
depth = Int(!rts.overall &
846-
isindented(verbose, moduleheader, many)),
850+
isindented(verbose, module_header, many)),
847851
bold = rts.overall | !many,
848852
hasbroken=hasbroken,
849853
maxidw=maxidw[]
@@ -870,8 +874,8 @@ function retest(@nospecialize(args::ArgType...);
870874

871875
ndone = 0
872876

873-
if moduleheader
874-
# + if moduleheader, we print the module as a header, to know where the currently
877+
if module_header
878+
# + if module_header, we print the module as a header, to know where the currently
875879
# printed testsets belong
876880
ntests += 1
877881
put!(outchan, module_ts) # printer task will take care of feeding computechan
@@ -1250,7 +1254,7 @@ function update_TESTED_MODULES!(double_check::Bool=false)
12501254
TESTED_MODULES
12511255
end
12521256

1253-
function fetchtests((mod, pat), verbose, moduleheader, maxidw; static, strict, dup)
1257+
function fetchtests((mod, pat), verbose, module_header, maxidw; static, strict, dup)
12541258
tests = updatetests!(mod, dup)
12551259
descwidth = 0
12561260
hasbroken = false
@@ -1270,16 +1274,21 @@ function fetchtests((mod, pat), verbose, moduleheader, maxidw; static, strict, d
12701274

12711275
tests = filter(ts -> ts.run, tests)
12721276
many = length(tests) > 1
1273-
indented = isindented(verbose, moduleheader, many)
1277+
indented = isindented(verbose, module_header, many)
12741278

1275-
if indented
1276-
descwidth += 2
1279+
if !isempty(tests)
1280+
if indented
1281+
descwidth += 2
1282+
end
1283+
if module_header || module_summary(verbose, many)
1284+
descwidth = max(descwidth, textwidth(string(mod)) + module_header) # +1 for ':'
1285+
end
12771286
end
1278-
descwidth = max(descwidth, textwidth(string(mod)) + indented)
12791287
tests, descwidth, hasbroken
12801288
end
12811289

1282-
isindented(verbose, moduleheader, many) = (verbose > 0) & moduleheader
1290+
isindented(verbose, module_header, many) = (verbose > 0) & module_header
1291+
module_summary(verbose, many) = many | iszero(verbose)
12831292

12841293
function dryrun(mod::Module, ts::TestsetExpr, pat::Pattern, align::Int=0, parentsubj=""
12851294
; maxidw::Int, # external calls

0 commit comments

Comments
 (0)