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 493ebf2
Show file tree
Hide file tree
Showing 5 changed files with 58 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 (
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)

0 comments on commit 493ebf2

Please sign in to comment.