Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ EzXML = "1"
LibGit2 = "1.10"
OrderedCollections = "1"
Pkg = "1.10"
PrettyTables = "0.12, 1.0, 2"
PrettyTables = "0.12, 1.0, 2, 3"
julia = "1.10"
58 changes: 43 additions & 15 deletions src/LocalCoverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module LocalCoverage
import CoverageTools
using Coverage: process_folder, process_file
using DocStringExtensions: SIGNATURES, FIELDS
using PrettyTables: pretty_table, Highlighter
using PrettyTables: PrettyTables, pretty_table
import DefaultApplication
import LibGit2
import Pkg
Expand Down Expand Up @@ -110,7 +110,7 @@ function Base.show(io::IO, summary::PackageCoverage)
header = ["Filename", "Lines", "Hit", "Miss", "%"]
percentage_column = length(header)
alignment = [:l, :r, :r, :r, :r]
columns_width = fill(0, 5)
columns_width = fill(-1, 5) # We need strictly negative number to autosize in PrettyTables 3.0, but this also works in v2
if get(io, :print_gaps, false)
push!(header, "Gaps")
push!(alignment, :l)
Expand All @@ -119,6 +119,13 @@ function Base.show(io::IO, summary::PackageCoverage)
else
rows = map(row -> Base.structdiff(row, NamedTuple{(:gaps,)}), rows)
end
# PrettyTables 3.0 changed Highlighter to TextHighlighter, which up to currently published version (v3.10) does not provide the kwargs constructor (despite having it documented). We create here a patch to handle both cases
Highlighter(f; kwargs...) = @static if pkgversion(PrettyTables) < v"3.0.0"
PrettyTables.Highlighter(f; kwargs...)
else
PrettyTables.TextHighlighter(f, PrettyTables.Crayon(;kwargs...))
end

highlighters = (
Highlighter(
(data, i, j) -> j == percentage_column && row_coverage[i] <= 50,
Expand All @@ -131,19 +138,40 @@ function Base.show(io::IO, summary::PackageCoverage)
foreground = :green),
)

pretty_table(
io,
rows;
title = "Coverage of $(package_dir)",
header,
alignment,
crop = :none,
linebreaks = true,
columns_width,
autowrap = true,
highlighters,
body_hlines = [length(rows) - 1],
)
# Kwargs of `pretty_table` itself also changed in PrettyTables 3.0, so we have to branch here as well
@static if pkgversion(PrettyTables) < v"3.0.0"
pretty_table(
io,
rows;
title = "Coverage of $(package_dir)",
header,
alignment,
crop = :none,
linebreaks = true,
columns_width,
autowrap = true,
highlighters,
body_hlines = [length(rows) - 1],
)
else
pretty_table(
io,
rows;
title = "Coverage of $(package_dir)",
column_labels = [header],
alignment,
# The crop kwarg is not present anymore, split into the next two ones
fit_table_in_display_horizontally = false,
fit_table_in_display_vertically = false,
line_breaks = true,
fixed_data_column_widths = columns_width,
auto_wrap = true,
highlighters = collect(highlighters), # v3 expects a vector instead of a Tuple
table_format = PrettyTables.TextTableFormat(;
horizontal_lines_at_data_rows = [length(rows) - 1],
),
)
end
end

"""
Expand Down
Loading