@@ -147,115 +147,119 @@ func TestMinLength(t *testing.T) {
147
147
func TestRequired (t * testing.T ) {
148
148
testTables := []struct {
149
149
propertyName string
150
+ replacementPropertyName string // Used for testing subkeys that are required only when the higher level key is present.
150
151
validationErrorPropertyName string
151
152
complianceLevel compliancelevel.Type
152
153
assertion assert.BoolAssertionFunc
153
154
}{
154
- {"name" , "name" , compliancelevel .Permissive , assert .True },
155
- {"name" , "name" , compliancelevel .Specification , assert .True },
156
- {"name" , "name" , compliancelevel .Strict , assert .True },
155
+ {"name" , "" , " name" , compliancelevel .Permissive , assert .True },
156
+ {"name" , "" , " name" , compliancelevel .Specification , assert .True },
157
+ {"name" , "" , " name" , compliancelevel .Strict , assert .True },
157
158
158
- {"version" , "version" , compliancelevel .Permissive , assert .True },
159
- {"version" , "version" , compliancelevel .Specification , assert .True },
160
- {"version" , "version" , compliancelevel .Strict , assert .True },
159
+ {"version" , "" , " version" , compliancelevel .Permissive , assert .True },
160
+ {"version" , "" , " version" , compliancelevel .Specification , assert .True },
161
+ {"version" , "" , " version" , compliancelevel .Strict , assert .True },
161
162
162
- {"compiler.warning_flags.none" , "compiler\\ .warning_flags\\ .none" , compliancelevel .Permissive , assert .False },
163
- {"compiler.warning_flags.none" , "compiler\\ .warning_flags\\ .none" , compliancelevel .Specification , assert .False },
164
- {"compiler.warning_flags.none" , "compiler\\ .warning_flags\\ .none" , compliancelevel .Strict , assert .True },
163
+ {"compiler.warning_flags.none" , "" , " compiler\\ .warning_flags\\ .none" , compliancelevel .Permissive , assert .False },
164
+ {"compiler.warning_flags.none" , "" , " compiler\\ .warning_flags\\ .none" , compliancelevel .Specification , assert .False },
165
+ {"compiler.warning_flags.none" , "" , " compiler\\ .warning_flags\\ .none" , compliancelevel .Strict , assert .True },
165
166
166
- {"compiler.warning_flags.default" , "compiler\\ .warning_flags\\ .default" , compliancelevel .Permissive , assert .False },
167
- {"compiler.warning_flags.default" , "compiler\\ .warning_flags\\ .default" , compliancelevel .Specification , assert .False },
168
- {"compiler.warning_flags.default" , "compiler\\ .warning_flags\\ .default" , compliancelevel .Strict , assert .True },
167
+ {"compiler.warning_flags.default" , "" , " compiler\\ .warning_flags\\ .default" , compliancelevel .Permissive , assert .False },
168
+ {"compiler.warning_flags.default" , "" , " compiler\\ .warning_flags\\ .default" , compliancelevel .Specification , assert .False },
169
+ {"compiler.warning_flags.default" , "" , " compiler\\ .warning_flags\\ .default" , compliancelevel .Strict , assert .True },
169
170
170
- {"compiler.warning_flags.more" , "compiler\\ .warning_flags\\ .more" , compliancelevel .Permissive , assert .False },
171
- {"compiler.warning_flags.more" , "compiler\\ .warning_flags\\ .more" , compliancelevel .Specification , assert .False },
172
- {"compiler.warning_flags.more" , "compiler\\ .warning_flags\\ .more" , compliancelevel .Strict , assert .True },
171
+ {"compiler.warning_flags.more" , "" , " compiler\\ .warning_flags\\ .more" , compliancelevel .Permissive , assert .False },
172
+ {"compiler.warning_flags.more" , "" , " compiler\\ .warning_flags\\ .more" , compliancelevel .Specification , assert .False },
173
+ {"compiler.warning_flags.more" , "" , " compiler\\ .warning_flags\\ .more" , compliancelevel .Strict , assert .True },
173
174
174
- {"compiler.warning_flags.all" , "compiler\\ .warning_flags\\ .all" , compliancelevel .Permissive , assert .False },
175
- {"compiler.warning_flags.all" , "compiler\\ .warning_flags\\ .all" , compliancelevel .Specification , assert .False },
176
- {"compiler.warning_flags.all" , "compiler\\ .warning_flags\\ .all" , compliancelevel .Strict , assert .True },
175
+ {"compiler.warning_flags.all" , "" , " compiler\\ .warning_flags\\ .all" , compliancelevel .Permissive , assert .False },
176
+ {"compiler.warning_flags.all" , "" , " compiler\\ .warning_flags\\ .all" , compliancelevel .Specification , assert .False },
177
+ {"compiler.warning_flags.all" , "" , " compiler\\ .warning_flags\\ .all" , compliancelevel .Strict , assert .True },
177
178
178
- {"recipe.c.o.pattern" , "recipe\\ .c\\ .o\\ .pattern" , compliancelevel .Permissive , assert .True },
179
- {"recipe.c.o.pattern" , "recipe\\ .c\\ .o\\ .pattern" , compliancelevel .Specification , assert .True },
180
- {"recipe.c.o.pattern" , "recipe\\ .c\\ .o\\ .pattern" , compliancelevel .Strict , assert .True },
179
+ {"recipe.c.o.pattern" , "" , " recipe\\ .c\\ .o\\ .pattern" , compliancelevel .Permissive , assert .True },
180
+ {"recipe.c.o.pattern" , "" , " recipe\\ .c\\ .o\\ .pattern" , compliancelevel .Specification , assert .True },
181
+ {"recipe.c.o.pattern" , "" , " recipe\\ .c\\ .o\\ .pattern" , compliancelevel .Strict , assert .True },
181
182
182
- {"recipe.cpp.o.pattern" , "recipe\\ .cpp\\ .o\\ .pattern" , compliancelevel .Permissive , assert .True },
183
- {"recipe.cpp.o.pattern" , "recipe\\ .cpp\\ .o\\ .pattern" , compliancelevel .Specification , assert .True },
184
- {"recipe.cpp.o.pattern" , "recipe\\ .cpp\\ .o\\ .pattern" , compliancelevel .Strict , assert .True },
183
+ {"recipe.cpp.o.pattern" , "" , " recipe\\ .cpp\\ .o\\ .pattern" , compliancelevel .Permissive , assert .True },
184
+ {"recipe.cpp.o.pattern" , "" , " recipe\\ .cpp\\ .o\\ .pattern" , compliancelevel .Specification , assert .True },
185
+ {"recipe.cpp.o.pattern" , "" , " recipe\\ .cpp\\ .o\\ .pattern" , compliancelevel .Strict , assert .True },
185
186
186
- {"recipe.S.o.pattern" , "recipe\\ .S\\ .o\\ .pattern" , compliancelevel .Permissive , assert .True },
187
- {"recipe.S.o.pattern" , "recipe\\ .S\\ .o\\ .pattern" , compliancelevel .Specification , assert .True },
188
- {"recipe.S.o.pattern" , "recipe\\ .S\\ .o\\ .pattern" , compliancelevel .Strict , assert .True },
187
+ {"recipe.S.o.pattern" , "" , " recipe\\ .S\\ .o\\ .pattern" , compliancelevel .Permissive , assert .True },
188
+ {"recipe.S.o.pattern" , "" , " recipe\\ .S\\ .o\\ .pattern" , compliancelevel .Specification , assert .True },
189
+ {"recipe.S.o.pattern" , "" , " recipe\\ .S\\ .o\\ .pattern" , compliancelevel .Strict , assert .True },
189
190
190
- {"recipe.ar.pattern" , "recipe\\ .ar\\ .pattern" , compliancelevel .Permissive , assert .True },
191
- {"recipe.ar.pattern" , "recipe\\ .ar\\ .pattern" , compliancelevel .Specification , assert .True },
192
- {"recipe.ar.pattern" , "recipe\\ .ar\\ .pattern" , compliancelevel .Strict , assert .True },
191
+ {"recipe.ar.pattern" , "" , " recipe\\ .ar\\ .pattern" , compliancelevel .Permissive , assert .True },
192
+ {"recipe.ar.pattern" , "" , " recipe\\ .ar\\ .pattern" , compliancelevel .Specification , assert .True },
193
+ {"recipe.ar.pattern" , "" , " recipe\\ .ar\\ .pattern" , compliancelevel .Strict , assert .True },
193
194
194
- {"recipe.c.combine.pattern" , "recipe\\ .c\\ .combine\\ .pattern" , compliancelevel .Permissive , assert .True },
195
- {"recipe.c.combine.pattern" , "recipe\\ .c\\ .combine\\ .pattern" , compliancelevel .Specification , assert .True },
196
- {"recipe.c.combine.pattern" , "recipe\\ .c\\ .combine\\ .pattern" , compliancelevel .Strict , assert .True },
195
+ {"recipe.c.combine.pattern" , "" , " recipe\\ .c\\ .combine\\ .pattern" , compliancelevel .Permissive , assert .True },
196
+ {"recipe.c.combine.pattern" , "" , " recipe\\ .c\\ .combine\\ .pattern" , compliancelevel .Specification , assert .True },
197
+ {"recipe.c.combine.pattern" , "" , " recipe\\ .c\\ .combine\\ .pattern" , compliancelevel .Strict , assert .True },
197
198
198
- {"recipe.output.tmp_file" , "recipe\\ .output\\ .tmp_file" , compliancelevel .Permissive , assert .True },
199
- {"recipe.output.tmp_file" , "recipe\\ .output\\ .tmp_file" , compliancelevel .Specification , assert .True },
200
- {"recipe.output.tmp_file" , "recipe\\ .output\\ .tmp_file" , compliancelevel .Strict , assert .True },
199
+ {"recipe.output.tmp_file" , "" , " recipe\\ .output\\ .tmp_file" , compliancelevel .Permissive , assert .True },
200
+ {"recipe.output.tmp_file" , "" , " recipe\\ .output\\ .tmp_file" , compliancelevel .Specification , assert .True },
201
+ {"recipe.output.tmp_file" , "" , " recipe\\ .output\\ .tmp_file" , compliancelevel .Strict , assert .True },
201
202
202
- {"tools.avrdude.upload.pattern" , "tools/avrdude/upload/pattern" , compliancelevel .Permissive , assert .True },
203
- {"tools.avrdude.upload.pattern" , "tools/avrdude/upload/pattern" , compliancelevel .Specification , assert .True },
204
- {"tools.avrdude.upload.pattern" , "tools/avrdude/upload/pattern" , compliancelevel .Strict , assert .True },
203
+ {"tools.avrdude.upload.pattern" , "" , " tools/avrdude/upload/pattern" , compliancelevel .Permissive , assert .True },
204
+ {"tools.avrdude.upload.pattern" , "" , " tools/avrdude/upload/pattern" , compliancelevel .Specification , assert .True },
205
+ {"tools.avrdude.upload.pattern" , "" , " tools/avrdude/upload/pattern" , compliancelevel .Strict , assert .True },
205
206
206
- {"tools.avrdude.program.params.verbose" , "tools/avrdude/program/params\\ .verbose" , compliancelevel .Permissive , assert .True },
207
- {"tools.avrdude.program.params.verbose" , "tools/avrdude/program/params\\ .verbose" , compliancelevel .Specification , assert .True },
208
- {"tools.avrdude.program.params.verbose" , "tools/avrdude/program/params\\ .verbose" , compliancelevel .Strict , assert .True },
207
+ {"tools.avrdude.program.params.verbose" , "" , " tools/avrdude/program/params\\ .verbose" , compliancelevel .Permissive , assert .True },
208
+ {"tools.avrdude.program.params.verbose" , "" , " tools/avrdude/program/params\\ .verbose" , compliancelevel .Specification , assert .True },
209
+ {"tools.avrdude.program.params.verbose" , "" , " tools/avrdude/program/params\\ .verbose" , compliancelevel .Strict , assert .True },
209
210
210
- {"tools.avrdude.program.params.quiet" , "tools/avrdude/program/params\\ .quiet" , compliancelevel .Permissive , assert .True },
211
- {"tools.avrdude.program.params.quiet" , "tools/avrdude/program/params\\ .quiet" , compliancelevel .Specification , assert .True },
212
- {"tools.avrdude.program.params.quiet" , "tools/avrdude/program/params\\ .quiet" , compliancelevel .Strict , assert .True },
211
+ {"tools.avrdude.program.params.quiet" , "" , " tools/avrdude/program/params\\ .quiet" , compliancelevel .Permissive , assert .True },
212
+ {"tools.avrdude.program.params.quiet" , "" , " tools/avrdude/program/params\\ .quiet" , compliancelevel .Specification , assert .True },
213
+ {"tools.avrdude.program.params.quiet" , "" , " tools/avrdude/program/params\\ .quiet" , compliancelevel .Strict , assert .True },
213
214
214
- {"tools.avrdude.program.pattern" , "tools/avrdude/program/pattern" , compliancelevel .Permissive , assert .True },
215
- {"tools.avrdude.program.pattern" , "tools/avrdude/program/pattern" , compliancelevel .Specification , assert .True },
216
- {"tools.avrdude.program.pattern" , "tools/avrdude/program/pattern" , compliancelevel .Strict , assert .True },
215
+ {"tools.avrdude.program.pattern" , "" , " tools/avrdude/program/pattern" , compliancelevel .Permissive , assert .True },
216
+ {"tools.avrdude.program.pattern" , "" , " tools/avrdude/program/pattern" , compliancelevel .Specification , assert .True },
217
+ {"tools.avrdude.program.pattern" , "" , " tools/avrdude/program/pattern" , compliancelevel .Strict , assert .True },
217
218
218
- {"tools.bossac.upload.pattern" , "tools/bossac/upload/pattern" , compliancelevel .Permissive , assert .True },
219
- {"tools.bossac.upload.pattern" , "tools/bossac/upload/pattern" , compliancelevel .Specification , assert .True },
220
- {"tools.bossac.upload.pattern" , "tools/bossac/upload/pattern" , compliancelevel .Strict , assert .True },
219
+ {"tools.bossac.upload.pattern" , "" , " tools/bossac/upload/pattern" , compliancelevel .Permissive , assert .True },
220
+ {"tools.bossac.upload.pattern" , "" , " tools/bossac/upload/pattern" , compliancelevel .Specification , assert .True },
221
+ {"tools.bossac.upload.pattern" , "" , " tools/bossac/upload/pattern" , compliancelevel .Strict , assert .True },
221
222
222
- {"compiler.c.extra_flags" , "compiler.c.extra_flags" , compliancelevel .Permissive , assert .False },
223
- {"compiler.c.extra_flags" , "compiler.c.extra_flags" , compliancelevel .Specification , assert .False },
224
- {"compiler.c.extra_flags" , "compiler.c.extra_flags" , compliancelevel .Strict , assert .True },
223
+ {"compiler.c.extra_flags" , "" , " compiler.c.extra_flags" , compliancelevel .Permissive , assert .False },
224
+ {"compiler.c.extra_flags" , "" , " compiler.c.extra_flags" , compliancelevel .Specification , assert .False },
225
+ {"compiler.c.extra_flags" , "" , " compiler.c.extra_flags" , compliancelevel .Strict , assert .True },
225
226
226
- {"compiler.c.elf.extra_flags" , "compiler.c.elf.extra_flags" , compliancelevel .Permissive , assert .False },
227
- {"compiler.c.elf.extra_flags" , "compiler.c.elf.extra_flags" , compliancelevel .Specification , assert .False },
228
- {"compiler.c.elf.extra_flags" , "compiler.c.elf.extra_flags" , compliancelevel .Strict , assert .True },
227
+ {"compiler.c.elf.extra_flags" , "" , " compiler.c.elf.extra_flags" , compliancelevel .Permissive , assert .False },
228
+ {"compiler.c.elf.extra_flags" , "" , " compiler.c.elf.extra_flags" , compliancelevel .Specification , assert .False },
229
+ {"compiler.c.elf.extra_flags" , "" , " compiler.c.elf.extra_flags" , compliancelevel .Strict , assert .True },
229
230
230
- {"compiler.S.extra_flags" , "compiler.S.extra_flags" , compliancelevel .Permissive , assert .False },
231
- {"compiler.S.extra_flags" , "compiler.S.extra_flags" , compliancelevel .Specification , assert .False },
232
- {"compiler.S.extra_flags" , "compiler.S.extra_flags" , compliancelevel .Strict , assert .True },
231
+ {"compiler.S.extra_flags" , "" , " compiler.S.extra_flags" , compliancelevel .Permissive , assert .False },
232
+ {"compiler.S.extra_flags" , "" , " compiler.S.extra_flags" , compliancelevel .Specification , assert .False },
233
+ {"compiler.S.extra_flags" , "" , " compiler.S.extra_flags" , compliancelevel .Strict , assert .True },
233
234
234
- {"compiler.cpp.extra_flags" , "compiler.cpp.extra_flags" , compliancelevel .Permissive , assert .False },
235
- {"compiler.cpp.extra_flags" , "compiler.cpp.extra_flags" , compliancelevel .Specification , assert .False },
236
- {"compiler.cpp.extra_flags" , "compiler.cpp.extra_flags" , compliancelevel .Strict , assert .True },
235
+ {"compiler.cpp.extra_flags" , "" , " compiler.cpp.extra_flags" , compliancelevel .Permissive , assert .False },
236
+ {"compiler.cpp.extra_flags" , "" , " compiler.cpp.extra_flags" , compliancelevel .Specification , assert .False },
237
+ {"compiler.cpp.extra_flags" , "" , " compiler.cpp.extra_flags" , compliancelevel .Strict , assert .True },
237
238
238
- {"compiler.ar.extra_flags" , "compiler.ar.extra_flags" , compliancelevel .Permissive , assert .False },
239
- {"compiler.ar.extra_flags" , "compiler.ar.extra_flags" , compliancelevel .Specification , assert .False },
240
- {"compiler.ar.extra_flags" , "compiler.ar.extra_flags" , compliancelevel .Strict , assert .True },
239
+ {"compiler.ar.extra_flags" , "" , " compiler.ar.extra_flags" , compliancelevel .Permissive , assert .False },
240
+ {"compiler.ar.extra_flags" , "" , " compiler.ar.extra_flags" , compliancelevel .Specification , assert .False },
241
+ {"compiler.ar.extra_flags" , "" , " compiler.ar.extra_flags" , compliancelevel .Strict , assert .True },
241
242
242
- {"recipe.size.pattern" , "recipe.size.pattern" , compliancelevel .Permissive , assert .False },
243
- {"recipe.size.pattern" , "recipe.size.pattern" , compliancelevel .Specification , assert .False },
244
- {"recipe.size.pattern" , "recipe.size.pattern" , compliancelevel .Strict , assert .True },
243
+ {"recipe.size.pattern" , "" , " recipe.size.pattern" , compliancelevel .Permissive , assert .False },
244
+ {"recipe.size.pattern" , "" , " recipe.size.pattern" , compliancelevel .Specification , assert .False },
245
+ {"recipe.size.pattern" , "" , " recipe.size.pattern" , compliancelevel .Strict , assert .True },
245
246
246
- {"recipe.size.regex" , "recipe.size.regex" , compliancelevel .Permissive , assert .False },
247
- {"recipe.size.regex" , "recipe.size.regex" , compliancelevel .Specification , assert .False },
248
- {"recipe.size.regex" , "recipe.size.regex" , compliancelevel .Strict , assert .True },
247
+ {"recipe.size.regex" , "" , " recipe.size.regex" , compliancelevel .Permissive , assert .False },
248
+ {"recipe.size.regex" , "" , " recipe.size.regex" , compliancelevel .Specification , assert .False },
249
+ {"recipe.size.regex" , "" , " recipe.size.regex" , compliancelevel .Strict , assert .True },
249
250
250
- {"recipe.size.regex.data" , "recipe.size.regex.data" , compliancelevel .Permissive , assert .False },
251
- {"recipe.size.regex.data" , "recipe.size.regex.data" , compliancelevel .Specification , assert .False },
252
- {"recipe.size.regex.data" , "recipe.size.regex.data" , compliancelevel .Strict , assert .True },
251
+ {"recipe.size.regex.data" , "" , " recipe.size.regex.data" , compliancelevel .Permissive , assert .False },
252
+ {"recipe.size.regex.data" , "" , " recipe.size.regex.data" , compliancelevel .Specification , assert .False },
253
+ {"recipe.size.regex.data" , "" , " recipe.size.regex.data" , compliancelevel .Strict , assert .True },
253
254
}
254
255
255
256
for _ , testTable := range testTables {
256
257
platformTxt , err := properties .LoadFromBytes (validPlatformTxtRaw )
257
258
require .Nil (t , err )
258
259
platformTxt .Remove (testTable .propertyName )
260
+ if testTable .replacementPropertyName != "" {
261
+ platformTxt .Set (testTable .replacementPropertyName , "foo" )
262
+ }
259
263
260
264
validationResult := platformtxt .Validate (platformTxt )
261
265
t .Run (fmt .Sprintf ("%s (%s)" , testTable .propertyName , testTable .complianceLevel ), func (t * testing.T ) {
0 commit comments