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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
package pkglint
import "gopkg.in/check.v1"
func (s *Suite) Test_VargroupsChecker__typo_in_group_name(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"_VARGROUPS+=\t\tgroup",
"_DEF_VARS.typo=\t\t# none",
"_LISTED_VARS.typo=\t# none")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:4: Expected _DEF_VARS.group, but found \"typo\".",
"WARN: Makefile:5: Expected _LISTED_VARS.group, but found \"typo\".")
}
func (s *Suite) Test_VargroupsChecker__duplicate_variable_name(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"_VARGROUPS+=\t\tgroup",
"_USER_VARS.group=\tVAR",
"_PKG_VARS.group=\tVAR",
"_SYS_VARS.group=\tVAR",
"_DEF_VARS.group=\tVAR",
"_USE_VARS.group=\tVAR",
"_IGN_VARS.group=\tVAR",
"_SORTED_VARS.group=\tVAR",
"_LISTED_VARS.group=\tVAR",
"",
"VAR=\t${VAR}")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:5: Duplicate variable name VAR, already appeared in line 4.",
"WARN: Makefile:6: Duplicate variable name VAR, already appeared in line 4.",
"WARN: Makefile:7: Duplicate variable name VAR, already appeared in line 4.",
"WARN: Makefile:8: Duplicate variable name VAR, already appeared in line 4.",
"WARN: Makefile:9: Duplicate variable name VAR, already appeared in line 4.")
}
func (s *Suite) Test_VargroupsChecker__variable_reference(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"_VARGROUPS+=\t\tgroup",
"_USER_VARS.group=\t${:Uparam:@param@VAR.${param}@}",
"_LISTED_VARS.group=\t${:Uparam:@param@VAR.${param}@}",
"",
"VAR.param=\tvalue")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:7: VAR.param is defined but not used.",
// FIXME: Hmmm, that's going to be complicated to get right.
"WARN: Makefile:7: Variable VAR.param is defined but not mentioned in the _VARGROUPS section.")
}
func (s *Suite) Test_VargroupsChecker__public_underscore(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"_VARGROUPS+=\t\tgroup",
"_USER_VARS.group=\t_VARGROUPS")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:4: _USER_VARS.group should list only variables that " +
"start with a letter, not \"_VARGROUPS\".")
}
func (s *Suite) Test_VargroupsChecker__declared_but_undefined(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"# UNDECLARED", // Documented to avoid a warning about being defined but unused.
"#\tDocumentation",
"#\tDocumentation",
"",
"_VARGROUPS+=\t\tgroup",
"_DEF_VARS.group=\tUNDEFINED",
"",
"UNDECLARED=\tvalue",
"UNDECLARED=\tvalue")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:10: Variable UNDECLARED is defined but not mentioned in the _VARGROUPS section.",
"WARN: Makefile:8: The variable UNDEFINED is not actually defined in this file.")
}
func (s *Suite) Test_VargroupsChecker__defined_but_undeclared(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
".if !defined(MAKEFILE_MK)",
"MAKEFILE_MK=",
"",
"_VARGROUPS+=\t\tgroup",
"",
"PKG_FAIL_REASON+=\tReason",
"",
".endif")
mklines.Check()
t.CheckOutputEmpty()
}
func (s *Suite) Test_VargroupsChecker__used_but_undeclared(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
t.SetUpTool("touch", "TOUCH", AtRunTime)
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"_VARGROUPS+=\tgroup",
"",
"pre-configure:",
"\t${TOOLS_SHELL} -c ':'",
"\t${TOUCH} ${TOUCH_FLAGS} ${.TARGET}",
"\t: ${PKGNAME}")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:8: Variable PKGNAME is used " +
"but not mentioned in the _VARGROUPS section.")
}
func (s *Suite) Test_VargroupsChecker__declared_but_unused(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"# UNDECLARED", // Documented to avoid a "used but not defined" warning.
"#\tDocumentation",
"#\tDocumentation",
"",
"_VARGROUPS+=\t\tgroup",
"_USE_VARS.group=\tUNUSED",
"",
"target: .PHONY",
"\t: ${UNDECLARED}",
"\t: ${UNDECLARED}")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:11: Variable UNDECLARED is used but not mentioned in the _VARGROUPS section.",
"WARN: Makefile:8: The variable UNUSED is not actually used in this file.")
}
func (s *Suite) Test_VargroupsChecker__used_in_BUILD_DEFS(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"# USER_VAR",
"#\tDocumentation.",
"#\tDocumentation.",
"",
"_VARGROUPS+=\t\tgroup",
"_USER_VARS.group=\tUSER_VAR",
"",
".if ${USER_VAR:U}",
".endif",
"BUILD_DEFS+=\t${_USER_VARS.group}")
mklines.Check()
// No warning about _USER_VARS.group being a write-only variable.
t.CheckOutputEmpty()
}
func (s *Suite) Test_VargroupsChecker__ignore(c *check.C) {
t := s.Init(c)
t.SetUpVartypes()
mklines := t.NewMkLines("Makefile",
MkCvsID,
"",
"_VARGROUPS+=\t\tgroup",
"_IGN_VARS.group=\tPREFER_*",
"",
".if ${PREFER_PKGSRC:U} || ${WRKOBJDIR:U}",
".endif")
mklines.Check()
t.CheckOutputLines(
"WARN: Makefile:6: Variable WRKOBJDIR is used but not mentioned in the _VARGROUPS section.")
}
|