-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm_test.go
More file actions
150 lines (138 loc) Β· 2.52 KB
/
term_test.go
File metadata and controls
150 lines (138 loc) Β· 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package color
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInitFlags(t *testing.T) {
tests := []struct {
name string
noColorEnv string
forceColorEnv string
wantNoColor bool
wantForceColor bool
setup func()
cleanup func()
}{
{
name: "NO_COLOR enabled",
wantNoColor: true,
wantForceColor: false,
setup: func() {
_ = os.Setenv("NO_COLOR", "true")
},
cleanup: func() {
_ = os.Unsetenv("NO_COLOR")
NoColor = false
},
},
{
name: "FORCE_COLOR enabled",
wantNoColor: false,
wantForceColor: true,
setup: func() {
_ = os.Setenv("FORCE_COLOR", "true")
},
cleanup: func() {
_ = os.Unsetenv("FORCE_COLOR")
ForceColor = false
},
},
{
name: "both disabled",
wantNoColor: false,
wantForceColor: false,
setup: func() {},
cleanup: func() {},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tc.setup()
initFlags()
assert.Equal(t, tc.wantNoColor, NoColor)
assert.Equal(t, tc.wantForceColor, ForceColor)
tc.cleanup()
})
}
}
func TestSupportsColor(t *testing.T) {
tests := []struct {
name string
termEnv string
colorTermEnv string
want bool
setup func()
cleanup func()
}{
{
name: "COLORTERM",
want: true,
setup: func() {
_ = os.Setenv("COLORTERM", "xterm256")
},
cleanup: func() {
_ = os.Unsetenv("COLORTERM")
},
},
{
name: "TERM=dumb",
want: false,
setup: func() {
_ = os.Setenv("TERM", "dumb")
},
cleanup: func() {
_ = os.Unsetenv("TERM")
},
},
{
name: "TERM is empty",
termEnv: "",
want: false,
setup: func() {
_ = os.Setenv("TERM", "")
},
cleanup: func() {
_ = os.Unsetenv("TERM")
},
},
{
name: "TERM=xterm-256color",
want: true,
setup: func() {
_ = os.Setenv("TERM", "xterm-256color")
},
cleanup: func() {
_ = os.Unsetenv("TERM")
},
},
{
name: "TERM=screen",
want: true,
setup: func() {
_ = os.Setenv("TERM", "screen")
},
cleanup: func() {
_ = os.Unsetenv("TERM")
},
},
{
name: "TERM=linux",
want: true,
setup: func() {
_ = os.Setenv("TERM", "linux")
},
cleanup: func() {
_ = os.Unsetenv("TERM")
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tc.setup()
result := SupportsColor()
assert.Equal(t, tc.want, result)
tc.cleanup()
})
}
}