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

Add option to use high-visibility icons #293

Merged
merged 4 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ Flags:
flags.PrintDefaults()
fmt.Fprintf(out, `
Formats:
dots print a character for each test
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testname print a line for each test and package
standard-quiet standard go test format
standard-verbose standard go test -v format
dots print a character for each test
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-hivis print a line for each package, use hi-visability icons
pkgname-and-test-fails print a line for each package and failed test output
pkgname-and-test-fails-hivis print a line for each package and failed test output, use hi-visability icons
testname print a line for each test and package
standard-quiet standard go test format
standard-verbose standard go test -v format

Commands:
%[1]s tool slowest find or skip the slowest tests
Expand Down
16 changes: 9 additions & 7 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ Flags:
--watch watch go files, and run tests when a file is modified

Formats:
dots print a character for each test
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testname print a line for each test and package
standard-quiet standard go test format
standard-verbose standard go test -v format
dots print a character for each test
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-hivis print a line for each package, use hi-visability icons
pkgname-and-test-fails print a line for each package and failed test output
pkgname-and-test-fails-hivis print a line for each package and failed test output, use hi-visability icons
testname print a line for each test and package
standard-quiet standard go test format
standard-verbose standard go test -v format

Commands:
gotestsum tool slowest find or skip the slowest tests
Expand Down
34 changes: 30 additions & 4 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import (
"github.com/fatih/color"
)

const (
hivisSuffiz = "-hivis"
defaultEmptyEmoji = "∅"
defaultSuccessEmoji = "✓"
defaultFailEmoji = "✖"
hivisEmptyEmpji = "🔳"
hivisSuccessEmoji = "✅"
hivisFailEmoji = "❌"
)

func debugFormat(event TestEvent, _ *Execution) string {
return fmt.Sprintf("%s %s %s (%.3f) [%d] %s\n",
event.Package,
Expand Down Expand Up @@ -139,6 +149,17 @@ func pkgNameFormat(opts FormatOptions) func(event TestEvent, exec *Execution) st

func shortFormatPackageEvent(opts FormatOptions, event TestEvent, exec *Execution) string {
pkg := exec.Package(event.Package)
var emptyEmoji, successEmoji, failEmoji string

if opts.UseHivisEmojis {
emptyEmoji = hivisEmptyEmpji
successEmoji = hivisSuccessEmoji
failEmoji = hivisFailEmoji
} else {
emptyEmoji = defaultEmptyEmoji
successEmoji = defaultSuccessEmoji
failEmoji = defaultFailEmoji
}

fmtEvent := func(action string) string {
return action + " " + packageLine(event, exec)
Expand All @@ -149,17 +170,17 @@ func shortFormatPackageEvent(opts FormatOptions, event TestEvent, exec *Executio
if opts.HideEmptyPackages {
return ""
}
return fmtEvent(withColor("∅"))
return fmtEvent(withColor(emptyEmoji))
case ActionPass:
if pkg.Total == 0 {
if opts.HideEmptyPackages {
return ""
}
return fmtEvent(withColor("∅"))
return fmtEvent(withColor(emptyEmoji))
}
return fmtEvent(withColor("✓"))
return fmtEvent(withColor(successEmoji))
case ActionFail:
return fmtEvent(withColor("✖"))
return fmtEvent(withColor(failEmoji))
}
return ""
}
Expand Down Expand Up @@ -223,10 +244,15 @@ type EventFormatter interface {

type FormatOptions struct {
HideEmptyPackages bool
UseHivisEmojis bool
}

// NewEventFormatter returns a formatter for printing events.
func NewEventFormatter(out io.Writer, format string, formatOpts FormatOptions) EventFormatter {
if strings.HasSuffix(format, hivisSuffiz) {
formatOpts.UseHivisEmojis = true
format = strings.TrimSuffix(format, hivisSuffiz)
}
switch format {
case "debug":
return &formatAdapter{out, debugFormat}
Expand Down
5 changes: 5 additions & 0 deletions testjson/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func TestFormats_DefaultGoTestJson(t *testing.T) {
format: pkgNameFormat(FormatOptions{}),
expectedOut: "format/pkgname.out",
},
{
name: "pkgname-hivis",
format: pkgNameFormat(FormatOptions{UseHivisEmojis: true}),
expectedOut: "format/pkgname-hivis.out",
},
{
name: "pkgname",
format: pkgNameFormat(FormatOptions{HideEmptyPackages: true}),
Expand Down
5 changes: 5 additions & 0 deletions testjson/testdata/format/pkgname-hivis.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
❌ testjson/internal/badmain (1ms)
🔳 testjson/internal/empty (cached)
✅ testjson/internal/good (cached)
❌ testjson/internal/parallelfails (20ms)
❌ testjson/internal/withfails (20ms)