Skip to content

Commit b5950b7

Browse files
committed
Add capability to test for required subproperties in platform.txt
An optional property may have a required subproperty. Previously, the test only allowed testing for required root properties, by removing the property entirely. In order to test for required subproperties, it is necessary to add a root property that is missing the subproperty in addition to removing the required property.
1 parent ad66228 commit b5950b7

File tree

1 file changed

+79
-75
lines changed

1 file changed

+79
-75
lines changed

internal/project/platform/platformtxt/platformtxtschema_test.go

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -147,115 +147,119 @@ func TestMinLength(t *testing.T) {
147147
func TestRequired(t *testing.T) {
148148
testTables := []struct {
149149
propertyName string
150+
replacementPropertyName string // Used for testing subkeys that are required only when the higher level key is present.
150151
validationErrorPropertyName string
151152
complianceLevel compliancelevel.Type
152153
assertion assert.BoolAssertionFunc
153154
}{
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},
157158

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},
161162

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},
165166

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},
169170

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},
173174

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},
177178

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},
181182

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},
185186

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},
189190

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},
193194

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},
197198

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},
201202

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},
205206

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},
209210

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},
213214

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},
217218

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},
221222

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},
225226

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},
229230

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},
233234

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},
237238

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},
241242

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},
245246

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},
249250

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},
253254
}
254255

255256
for _, testTable := range testTables {
256257
platformTxt, err := properties.LoadFromBytes(validPlatformTxtRaw)
257258
require.Nil(t, err)
258259
platformTxt.Remove(testTable.propertyName)
260+
if testTable.replacementPropertyName != "" {
261+
platformTxt.Set(testTable.replacementPropertyName, "foo")
262+
}
259263

260264
validationResult := platformtxt.Validate(platformTxt)
261265
t.Run(fmt.Sprintf("%s (%s)", testTable.propertyName, testTable.complianceLevel), func(t *testing.T) {

0 commit comments

Comments
 (0)