Skip to content

Commit b06fcbf

Browse files
committed
Add Test_noColorIsSet
1 parent 8e3ccd4 commit b06fcbf

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

color_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ func TestNoColor_Env(t *testing.T) {
199199
}
200200
}
201201

202+
func Test_noColorIsSet(t *testing.T) {
203+
tests := []struct {
204+
name string
205+
act func()
206+
want bool
207+
}{
208+
{
209+
name: "default",
210+
act: func() {},
211+
want: false,
212+
},
213+
{
214+
name: "NO_COLOR=1",
215+
act: func() { os.Setenv("NO_COLOR", "1") },
216+
want: true,
217+
},
218+
{
219+
name: "NO_COLOR=",
220+
act: func() { os.Setenv("NO_COLOR", "") },
221+
want: false,
222+
},
223+
}
224+
for _, tt := range tests {
225+
t.Run(tt.name, func(t *testing.T) {
226+
t.Cleanup(func() {
227+
os.Unsetenv("NO_COLOR")
228+
})
229+
tt.act()
230+
if got := noColorIsSet(); got != tt.want {
231+
t.Errorf("noColorIsSet() = %v, want %v", got, tt.want)
232+
}
233+
})
234+
}
235+
}
236+
202237
func TestColorVisual(t *testing.T) {
203238
// First Visual Test
204239
Output = colorable.NewColorableStdout()

0 commit comments

Comments
 (0)