From 7c35cb283a42c7311ed03dd7e176a474b522f1a5 Mon Sep 17 00:00:00 2001 From: jonasbn Date: Mon, 9 Mar 2020 21:30:00 +0100 Subject: [PATCH 1/9] Implemented use of 3 variables instead of a single --- main.go | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/main.go b/main.go index 00dc065..afce33a 100644 --- a/main.go +++ b/main.go @@ -21,13 +21,11 @@ import ( ) var ( - success = color.New(color.FgGreen) - skipped = color.New(color.FgYellow) - fail = color.New(color.FgHiRed) + pass = color.New(color.FgGreen) + skip = color.New(color.FgYellow) + fail = color.New(color.FgHiRed) ) -const paletteEnv = "GOTEST_PALETTE" - func main() { setPalette() enableOnCI() @@ -86,19 +84,19 @@ func parse(line string) { case strings.HasPrefix(trimmed, "?"): c = nil - // success + // succeeded case strings.HasPrefix(trimmed, "--- PASS"): fallthrough case strings.HasPrefix(trimmed, "ok"): fallthrough case strings.HasPrefix(trimmed, "PASS"): - c = success + c = pass // skipped case strings.HasPrefix(trimmed, "--- SKIP"): - c = skipped + c = skip - // failure + // failed case strings.HasPrefix(trimmed, "--- FAIL"): fallthrough case strings.HasPrefix(trimmed, "FAIL"): @@ -127,19 +125,23 @@ func enableOnCI() { } func setPalette() { - v := os.Getenv(paletteEnv) - if v == "" { - return - } - vals := strings.Split(v, ",") - if len(vals) != 2 { - return - } - if c, ok := colors[vals[0]]; ok { - fail = color.New(c) - } - if c, ok := colors[vals[1]]; ok { - success = color.New(c) + envArray := [3]string{"GOTEST_SKIP_COLOR", "GOTEST_FAIL_COLOR", "GOTEST_PASS_COLOR"} + + for _, e := range envArray { + v := os.Getenv(e) + if v == "" { + continue + } + if c, ok := colors[v]; ok { + switch e { + case "GOTEST_FAIL_COLOR": + fail = color.New(c) + case "GOTEST_PASS_COLOR": + pass = color.New(c) + case "GOTEST_SKIP_COLOR": + skip = color.New(c) + } + } } } From c4b7aecc1a88ec1ae7fefc9f4e5f0eb264287f1b Mon Sep 17 00:00:00 2001 From: jonasbn Date: Tue, 12 May 2020 20:24:36 +0200 Subject: [PATCH 2/9] Changed into using constants for repeated string values --- main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index afce33a..ee7b60d 100644 --- a/main.go +++ b/main.go @@ -125,7 +125,12 @@ func enableOnCI() { } func setPalette() { - envArray := [3]string{"GOTEST_SKIP_COLOR", "GOTEST_FAIL_COLOR", "GOTEST_PASS_COLOR"} + + const TestSkipColorEnvVar string = "GOTEST_SKIP_COLOR" + const TestFailColorEnvVar string = "GOTEST_FAIL_COLOR" + const TestPassColorEnvVar string = "GOTEST_PASS_COLOR" + + envArray := [3]string{TestSkipColorEnvVar, TestFailColorEnvVar, TestFailColorEnvVar} for _, e := range envArray { v := os.Getenv(e) @@ -134,11 +139,11 @@ func setPalette() { } if c, ok := colors[v]; ok { switch e { - case "GOTEST_FAIL_COLOR": + case TestFailColorEnvVar: fail = color.New(c) - case "GOTEST_PASS_COLOR": + case TestPassColorEnvVar: pass = color.New(c) - case "GOTEST_SKIP_COLOR": + case TestSkipColorEnvVar: skip = color.New(c) } } From 33c93e90323ada5bb43fbe14ae27f2de28655d2f Mon Sep 17 00:00:00 2001 From: jonasbn Date: Wed, 13 May 2020 20:53:06 +0200 Subject: [PATCH 3/9] Revert "Implemented use of 3 variables instead of a single" This reverts commit 7c35cb283a42c7311ed03dd7e176a474b522f1a5. --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index ee7b60d..8d707d8 100644 --- a/main.go +++ b/main.go @@ -21,9 +21,9 @@ import ( ) var ( - pass = color.New(color.FgGreen) - skip = color.New(color.FgYellow) - fail = color.New(color.FgHiRed) + success = color.New(color.FgGreen) + skipped = color.New(color.FgYellow) + fail = color.New(color.FgHiRed) ) func main() { @@ -84,19 +84,19 @@ func parse(line string) { case strings.HasPrefix(trimmed, "?"): c = nil - // succeeded + // success case strings.HasPrefix(trimmed, "--- PASS"): fallthrough case strings.HasPrefix(trimmed, "ok"): fallthrough case strings.HasPrefix(trimmed, "PASS"): - c = pass + c = success // skipped case strings.HasPrefix(trimmed, "--- SKIP"): - c = skip + c = skipped - // failed + // failure case strings.HasPrefix(trimmed, "--- FAIL"): fallthrough case strings.HasPrefix(trimmed, "FAIL"): @@ -142,9 +142,9 @@ func setPalette() { case TestFailColorEnvVar: fail = color.New(c) case TestPassColorEnvVar: - pass = color.New(c) + success = color.New(c) case TestSkipColorEnvVar: - skip = color.New(c) + skipped = color.New(c) } } } From 7ca2673953a8c42f2f019c752904581c63cda22b Mon Sep 17 00:00:00 2001 From: jonasbn Date: Wed, 13 May 2020 22:56:06 +0200 Subject: [PATCH 4/9] Fixed a recently introduced bug --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8d707d8..8f18a7a 100644 --- a/main.go +++ b/main.go @@ -130,7 +130,7 @@ func setPalette() { const TestFailColorEnvVar string = "GOTEST_FAIL_COLOR" const TestPassColorEnvVar string = "GOTEST_PASS_COLOR" - envArray := [3]string{TestSkipColorEnvVar, TestFailColorEnvVar, TestFailColorEnvVar} + envArray := [3]string{TestSkipColorEnvVar, TestFailColorEnvVar, TestPassColorEnvVar} for _, e := range envArray { v := os.Getenv(e) From a407bac1cb3dc6e08bbc0a23631b946504528ccb Mon Sep 17 00:00:00 2001 From: jonasbn Date: Sat, 16 May 2020 22:42:15 +0200 Subject: [PATCH 5/9] WIP: Made first iteration on changes based on feedback from @subtlepseudonym --- main.go | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 8f18a7a..f45b0fb 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,13 @@ import ( "github.com/fatih/color" ) +const ( + paletteEnv = "GOTEST_PALETTE" + failEnv = "GOTEST_FAIL_COLOR" + passEnv = "GOTEST_PASS_COLOR" + skipEnv = "GOTEST_SKIP_COLOR" +) + var ( success = color.New(color.FgGreen) skipped = color.New(color.FgYellow) @@ -27,7 +34,7 @@ var ( ) func main() { - setPalette() + parseEnvAndSetPalette() enableOnCI() os.Exit(gotest(os.Args[1:])) } @@ -124,13 +131,32 @@ func enableOnCI() { } } -func setPalette() { +func parseEnvAndSetPalette() { + v := os.Getenv(paletteEnv) + if v == "" { + parseEnvColor() + } else { + + vals := strings.Split(v, ",") + if len(vals) != 3 { + return + } + + if c, ok := colors[vals[0]]; ok { + fail = color.New(c) + } + if c, ok := colors[vals[1]]; ok { + success = color.New(c) + } + if c, ok := colors[vals[2]]; ok { + skipped = color.New(c) + } + } +} - const TestSkipColorEnvVar string = "GOTEST_SKIP_COLOR" - const TestFailColorEnvVar string = "GOTEST_FAIL_COLOR" - const TestPassColorEnvVar string = "GOTEST_PASS_COLOR" +func parseEnvColor() { - envArray := [3]string{TestSkipColorEnvVar, TestFailColorEnvVar, TestPassColorEnvVar} + envArray := [3]string{skipEnv, failEnv, passEnv} for _, e := range envArray { v := os.Getenv(e) @@ -139,11 +165,11 @@ func setPalette() { } if c, ok := colors[v]; ok { switch e { - case TestFailColorEnvVar: + case failEnv: fail = color.New(c) - case TestPassColorEnvVar: + case passEnv: success = color.New(c) - case TestSkipColorEnvVar: + case skipEnv: skipped = color.New(c) } } From 5d71bfcad4620eadcade92b1cee9a6d54c5d0d78 Mon Sep 17 00:00:00 2001 From: jonasbn Date: Mon, 8 Jun 2020 21:39:26 +0200 Subject: [PATCH 6/9] Single color definitions now holds precedence over the palette definition --- main.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 8a6ef08..f14c93d 100644 --- a/main.go +++ b/main.go @@ -150,29 +150,30 @@ func enableOnCI() { } func parseEnvAndSetPalette() { + parsePaletteEnv() + parseColorEnvs() +} + +func parsePaletteEnv() { + v := os.Getenv(paletteEnv) - if v == "" { - parseEnvColor() - } else { + if v != "" { vals := strings.Split(v, ",") - if len(vals) != 3 { - return + states := []color.Attribute{fail, pass, skip} + for i := range vals { + if c, ok := colors[vals[i]]; ok { + states[i] = color.Attribute(c) + } } - if c, ok := colors[vals[0]]; ok { - fail = c - } - if c, ok := colors[vals[1]]; ok { - pass = c - } - if c, ok := colors[vals[2]]; ok { - skip = c - } + fail = states[0] + pass = states[1] + skip = states[2] } } -func parseEnvColor() { +func parseColorEnvs() { envArray := [3]string{skipEnv, failEnv, passEnv} From 857339493b4503d5d353d4ec803d678ac36524ca Mon Sep 17 00:00:00 2001 From: jonasbn Date: Mon, 8 Jun 2020 21:46:52 +0200 Subject: [PATCH 7/9] First shot at documentation, In general the documentation needs an overhaul, please see the other PRs with documentation changes. --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72547bb..34eeb90 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,13 @@ $ 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: +gotest comes with many colors! Configure the color of the output by setting the following environment variables: + +- `GOTEST_FAIL` +- `GOTEST_PASS` +- `GOTEST_SKIP` + +Alternatively you can use a single environment supporting a list of colors, in the order: fail and pass. ``` $ GOTEST_PALETTE="magenta,white" @@ -29,3 +35,13 @@ $ 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. + +Do note that the individually set environment variables take precedence over the palette variable + +For the setting: + +``` +$ GOTEST_PASS="hiblue" GOTEST_PALETTE="magenta,white" +``` + +The output will have magenta for failed cases, hiblue for success. From 6f170e02ea58f440ef70e00e37f6ef8d8e45cb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Br=C3=B8ms=C3=B8?= Date: Tue, 9 Jun 2020 07:09:24 +0200 Subject: [PATCH 8/9] Updated README.md All 3 parameters mentioned Co-authored-by: Connor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 34eeb90..470bdd8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ gotest comes with many colors! Configure the color of the output by setting the - `GOTEST_PASS` - `GOTEST_SKIP` -Alternatively you can use a single environment supporting a list of colors, in the order: fail and pass. +Alternatively you can use a single environment supporting a list of colors, in the order: fail, pass, and skip. ``` $ GOTEST_PALETTE="magenta,white" From ee765eac8ef09dc28996b0cb78077229549dc5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Br=C3=B8ms=C3=B8?= Date: Tue, 9 Jun 2020 07:09:50 +0200 Subject: [PATCH 9/9] Removed excess line Co-authored-by: Connor --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index f14c93d..20aa55d 100644 --- a/main.go +++ b/main.go @@ -155,7 +155,6 @@ func parseEnvAndSetPalette() { } func parsePaletteEnv() { - v := os.Getenv(paletteEnv) if v != "" {