Skip to content

Commit fb28a16

Browse files
Add consoleWriter.FormatAction
1 parent 47f9d84 commit fb28a16

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

internal/app/console_writer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package app
22

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

67
"github.com/charmbracelet/lipgloss"
8+
"github.com/mfridman/tparse/parse"
79
"github.com/muesli/termenv"
810
)
911

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

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)