diff --git a/README.md b/README.md index 536df56c..95fdc5b1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cmd/main.go b/cmd/main.go index 8eacaa02..0f32240f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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, diff --git a/cmd/testdata/gotestsum-help-text b/cmd/testdata/gotestsum-help-text index 83c98230..9566dddb 100644 --- a/cmd/testdata/gotestsum-help-text +++ b/cmd/testdata/gotestsum-help-text @@ -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 diff --git a/testjson/format.go b/testjson/format.go index d311f9ff..b4093ca8 100644 --- a/testjson/format.go +++ b/testjson/format.go @@ -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) } @@ -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 "" } @@ -222,7 +233,8 @@ type EventFormatter interface { } type FormatOptions struct { - HideEmptyPackages bool + HideEmptyPackages bool + UseHiVisibilityIcons bool } // NewEventFormatter returns a formatter for printing events. diff --git a/testjson/format_test.go b/testjson/format_test.go index 2f43e796..87e8e376 100644 --- a/testjson/format_test.go +++ b/testjson/format_test.go @@ -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}), diff --git a/testjson/testdata/format/pkgname-hivis.out b/testjson/testdata/format/pkgname-hivis.out new file mode 100644 index 00000000..c7049877 --- /dev/null +++ b/testjson/testdata/format/pkgname-hivis.out @@ -0,0 +1,5 @@ +❌ testjson/internal/badmain (1ms) +➖ testjson/internal/empty (cached) +✅ testjson/internal/good (cached) +❌ testjson/internal/parallelfails (20ms) +❌ testjson/internal/withfails (20ms)