@@ -142,9 +142,52 @@ func TestNoColor(t *testing.T) {
142142
143143 // global check
144144 NoColor = true
145- defer func () {
145+ t . Cleanup ( func () {
146146 NoColor = false
147- }()
147+ })
148+
149+ for _ , c := range testColors {
150+ p := New (c .code )
151+ p .Print (c .text )
152+
153+ line , _ := rb .ReadString ('\n' )
154+ if line != c .text {
155+ t .Errorf ("Expecting %s, got '%s'\n " , c .text , line )
156+ }
157+ }
158+ }
159+
160+ func TestNoColor_Env (t * testing.T ) {
161+ rb := new (bytes.Buffer )
162+ Output = rb
163+
164+ testColors := []struct {
165+ text string
166+ code Attribute
167+ }{
168+ {text : "black" , code : FgBlack },
169+ {text : "red" , code : FgRed },
170+ {text : "green" , code : FgGreen },
171+ {text : "yellow" , code : FgYellow },
172+ {text : "blue" , code : FgBlue },
173+ {text : "magent" , code : FgMagenta },
174+ {text : "cyan" , code : FgCyan },
175+ {text : "white" , code : FgWhite },
176+ {text : "hblack" , code : FgHiBlack },
177+ {text : "hred" , code : FgHiRed },
178+ {text : "hgreen" , code : FgHiGreen },
179+ {text : "hyellow" , code : FgHiYellow },
180+ {text : "hblue" , code : FgHiBlue },
181+ {text : "hmagent" , code : FgHiMagenta },
182+ {text : "hcyan" , code : FgHiCyan },
183+ {text : "hwhite" , code : FgHiWhite },
184+ }
185+
186+ os .Setenv ("NO_COLOR" , "" )
187+ t .Cleanup (func () {
188+ os .Unsetenv ("NO_COLOR" )
189+ })
190+
148191 for _ , c := range testColors {
149192 p := New (c .code )
150193 p .Print (c .text )
0 commit comments