diff --git a/README.md b/README.md index 72547bb..a60b45c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Like `go test` but with colors. ## Installation -``` +```bash $ go get -u github.com/rakyll/gotest ``` @@ -16,16 +16,61 @@ 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 [fatih/color](https://pkg.go.dev/mod/github.com/fatih/color). + +You can configure the color of the output by setting the environment variable `GOTEST_PALETTE`: + +```bash +$ GOTEST_PALETTE="magenta,white,hiyellow" gotest -v github.com/rakyll/hey ``` -$ GOTEST_PALETTE="magenta,white" -``` -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 output will have `magenta` for failed test cases, `white` for passing test cases, and `hiyellow` for skipped test cases. + +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 +``` diff --git a/main.go b/main.go index 18a5bef..985f2fb 100644 --- a/main.go +++ b/main.go @@ -149,16 +149,18 @@ func setPalette() { if v == "" { return } + vals := strings.Split(v, ",") - if len(vals) != 2 { - return - } - if c, ok := colors[vals[0]]; ok { - fail = c - } - if c, ok := colors[vals[1]]; ok { - pass = c + states := []color.Attribute{fail, pass, skip} + for i := range vals { + if c, ok := colors[vals[i]]; ok { + states[i] = color.Attribute(c) + } } + + fail = states[0] + pass = states[1] + skip = states[2] } var colors = map[string]color.Attribute{