diff --git a/README.md b/README.md index e2d1763..1ea022f 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,13 @@ func Test(t *testing.T) { ## Color -To turn off the colors, run `go test` with the `-nocolor` flag, or with the env var `IS_NO_COLOR=true`. +To turn off the colors, run `go test` with the `-nocolor` flag, +or with the env var [`NO_COLOR` (with any value)](https://no-color.org). ``` go test -nocolor ``` ``` -IS_NO_COLOR=true go test +NO_COLOR=1 go test ``` diff --git a/is.go b/is.go index a95a409..305c153 100644 --- a/is.go +++ b/is.go @@ -22,7 +22,6 @@ // the helper methods: // // func Test(t *testing.T) { -// // // always start tests with this // is := is.New(t) // @@ -32,7 +31,6 @@ // // body := readBody(r) // is.True(strings.Contains(body, "Hi there")) -// // } package is @@ -45,6 +43,7 @@ import ( "os" "path/filepath" "reflect" + "strconv" "strings" ) @@ -74,7 +73,19 @@ type I struct { var noColorFlag bool func init() { - envNoColor := os.Getenv("IS_NO_COLOR") == "true" + var envNoColor bool + + // prefer https://no-color.org (with any value) + if _, ok := os.LookupEnv("NO_COLOR"); ok { + envNoColor = true + } + + if v, ok := os.LookupEnv("IS_NO_COLOR"); ok { + if b, err := strconv.ParseBool(v); err == nil { + envNoColor = b + } + } + flag.BoolVar(&noColorFlag, "nocolor", envNoColor, "turns off colors") }