Skip to content

Commit

Permalink
Add format icons for nerdfonts instead of unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Sep 19, 2023
1 parent 6158754 commit d91997b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ outputs use color to highlight pass, fail, or skip.

The `--format-icons` flag changes the icons used by `pkgname` and `testdox` formats.
You can set the `GOTESTSUM_FORMAT_ICONS` environment variable, instead of the flag.
The nerdfonts icons requires a font from [Nerd Fonts](https://www.nerdfonts.com/).

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

Expand Down
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ Formats:
Format icons:
default the original unicode (✓, ∅, ✖)
hivis higher visibility unicode (✅, ➖, ❌)
* nerdfonts requires a font from https://www.nerdfonts.com/
codicons   
octicons   
Commands:
%[1]s tool slowest find or skip the slowest tests
Expand Down
3 changes: 3 additions & 0 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Formats:
Format icons:
default the original unicode (✓, ∅, ✖)
hivis higher visibility unicode (✅, ➖, ❌)
* nerdfonts requires a font from https://www.nerdfonts.com/
codicons   
octicons   

Commands:
gotestsum tool slowest find or skip the slowest tests
Expand Down
14 changes: 14 additions & 0 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,20 @@ func getIconFunc(opts FormatOptions) func(Action) string {
fail: "❌", // CROSS MARK
color: false,
}.forAction
case opts.Icons == "codicons":
return icons{
pass: "\ueba4", // cod-pass
skip: "\ueabd", // cod-circle_slash
fail: "\uea87", // cod-error
color: true,
}.forAction
case opts.Icons == "octicons":
return icons{
pass: "\uf49e", // oct-check_circle
skip: "\uf517", // oct-skip
fail: "\uf52f", // oct-x_circle
color: true,
}.forAction
default:
return icons{
pass: "✓", // CHECK MARK
Expand Down
14 changes: 14 additions & 0 deletions testjson/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ func TestFormats_DefaultGoTestJson(t *testing.T) {
},
expectedOut: "format/pkgname-hivis.out",
},
{
name: "pkgname with codicons",
format: func(out io.Writer) EventFormatter {
return pkgNameFormat(out, FormatOptions{Icons: "codicons"})
},
expectedOut: "format/pkgname-codicons.out",
},
{
name: "pkgname with octicons",
format: func(out io.Writer) EventFormatter {
return pkgNameFormat(out, FormatOptions{Icons: "octicons"})
},
expectedOut: "format/pkgname-octicons.out",
},
{
name: "pkgname with hide-empty",
format: func(out io.Writer) EventFormatter {
Expand Down
5 changes: 5 additions & 0 deletions testjson/testdata/format/pkgname-codicons.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)
5 changes: 5 additions & 0 deletions testjson/testdata/format/pkgname-octicons.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 d91997b

Please sign in to comment.