Skip to content

Commit

Permalink
Fix top-level @check not showing how long it takes
Browse files Browse the repository at this point in the history
I don't remember why I guarded this behind a version check,
and the helpful comment doesn't say. Since it bothered me not to
see the duration from a top-level `@check`, I've removed
the `@static if` that guarded this.
  • Loading branch information
Seelengrab committed Mar 18, 2024
1 parent fb4b42c commit 87b22a1
Showing 1 changed file with 87 additions and 90 deletions.
177 changes: 87 additions & 90 deletions src/testset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,101 +90,98 @@ Test.get_alignment(sr::SuppositionReport, depth::Int) = 2*depth + textwidth(sr.d
end
end # @static if

# This is to get fancy printing on earlier versions
@static if VERSION.major == 1 && VERSION.minor < 11
function Test.print_test_results(sr::SuppositionReport, depth_pad=0)
# Calculate the overall number for each type so each of
# the test result types are aligned
res = results(sr)
total_pass = Int(res.ispass)
total_fail = Int(res.isfail)
total_error = Int(res.iserror)
total_broken = Int(res.isbroken)
dig_pass = total_pass > 0 ? ndigits(total_pass) : 0
dig_fail = total_fail > 0 ? ndigits(total_fail) : 0
dig_error = total_error > 0 ? ndigits(total_error) : 0
dig_broken = total_broken > 0 ? ndigits(total_broken) : 0
total = total_pass + total_fail + total_error + total_broken
dig_total = total > 0 ? ndigits(total) : 0
# For each category, take max of digits and header width if there are
# tests of that type
pass_width = dig_pass > 0 ? max(length("Pass"), dig_pass) : 0
fail_width = dig_fail > 0 ? max(length("Fail"), dig_fail) : 0
error_width = dig_error > 0 ? max(length("Error"), dig_error) : 0
broken_width = dig_broken > 0 ? max(length("Broken"), dig_broken) : 0
total_width = max(textwidth("Total"), dig_total)
duration = _format_duration(sr)
duration_width = max(textwidth("Time"), textwidth(duration))
# Calculate the alignment of the test result counts by
# recursively walking the tree of test sets
align = max(Test.get_alignment(sr, 0), textwidth("Test Summary:"))
# Print the outer test set header once
printstyled(rpad("Test Summary:", align, " "), " |", " "; bold=true)
if pass_width > 0
printstyled(lpad("Pass", pass_width, " "), " "; bold=true, color=:green)
end
if fail_width > 0
printstyled(lpad("Fail", fail_width, " "), " "; bold=true, color=Base.error_color())
end
if error_width > 0
printstyled(lpad("Error", error_width, " "), " "; bold=true, color=Base.error_color())
end
if broken_width > 0
printstyled(lpad("Broken", broken_width, " "), " "; bold=true, color=Base.warn_color())
end
if total_width > 0 || total == 0
printstyled(lpad("Total", total_width, " "), " "; bold=true, color=Base.info_color())
end
printstyled(lpad("Time", duration_width, " "); bold=true)
println()
fallbackstr = " "
subtotal = total_pass + total_fail + total_error + total_broken
# Print test set header, with an alignment that ensures all
# the test results appear above each other
print(rpad(string(" "^depth_pad, sr.description), align, " "), " | ")

n_passes = total_pass
if n_passes > 0
printstyled(lpad(string(n_passes), pass_width, " "), " ", color=:green)
elseif pass_width > 0
# No passes at this level, but some at another level
printstyled(lpad(fallbackstr, pass_width, " "), " ", color=:green)
end

n_fails = total_fail
if n_fails > 0
printstyled(lpad(string(n_fails), fail_width, " "), " ", color=Base.error_color())
elseif fail_width > 0
# No fails at this level, but some at another level
printstyled(lpad(fallbackstr, fail_width, " "), " ", color=Base.error_color())
end
function Test.print_test_results(sr::SuppositionReport, depth_pad=0)
# Calculate the overall number for each type so each of
# the test result types are aligned
res = results(sr)
total_pass = Int(res.ispass)
total_fail = Int(res.isfail)
total_error = Int(res.iserror)
total_broken = Int(res.isbroken)
dig_pass = total_pass > 0 ? ndigits(total_pass) : 0
dig_fail = total_fail > 0 ? ndigits(total_fail) : 0
dig_error = total_error > 0 ? ndigits(total_error) : 0
dig_broken = total_broken > 0 ? ndigits(total_broken) : 0
total = total_pass + total_fail + total_error + total_broken
dig_total = total > 0 ? ndigits(total) : 0
# For each category, take max of digits and header width if there are
# tests of that type
pass_width = dig_pass > 0 ? max(length("Pass"), dig_pass) : 0
fail_width = dig_fail > 0 ? max(length("Fail"), dig_fail) : 0
error_width = dig_error > 0 ? max(length("Error"), dig_error) : 0
broken_width = dig_broken > 0 ? max(length("Broken"), dig_broken) : 0
total_width = max(textwidth("Total"), dig_total)
duration = _format_duration(sr)
duration_width = max(textwidth("Time"), textwidth(duration))
# Calculate the alignment of the test result counts by
# recursively walking the tree of test sets
align = max(Test.get_alignment(sr, 0), textwidth("Test Summary:"))
# Print the outer test set header once
printstyled(rpad("Test Summary:", align, " "), " |", " "; bold=true)
if pass_width > 0
printstyled(lpad("Pass", pass_width, " "), " "; bold=true, color=:green)
end
if fail_width > 0
printstyled(lpad("Fail", fail_width, " "), " "; bold=true, color=Base.error_color())
end
if error_width > 0
printstyled(lpad("Error", error_width, " "), " "; bold=true, color=Base.error_color())
end
if broken_width > 0
printstyled(lpad("Broken", broken_width, " "), " "; bold=true, color=Base.warn_color())
end
if total_width > 0 || total == 0
printstyled(lpad("Total", total_width, " "), " "; bold=true, color=Base.info_color())
end
printstyled(lpad("Time", duration_width, " "); bold=true)
println()
fallbackstr = " "
subtotal = total_pass + total_fail + total_error + total_broken
# Print test set header, with an alignment that ensures all
# the test results appear above each other
print(rpad(string(" "^depth_pad, sr.description), align, " "), " | ")

n_passes = total_pass
if n_passes > 0
printstyled(lpad(string(n_passes), pass_width, " "), " ", color=:green)
elseif pass_width > 0
# No passes at this level, but some at another level
printstyled(lpad(fallbackstr, pass_width, " "), " ", color=:green)
end

n_errors = total_error
if n_errors > 0
printstyled(lpad(string(n_errors), error_width, " "), " ", color=Base.error_color())
elseif error_width > 0
# No errors at this level, but some at another level
printstyled(lpad(fallbackstr, error_width, " "), " ", color=Base.error_color())
end
n_fails = total_fail
if n_fails > 0
printstyled(lpad(string(n_fails), fail_width, " "), " ", color=Base.error_color())
elseif fail_width > 0
# No fails at this level, but some at another level
printstyled(lpad(fallbackstr, fail_width, " "), " ", color=Base.error_color())
end

n_broken = total_broken
if n_broken > 0
printstyled(lpad(string(n_broken), broken_width, " "), " ", color=Base.warn_color())
elseif broken_width > 0
# None broken at this level, but some at another level
printstyled(lpad(fallbackstr, broken_width, " "), " ", color=Base.warn_color())
end
n_errors = total_error
if n_errors > 0
printstyled(lpad(string(n_errors), error_width, " "), " ", color=Base.error_color())
elseif error_width > 0
# No errors at this level, but some at another level
printstyled(lpad(fallbackstr, error_width, " "), " ", color=Base.error_color())
end

if n_passes == 0 && n_fails == 0 && n_errors == 0 && n_broken == 0
total_str = string(subtotal)
printstyled(lpad(total_str, total_width, " "), " ", color=Base.info_color())
else
printstyled(lpad(string(subtotal), total_width, " "), " ", color=Base.info_color())
end
n_broken = total_broken
if n_broken > 0
printstyled(lpad(string(n_broken), broken_width, " "), " ", color=Base.warn_color())
elseif broken_width > 0
# None broken at this level, but some at another level
printstyled(lpad(fallbackstr, broken_width, " "), " ", color=Base.warn_color())
end

printstyled(lpad(duration, duration_width, " "))
println()
if n_passes == 0 && n_fails == 0 && n_errors == 0 && n_broken == 0
total_str = string(subtotal)
printstyled(lpad(total_str, total_width, " "), " ", color=Base.info_color())
else
printstyled(lpad(string(subtotal), total_width, " "), " ", color=Base.info_color())
end

printstyled(lpad(duration, duration_width, " "))
println()
end

record_name(sr::SuppositionReport) = sr.record_base * "_" * sr.description
Expand Down

0 comments on commit 87b22a1

Please sign in to comment.