Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cover display in package table summary #68

Merged
merged 2 commits into from
Jun 4, 2022
Merged
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
32 changes: 22 additions & 10 deletions internal/app/table_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ import (

"github.com/charmbracelet/lipgloss"
"github.com/mfridman/tparse/parse"
"github.com/olekukonko/tablewriter"
)

func (c *consoleWriter) summaryTable(packages []*parse.Package, showNoTests bool) {
var tableString strings.Builder
tbl := newTableWriter(&tableString, c.format)

tbl.SetColumnAlignment([]int{
tablewriter.ALIGN_LEFT,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_LEFT,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
tablewriter.ALIGN_CENTER,
})
header := summaryRow{
status: "Status",
elapsed: "Elapsed",
Expand Down Expand Up @@ -98,15 +107,18 @@ func (c *consoleWriter) summaryTable(packages []*parse.Package, showNoTests bool
}
}

coverage := fmt.Sprintf("%.1f%%", pkg.Coverage)
if pkg.Summary.Action != parse.ActionFail {
switch cover := pkg.Coverage; {
case cover > 0.0 && cover <= 50.0:
coverage = c.red(coverage, false)
case pkg.Coverage > 50.0 && pkg.Coverage < 80.0:
coverage = c.yellow(coverage, false)
case pkg.Coverage >= 80.0:
coverage = c.green(coverage, false)
coverage := "--"
if pkg.Cover {
coverage = fmt.Sprintf("%.1f%%", pkg.Coverage)
if pkg.Summary.Action != parse.ActionFail {
switch cover := pkg.Coverage; {
case cover > 0.0 && cover <= 50.0:
coverage = c.red(coverage, false)
case pkg.Coverage > 50.0 && pkg.Coverage < 80.0:
coverage = c.yellow(coverage, false)
case pkg.Coverage >= 80.0:
coverage = c.green(coverage, false)
}
}
}

Expand Down