Skip to content

Commit

Permalink
Improve coverage display in package table summary (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman authored Jun 4, 2022
1 parent a20c511 commit 41a62ef
Showing 1 changed file with 22 additions and 10 deletions.
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

0 comments on commit 41a62ef

Please sign in to comment.