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 all commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ The `--format` flag or `GOTESTSUM_FORMAT` environment variable set the format th
is used to print the test names, and possibly test output, as the tests run. Most
outputs use color to highlight pass, fail, or skip.

The `--format-hivis` flag changes the icons used by `pkgname` formats to higher
visiblity unicode characters.

Commonly used formats (see `--help` for a full list):

* `dots` - print a character for each test.
Expand Down
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
"print format of test input")
flags.BoolVar(&opts.formatOptions.HideEmptyPackages, "format-hide-empty-pkg",
false, "do not print empty packages in compact formats")
flags.BoolVar(&opts.formatOptions.UseHiVisibilityIcons, "format-hivis",
false, "use high visibility characters in some formats")
flags.BoolVar(&opts.rawCommand, "raw-command", false,
"don't prepend 'go test -json' to the 'go test' command")
flags.BoolVar(&opts.ignoreNonJSONOutputLines, "ignore-non-json-output-lines", false,
Expand Down
1 change: 1 addition & 0 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Flags:
--debug enabled debug logging
-f, --format string print format of test input (default "short")
--format-hide-empty-pkg do not print empty packages in compact formats
--format-hivis use high visibility characters in some formats
--hide-summary summary hide sections of the summary: skipped,failed,errors,output (default none)
--jsonfile string write all TestEvents to file
--junitfile string write a JUnit XML file
Expand Down
22 changes: 17 additions & 5 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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 iconSkipped, iconSuccess, iconFailure string
if opts.UseHiVisibilityIcons {
iconSkipped = "➖"
iconSuccess = "✅"
iconFailure = "❌"
} else {
iconSkipped = "∅"
iconSuccess = "✓"
iconFailure = "✖"
}

fmtEvent := func(action string) string {
return action + " " + packageLine(event, exec)
}
Expand All @@ -149,17 +160,17 @@ func shortFormatPackageEvent(opts FormatOptions, event TestEvent, exec *Executio
if opts.HideEmptyPackages {
return ""
}
return fmtEvent(withColor("∅"))
return fmtEvent(withColor(iconSkipped))
case ActionPass:
if pkg.Total == 0 {
if opts.HideEmptyPackages {
return ""
}
return fmtEvent(withColor("∅"))
return fmtEvent(withColor(iconSkipped))
}
return fmtEvent(withColor("✓"))
return fmtEvent(withColor(iconSuccess))
case ActionFail:
return fmtEvent(withColor("✖"))
return fmtEvent(withColor(iconFailure))
}
return ""
}
Expand Down Expand Up @@ -222,7 +233,8 @@ type EventFormatter interface {
}

type FormatOptions struct {
HideEmptyPackages bool
HideEmptyPackages bool
UseHiVisibilityIcons bool
}

// NewEventFormatter returns a formatter for printing events.
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{UseHiVisibilityIcons: 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)