Skip to content

Commit

Permalink
Add format flag for nerdfonts instead of unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund authored and dnephin committed Aug 27, 2023
1 parent dac0c43 commit 77eef0d
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ 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.
The `--format-icons` flag changes the icons used by `pkgname` and `testdox` formats.
`nerdfonts` requires a front from [Nerd Fonts](https://www.nerdfonts.com/).

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

Expand Down
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func setupFlags(name string) (*pflag.FlagSet, *options) {
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.MarkHidden("format-hivis")
_ = flags.MarkHidden("format-hivis")
flags.StringVar(&opts.formatOptions.Icons, "format-icons", "",
"use different icons, see help for options")

Expand Down Expand Up @@ -152,6 +152,7 @@ Formats:
Format icons:
default the original unicode (✓, ∅, ✖)
hivis higher visibility unicode (✅, ➖, ❌)
nerdfonts requires a font from https://www.nerdfonts.com/
Commands:
%[1]s tool slowest find or skip the slowest tests
Expand Down
5 changes: 3 additions & 2 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ Formats:
standard-verbose standard go test -v format

Format icons:
default the original icons (✓, ∅, ✖)
hivis higher visibility icons (✅, ➖, ❌)
default the original unicode (✓, ∅, ✖)
hivis higher visibility unicode (✅, ➖, ❌)
nerdfonts requires a font from https://www.nerdfonts.com/

Commands:
gotestsum tool slowest find or skip the slowest tests
Expand Down
63 changes: 38 additions & 25 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,45 @@ func pkgNameFormat(out io.Writer, opts FormatOptions) eventFormatterFunc {
}
}

func getIconFunc(opts FormatOptions) func(Action) string {
if opts.UseHiVisibilityIcons || opts.Icons == "hivis" {
return func(action Action) string {
switch action {
case ActionPass:
return "✅"
case ActionSkip:
return "➖"
case ActionFail:
return "❌"
default:
return ""
}
}
type icons struct {
pass string
fail string
skip string
}

func (i icons) forAction(action Action) string {
switch action {
case ActionPass:
return i.pass
case ActionSkip:
return i.skip
case ActionFail:
return i.fail
default:
return " "
}
return func(action Action) string {
switch action {
case ActionPass:
return color.GreenString("✓")
case ActionSkip:
return color.YellowString("∅")
case ActionFail:
return color.RedString("✖")
default:
return ""
}
}

func getIconFunc(opts FormatOptions) func(Action) string {
switch {
case opts.UseHiVisibilityIcons || opts.Icons == "hivis":
return icons{
pass: "✅",
skip: "➖",
fail: "❌",
}.forAction
case opts.Icons == "nerdfonts":
return icons{
pass: "\ueba4", //  nf-cod-pass
skip: "\ueabd", //  nf-cod-circle_slash
fail: "\uea87", //  nf-cod-error
}.forAction
default:
return icons{
pass: color.GreenString("✓"),
skip: color.YellowString("∅"),
fail: color.RedString("✖"),
}.forAction
}
}

Expand Down
7 changes: 7 additions & 0 deletions testjson/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ func TestFormats_DefaultGoTestJson(t *testing.T) {
},
expectedOut: "format/pkgname-hivis.out",
},
{
name: "pkgname with nerdfonts",
format: func(out io.Writer) EventFormatter {
return pkgNameFormat(out, FormatOptions{Icons: "nerdfonts"})
},
expectedOut: "format/pkgname-nerdfonts.out",
},
{
name: "pkgname with hide-empty",
format: func(out io.Writer) EventFormatter {
Expand Down
5 changes: 5 additions & 0 deletions testjson/testdata/format/pkgname-nerdfonts.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 77eef0d

Please sign in to comment.