Skip to content

Commit

Permalink
Add option to use high-visibility icons
Browse files Browse the repository at this point in the history
The default icons used in the pkgname output formats (∅,✔,𐄂) can
be hard to spot when scrolling through test output.

This PR adds the ability to pick a higher-visiblity/contrast set of
icons (🔳,✅,❌) by adding a `-hivis` suffix to either of the 'pkgname'
style formats.
  • Loading branch information
n-oden committed Dec 15, 2022
1 parent 10c2a47 commit a923785
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
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 (
hivisSuffix = "-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, hivisSuffix) {
formatOpts.UseHivisEmojis = true
format = strings.TrimSuffix(format, hivisSuffix)
}
switch format {
case "debug":
return &formatAdapter{out, debugFormat}
Expand Down

0 comments on commit a923785

Please sign in to comment.