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 committed Aug 26, 2023
1 parent e7c9840 commit 7e04e53
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ 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-nerdfonts` flag changes the icons used by `pkgname` formats to
use [Nerd Fonts](https://www.nerdfonts.com/) 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 @@ -63,6 +63,8 @@ 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.BoolVar(&opts.formatOptions.UseNerdFontsIcons, "format-nerdfonts",
false, "use nerd fonts characters instead of unicode")
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 @@ -9,6 +9,7 @@ Flags:
-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
--format-nerdfonts use nerd fonts characters instead of unicode
--hide-summary summary hide sections of the summary: skipped,failed,errors,output (default none)
--jsonfile string write all TestEvents to file
--jsonfile-timing-events string write only the pass, skip, and fail TestEvents to the file
Expand Down
5 changes: 5 additions & 0 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func shortFormatPackageEvent(opts FormatOptions, event TestEvent, exec *Executio
iconSkipped = "➖"
iconSuccess = "✅"
iconFailure = "❌"
} else if opts.UseNerdFontsIcons {
iconSkipped = "\ueabd" //  nf-cod-circle_slash
iconSuccess = "\ueba4" //  nf-cod-pass
iconFailure = "\uea87" //  nf-cod-error
} else {
iconSkipped = "∅"
iconSuccess = "✓"
Expand Down Expand Up @@ -287,6 +291,7 @@ func (e eventFormatterFunc) Format(event TestEvent, output *Execution) error {
type FormatOptions struct {
HideEmptyPackages bool
UseHiVisibilityIcons bool
UseNerdFontsIcons bool
}

// NewEventFormatter returns a formatter for printing events.
Expand Down
7 changes: 7 additions & 0 deletions testjson/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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{UseNerdFontsIcons: true})
},
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 7e04e53

Please sign in to comment.