Skip to content

Commit 800eedf

Browse files
Add consoleWriter.FormatAction
1 parent 47f9d84 commit 800eedf

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

internal/app/console_writer.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package app
22

33
import (
44
"io"
5+
"strings"
56

67
"github.com/charmbracelet/lipgloss"
78
"github.com/muesli/termenv"
9+
10+
"github.com/mfridman/tparse/parse"
811
)
912

1013
type OutputFormat int
@@ -81,3 +84,17 @@ func newConsoleWriter(w io.Writer, format OutputFormat, disableColor bool) *cons
8184
}
8285
return cw
8386
}
87+
88+
func (w *consoleWriter) FormatAction(action parse.Action) string {
89+
s := strings.ToUpper(action.String())
90+
switch action {
91+
case parse.ActionPass:
92+
return w.green(s)
93+
case parse.ActionSkip:
94+
return w.yellow(s)
95+
case parse.ActionFail:
96+
return w.red(s)
97+
default:
98+
return s
99+
}
100+
}

internal/app/table_summary.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,7 @@ func (c *consoleWriter) summaryTable(
167167
}
168168
}
169169

170-
status := strings.ToUpper(pkg.Summary.Action.String())
171-
switch pkg.Summary.Action {
172-
case parse.ActionPass:
173-
status = c.green(status)
174-
case parse.ActionSkip:
175-
status = c.yellow(status)
176-
case parse.ActionFail:
177-
status = c.red(status)
178-
}
170+
status := c.FormatAction(pkg.Summary.Action)
179171

180172
// Skip packages with no coverage to mimic nocoverageredesign behavior (changed in github.com/golang/go/issues/24570)
181173
totalTests := len(pkg.TestsByAction(parse.ActionPass)) + len(pkg.TestsByAction(parse.ActionFail)) + len(pkg.TestsByAction(parse.ActionSkip))

internal/app/table_tests.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,7 @@ func (c *consoleWriter) testsTable(packages []*parse.Package, option TestTableOp
8787

8888
testName := shortenTestName(t.Name, option.Trim, 32)
8989

90-
status := strings.ToUpper(t.Status().String())
91-
switch t.Status() {
92-
case parse.ActionPass:
93-
status = c.green(status)
94-
case parse.ActionSkip:
95-
status = c.yellow(status)
96-
case parse.ActionFail:
97-
status = c.red(status)
98-
}
99-
90+
status := c.FormatAction(t.Status())
10091
packageName := shortenPackageName(t.Package, packagePrefix, 16, option.Trim, option.TrimPath)
10192

10293
row := testRow{
@@ -155,15 +146,7 @@ func (c *consoleWriter) testsTableMarkdown(packages []*parse.Package, option Tes
155146

156147
testName := shortenTestName(t.Name, option.Trim, 32)
157148

158-
status := strings.ToUpper(t.Status().String())
159-
switch t.Status() {
160-
case parse.ActionPass:
161-
status = c.green(status)
162-
case parse.ActionSkip:
163-
status = c.yellow(status)
164-
case parse.ActionFail:
165-
status = c.red(status)
166-
}
149+
status := c.FormatAction(t.Status())
167150
data.Append([]string{
168151
status,
169152
strconv.FormatFloat(t.Elapsed(), 'f', 2, 64),

0 commit comments

Comments
 (0)