Skip to content
Open
63 changes: 57 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Like `go test` but with colors.

## Installation

```
```bash
$ go get -u github.com/rakyll/gotest
```

Expand All @@ -14,16 +14,67 @@ Accepts all the arguments and flags `go test` works with.

Example:

```
```bash
$ gotest -v github.com/rakyll/hey
```

![go test output](https://i.imgur.com/udjWuZx.gif)

gotest comes with many colors! Configure the color of the output by setting the following env variable:
The default output colors for `gotest` are:

- `hired` for failed test cases
- `green` for passing test cases
- `yellow` for skipped test cases

`gotest` comes with many colors. All available colors are:

- `black`
- `hiblack`
- `red`
- `hired`
- `green`
- `higreen`
- `yellow`
- `hiyellow`
- `blue`
- `hiblue`
- `magenta`
- `himagenta`
- `cyan`
- `hicyan`
- `white`
- `hiwhite`

For a graphical presentation of the colors please see the documentation for the Go package [color](https://pkg.go.dev/mod/github.com/fatih/color), which is the implementation used for by `gotest`.

You can configure the color of the output by setting the environment variable `GOTEST_PALETTE`:

```bash
$ GOTEST_PALETTE="magenta,white" gotest -v github.com/rakyll/hey
```
$ GOTEST_PALETTE="magenta,white"

The output will have `magenta` for failed test cases and `white` for passing test cases.

You can specify the color for skipped tests also:

```bash
$ GOTEST_PALETTE="magenta,white,hiyellow" gotest -v github.com/rakyll/hey
```

The output will have magenta for failed cases, white for success.
Available colors: black, hiblack, red, hired, green, higreen, yellow, hiyellow, blue, hiblue, magenta, himagenta, cyan, hicyan, white, hiwhite.
The order of the colors for are:

1 failed test cases
1 passing test cases
1 skipped test cases

If you only want to overwrite the colors for indicating passing or skipped test cases, you can leave the spot empty.

This example demonstrates:

- `hired` for failed test cases, using the default
- `white` for passing test cases, overwriting the default
- `hiyellow` for skipped test cases, overwriting the default

```bash
$ GOTEST_PALETTE=",white,hiyellow" gotest -v github.com/rakyll/hey
```
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,23 @@ func setPalette() {
return
}
vals := strings.Split(v, ",")
if len(vals) != 2 {
if len(vals) > 3 {
return
}
if c, ok := colors[vals[0]]; ok {
fail = color.New(c)
if len(vals) > 0 {
if c, ok := colors[vals[0]]; ok {
fail = color.New(c)
}
}
if len(vals) > 1 {
if c, ok := colors[vals[1]]; ok {
success = color.New(c)
}
}
if c, ok := colors[vals[1]]; ok {
success = color.New(c)
if len(vals) > 2 {
if c, ok := colors[vals[2]]; ok {
skipped = color.New(c)
}
}
}

Expand Down