Skip to content

Add support for platform properties introduced for pluggable discovery #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 2, 2021
Merged
Prev Previous commit
Next Next commit
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.
  • Loading branch information
per1234 committed Sep 2, 2021
commit b5950b70c3ea68e08ff090a3b8cacc29d82250ff
154 changes: 79 additions & 75 deletions internal/project/platform/platformtxt/platformtxtschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,115 +147,119 @@ func TestMinLength(t *testing.T) {
func TestRequired(t *testing.T) {
testTables := []struct {
propertyName string
replacementPropertyName string // Used for testing subkeys that are required only when the higher level key is present.
validationErrorPropertyName string
complianceLevel compliancelevel.Type
assertion assert.BoolAssertionFunc
}{
{"name", "name", compliancelevel.Permissive, assert.True},
{"name", "name", compliancelevel.Specification, assert.True},
{"name", "name", compliancelevel.Strict, assert.True},
{"name", "", "name", compliancelevel.Permissive, assert.True},
{"name", "", "name", compliancelevel.Specification, assert.True},
{"name", "", "name", compliancelevel.Strict, assert.True},

{"version", "version", compliancelevel.Permissive, assert.True},
{"version", "version", compliancelevel.Specification, assert.True},
{"version", "version", compliancelevel.Strict, assert.True},
{"version", "", "version", compliancelevel.Permissive, assert.True},
{"version", "", "version", compliancelevel.Specification, assert.True},
{"version", "", "version", compliancelevel.Strict, assert.True},

{"compiler.warning_flags.none", "compiler\\.warning_flags\\.none", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.none", "compiler\\.warning_flags\\.none", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.none", "compiler\\.warning_flags\\.none", compliancelevel.Strict, assert.True},
{"compiler.warning_flags.none", "", "compiler\\.warning_flags\\.none", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.none", "", "compiler\\.warning_flags\\.none", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.none", "", "compiler\\.warning_flags\\.none", compliancelevel.Strict, assert.True},

{"compiler.warning_flags.default", "compiler\\.warning_flags\\.default", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.default", "compiler\\.warning_flags\\.default", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.default", "compiler\\.warning_flags\\.default", compliancelevel.Strict, assert.True},
{"compiler.warning_flags.default", "", "compiler\\.warning_flags\\.default", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.default", "", "compiler\\.warning_flags\\.default", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.default", "", "compiler\\.warning_flags\\.default", compliancelevel.Strict, assert.True},

{"compiler.warning_flags.more", "compiler\\.warning_flags\\.more", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.more", "compiler\\.warning_flags\\.more", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.more", "compiler\\.warning_flags\\.more", compliancelevel.Strict, assert.True},
{"compiler.warning_flags.more", "", "compiler\\.warning_flags\\.more", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.more", "", "compiler\\.warning_flags\\.more", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.more", "", "compiler\\.warning_flags\\.more", compliancelevel.Strict, assert.True},

{"compiler.warning_flags.all", "compiler\\.warning_flags\\.all", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.all", "compiler\\.warning_flags\\.all", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.all", "compiler\\.warning_flags\\.all", compliancelevel.Strict, assert.True},
{"compiler.warning_flags.all", "", "compiler\\.warning_flags\\.all", compliancelevel.Permissive, assert.False},
{"compiler.warning_flags.all", "", "compiler\\.warning_flags\\.all", compliancelevel.Specification, assert.False},
{"compiler.warning_flags.all", "", "compiler\\.warning_flags\\.all", compliancelevel.Strict, assert.True},

{"recipe.c.o.pattern", "recipe\\.c\\.o\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.c.o.pattern", "recipe\\.c\\.o\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.c.o.pattern", "recipe\\.c\\.o\\.pattern", compliancelevel.Strict, assert.True},
{"recipe.c.o.pattern", "", "recipe\\.c\\.o\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.c.o.pattern", "", "recipe\\.c\\.o\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.c.o.pattern", "", "recipe\\.c\\.o\\.pattern", compliancelevel.Strict, assert.True},

{"recipe.cpp.o.pattern", "recipe\\.cpp\\.o\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.cpp.o.pattern", "recipe\\.cpp\\.o\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.cpp.o.pattern", "recipe\\.cpp\\.o\\.pattern", compliancelevel.Strict, assert.True},
{"recipe.cpp.o.pattern", "", "recipe\\.cpp\\.o\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.cpp.o.pattern", "", "recipe\\.cpp\\.o\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.cpp.o.pattern", "", "recipe\\.cpp\\.o\\.pattern", compliancelevel.Strict, assert.True},

{"recipe.S.o.pattern", "recipe\\.S\\.o\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.S.o.pattern", "recipe\\.S\\.o\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.S.o.pattern", "recipe\\.S\\.o\\.pattern", compliancelevel.Strict, assert.True},
{"recipe.S.o.pattern", "", "recipe\\.S\\.o\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.S.o.pattern", "", "recipe\\.S\\.o\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.S.o.pattern", "", "recipe\\.S\\.o\\.pattern", compliancelevel.Strict, assert.True},

{"recipe.ar.pattern", "recipe\\.ar\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.ar.pattern", "recipe\\.ar\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.ar.pattern", "recipe\\.ar\\.pattern", compliancelevel.Strict, assert.True},
{"recipe.ar.pattern", "", "recipe\\.ar\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.ar.pattern", "", "recipe\\.ar\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.ar.pattern", "", "recipe\\.ar\\.pattern", compliancelevel.Strict, assert.True},

{"recipe.c.combine.pattern", "recipe\\.c\\.combine\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.c.combine.pattern", "recipe\\.c\\.combine\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.c.combine.pattern", "recipe\\.c\\.combine\\.pattern", compliancelevel.Strict, assert.True},
{"recipe.c.combine.pattern", "", "recipe\\.c\\.combine\\.pattern", compliancelevel.Permissive, assert.True},
{"recipe.c.combine.pattern", "", "recipe\\.c\\.combine\\.pattern", compliancelevel.Specification, assert.True},
{"recipe.c.combine.pattern", "", "recipe\\.c\\.combine\\.pattern", compliancelevel.Strict, assert.True},

{"recipe.output.tmp_file", "recipe\\.output\\.tmp_file", compliancelevel.Permissive, assert.True},
{"recipe.output.tmp_file", "recipe\\.output\\.tmp_file", compliancelevel.Specification, assert.True},
{"recipe.output.tmp_file", "recipe\\.output\\.tmp_file", compliancelevel.Strict, assert.True},
{"recipe.output.tmp_file", "", "recipe\\.output\\.tmp_file", compliancelevel.Permissive, assert.True},
{"recipe.output.tmp_file", "", "recipe\\.output\\.tmp_file", compliancelevel.Specification, assert.True},
{"recipe.output.tmp_file", "", "recipe\\.output\\.tmp_file", compliancelevel.Strict, assert.True},

{"tools.avrdude.upload.pattern", "tools/avrdude/upload/pattern", compliancelevel.Permissive, assert.True},
{"tools.avrdude.upload.pattern", "tools/avrdude/upload/pattern", compliancelevel.Specification, assert.True},
{"tools.avrdude.upload.pattern", "tools/avrdude/upload/pattern", compliancelevel.Strict, assert.True},
{"tools.avrdude.upload.pattern", "", "tools/avrdude/upload/pattern", compliancelevel.Permissive, assert.True},
{"tools.avrdude.upload.pattern", "", "tools/avrdude/upload/pattern", compliancelevel.Specification, assert.True},
{"tools.avrdude.upload.pattern", "", "tools/avrdude/upload/pattern", compliancelevel.Strict, assert.True},

{"tools.avrdude.program.params.verbose", "tools/avrdude/program/params\\.verbose", compliancelevel.Permissive, assert.True},
{"tools.avrdude.program.params.verbose", "tools/avrdude/program/params\\.verbose", compliancelevel.Specification, assert.True},
{"tools.avrdude.program.params.verbose", "tools/avrdude/program/params\\.verbose", compliancelevel.Strict, assert.True},
{"tools.avrdude.program.params.verbose", "", "tools/avrdude/program/params\\.verbose", compliancelevel.Permissive, assert.True},
{"tools.avrdude.program.params.verbose", "", "tools/avrdude/program/params\\.verbose", compliancelevel.Specification, assert.True},
{"tools.avrdude.program.params.verbose", "", "tools/avrdude/program/params\\.verbose", compliancelevel.Strict, assert.True},

{"tools.avrdude.program.params.quiet", "tools/avrdude/program/params\\.quiet", compliancelevel.Permissive, assert.True},
{"tools.avrdude.program.params.quiet", "tools/avrdude/program/params\\.quiet", compliancelevel.Specification, assert.True},
{"tools.avrdude.program.params.quiet", "tools/avrdude/program/params\\.quiet", compliancelevel.Strict, assert.True},
{"tools.avrdude.program.params.quiet", "", "tools/avrdude/program/params\\.quiet", compliancelevel.Permissive, assert.True},
{"tools.avrdude.program.params.quiet", "", "tools/avrdude/program/params\\.quiet", compliancelevel.Specification, assert.True},
{"tools.avrdude.program.params.quiet", "", "tools/avrdude/program/params\\.quiet", compliancelevel.Strict, assert.True},

{"tools.avrdude.program.pattern", "tools/avrdude/program/pattern", compliancelevel.Permissive, assert.True},
{"tools.avrdude.program.pattern", "tools/avrdude/program/pattern", compliancelevel.Specification, assert.True},
{"tools.avrdude.program.pattern", "tools/avrdude/program/pattern", compliancelevel.Strict, assert.True},
{"tools.avrdude.program.pattern", "", "tools/avrdude/program/pattern", compliancelevel.Permissive, assert.True},
{"tools.avrdude.program.pattern", "", "tools/avrdude/program/pattern", compliancelevel.Specification, assert.True},
{"tools.avrdude.program.pattern", "", "tools/avrdude/program/pattern", compliancelevel.Strict, assert.True},

{"tools.bossac.upload.pattern", "tools/bossac/upload/pattern", compliancelevel.Permissive, assert.True},
{"tools.bossac.upload.pattern", "tools/bossac/upload/pattern", compliancelevel.Specification, assert.True},
{"tools.bossac.upload.pattern", "tools/bossac/upload/pattern", compliancelevel.Strict, assert.True},
{"tools.bossac.upload.pattern", "", "tools/bossac/upload/pattern", compliancelevel.Permissive, assert.True},
{"tools.bossac.upload.pattern", "", "tools/bossac/upload/pattern", compliancelevel.Specification, assert.True},
{"tools.bossac.upload.pattern", "", "tools/bossac/upload/pattern", compliancelevel.Strict, assert.True},

{"compiler.c.extra_flags", "compiler.c.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.c.extra_flags", "compiler.c.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.c.extra_flags", "compiler.c.extra_flags", compliancelevel.Strict, assert.True},
{"compiler.c.extra_flags", "", "compiler.c.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.c.extra_flags", "", "compiler.c.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.c.extra_flags", "", "compiler.c.extra_flags", compliancelevel.Strict, assert.True},

{"compiler.c.elf.extra_flags", "compiler.c.elf.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.c.elf.extra_flags", "compiler.c.elf.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.c.elf.extra_flags", "compiler.c.elf.extra_flags", compliancelevel.Strict, assert.True},
{"compiler.c.elf.extra_flags", "", "compiler.c.elf.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.c.elf.extra_flags", "", "compiler.c.elf.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.c.elf.extra_flags", "", "compiler.c.elf.extra_flags", compliancelevel.Strict, assert.True},

{"compiler.S.extra_flags", "compiler.S.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.S.extra_flags", "compiler.S.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.S.extra_flags", "compiler.S.extra_flags", compliancelevel.Strict, assert.True},
{"compiler.S.extra_flags", "", "compiler.S.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.S.extra_flags", "", "compiler.S.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.S.extra_flags", "", "compiler.S.extra_flags", compliancelevel.Strict, assert.True},

{"compiler.cpp.extra_flags", "compiler.cpp.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.cpp.extra_flags", "compiler.cpp.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.cpp.extra_flags", "compiler.cpp.extra_flags", compliancelevel.Strict, assert.True},
{"compiler.cpp.extra_flags", "", "compiler.cpp.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.cpp.extra_flags", "", "compiler.cpp.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.cpp.extra_flags", "", "compiler.cpp.extra_flags", compliancelevel.Strict, assert.True},

{"compiler.ar.extra_flags", "compiler.ar.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.ar.extra_flags", "compiler.ar.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.ar.extra_flags", "compiler.ar.extra_flags", compliancelevel.Strict, assert.True},
{"compiler.ar.extra_flags", "", "compiler.ar.extra_flags", compliancelevel.Permissive, assert.False},
{"compiler.ar.extra_flags", "", "compiler.ar.extra_flags", compliancelevel.Specification, assert.False},
{"compiler.ar.extra_flags", "", "compiler.ar.extra_flags", compliancelevel.Strict, assert.True},

{"recipe.size.pattern", "recipe.size.pattern", compliancelevel.Permissive, assert.False},
{"recipe.size.pattern", "recipe.size.pattern", compliancelevel.Specification, assert.False},
{"recipe.size.pattern", "recipe.size.pattern", compliancelevel.Strict, assert.True},
{"recipe.size.pattern", "", "recipe.size.pattern", compliancelevel.Permissive, assert.False},
{"recipe.size.pattern", "", "recipe.size.pattern", compliancelevel.Specification, assert.False},
{"recipe.size.pattern", "", "recipe.size.pattern", compliancelevel.Strict, assert.True},

{"recipe.size.regex", "recipe.size.regex", compliancelevel.Permissive, assert.False},
{"recipe.size.regex", "recipe.size.regex", compliancelevel.Specification, assert.False},
{"recipe.size.regex", "recipe.size.regex", compliancelevel.Strict, assert.True},
{"recipe.size.regex", "", "recipe.size.regex", compliancelevel.Permissive, assert.False},
{"recipe.size.regex", "", "recipe.size.regex", compliancelevel.Specification, assert.False},
{"recipe.size.regex", "", "recipe.size.regex", compliancelevel.Strict, assert.True},

{"recipe.size.regex.data", "recipe.size.regex.data", compliancelevel.Permissive, assert.False},
{"recipe.size.regex.data", "recipe.size.regex.data", compliancelevel.Specification, assert.False},
{"recipe.size.regex.data", "recipe.size.regex.data", compliancelevel.Strict, assert.True},
{"recipe.size.regex.data", "", "recipe.size.regex.data", compliancelevel.Permissive, assert.False},
{"recipe.size.regex.data", "", "recipe.size.regex.data", compliancelevel.Specification, assert.False},
{"recipe.size.regex.data", "", "recipe.size.regex.data", compliancelevel.Strict, assert.True},
}

for _, testTable := range testTables {
platformTxt, err := properties.LoadFromBytes(validPlatformTxtRaw)
require.Nil(t, err)
platformTxt.Remove(testTable.propertyName)
if testTable.replacementPropertyName != "" {
platformTxt.Set(testTable.replacementPropertyName, "foo")
}

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