From 090caf8c82087b643e05d70b6ce0d0bfef762c86 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 14 Dec 2020 06:23:41 -0800 Subject: [PATCH 1/2] Use appropriate check result value when determined not relevant There are various extents to which a check can be run: 1. Skipped due to check configuration (e.g., check is configured to run for libraries but the project is a sketch). 2. Not run due to a problem not directly related to the check (e.g., invalid library.properties data format). 3. Skipped because the check function determined it was not applicable (e.g., formating check on undefined optional library.properties field). 4. Run. Each has an associated check result value: Skip, NotRun, Pass/Fail. Previously, the "NotRun" result was used for both (2) and (3), but "Skip" is much more appropriate for (3) because this is a situation where there was no reason to run the check, whereas "NotRun" indicates that the check should have been run, but couldn't. --- check/checkfunctions/checkfunctions.go | 4 +- check/checkfunctions/checkfunctions_test.go | 4 +- check/checkfunctions/library.go | 137 +++++++++++--------- check/checkfunctions/library_test.go | 26 ++-- check/checkfunctions/sketch.go | 4 +- check/checkfunctions/sketch_test.go | 4 +- 6 files changed, 99 insertions(+), 80 deletions(-) diff --git a/check/checkfunctions/checkfunctions.go b/check/checkfunctions/checkfunctions.go index ef64a7fb1..dc1e282ff 100644 --- a/check/checkfunctions/checkfunctions.go +++ b/check/checkfunctions/checkfunctions.go @@ -72,7 +72,7 @@ func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName stri // MissingReadme checks if the project has a readme that will be recognized by GitHub. func MissingReadme() (result checkresult.Type, output string) { if checkdata.ProjectType() != checkdata.SuperProjectType() { - return checkresult.NotRun, "Readme not required for subprojects" + return checkresult.Skip, "Readme not required for subprojects" } // https://github.com/github/markup/blob/master/README.md @@ -91,7 +91,7 @@ func MissingReadme() (result checkresult.Type, output string) { // MissingLicenseFile checks if the project has a license file that will be recognized by GitHub. func MissingLicenseFile() (result checkresult.Type, output string) { if checkdata.ProjectType() != checkdata.SuperProjectType() { - return checkresult.NotRun, "License file not required for subprojects" + return checkresult.Skip, "License file not required for subprojects" } // https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/licensing-a-repository#detecting-a-license diff --git a/check/checkfunctions/checkfunctions_test.go b/check/checkfunctions/checkfunctions_test.go index c85adb849..7c5b42f89 100644 --- a/check/checkfunctions/checkfunctions_test.go +++ b/check/checkfunctions/checkfunctions_test.go @@ -64,7 +64,7 @@ func checkCheckFunction(checkFunction Type, testTables []checkFunctionTestTable, func TestMissingReadme(t *testing.T) { testTables := []checkFunctionTestTable{ - {"Subproject", "readme", projecttype.Sketch, projecttype.Library, checkresult.NotRun, ""}, + {"Subproject", "readme", projecttype.Sketch, projecttype.Library, checkresult.Skip, ""}, {"Readme", "readme", projecttype.Sketch, projecttype.Sketch, checkresult.Pass, ""}, {"No readme", "no-readme", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""}, } @@ -74,7 +74,7 @@ func TestMissingReadme(t *testing.T) { func TestMissingLicenseFile(t *testing.T) { testTables := []checkFunctionTestTable{ - {"Subproject", "no-license-file", projecttype.Sketch, projecttype.Library, checkresult.NotRun, ""}, + {"Subproject", "no-license-file", projecttype.Sketch, projecttype.Library, checkresult.Skip, ""}, {"Has license", "license-file", projecttype.Sketch, projecttype.Sketch, checkresult.Pass, ""}, {"Has license in subfolder", "license-file-in-subfolder", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""}, {"No license", "no-license-file", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""}, diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 1dbc0dce5..6f551911f 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -43,7 +43,7 @@ import ( // LibraryPropertiesFormat checks for invalid library.properties format. func LibraryPropertiesFormat() (result checkresult.Type, output string) { if checkdata.LoadedLibrary() != nil && checkdata.LoadedLibrary().IsLegacy { - return checkresult.NotRun, "Library has no library.properties" + return checkresult.Skip, "Library has no library.properties" } if checkdata.LibraryPropertiesLoadError() != nil { @@ -110,9 +110,12 @@ func RedundantLibraryProperties() (result checkresult.Type, output string) { // LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field. func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("name", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -340,9 +343,12 @@ func LibraryPropertiesNameFieldHeaderMismatch() (result checkresult.Type, output // LibraryPropertiesVersionFieldMissing checks for missing library.properties "version" field. func LibraryPropertiesVersionFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("version", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -390,7 +396,7 @@ func LibraryPropertiesVersionFieldNonSemver() (result checkresult.Type, output s // LibraryPropertiesVersionFieldBehindTag checks whether a release tag was made without first bumping the library.properties version value. func LibraryPropertiesVersionFieldBehindTag() (result checkresult.Type, output string) { if checkdata.ProjectType() != checkdata.SuperProjectType() { - return checkresult.NotRun, "Not relevant for subprojects" + return checkresult.Skip, "Not relevant for subprojects" } if checkdata.LibraryPropertiesLoadError() != nil { @@ -410,7 +416,7 @@ func LibraryPropertiesVersionFieldBehindTag() (result checkresult.Type, output s repository, err := git.PlainOpen(checkdata.ProjectPath().String()) if err != nil { - return checkresult.NotRun, "Project path is not a repository" + return checkresult.Skip, "Project path is not a repository" } headRef, err := repository.Head() @@ -482,9 +488,12 @@ func LibraryPropertiesVersionFieldBehindTag() (result checkresult.Type, output s // LibraryPropertiesAuthorFieldMissing checks for missing library.properties "author" field. func LibraryPropertiesAuthorFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("author", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -512,9 +521,12 @@ func LibraryPropertiesAuthorFieldLTMinLength() (result checkresult.Type, output // LibraryPropertiesMaintainerFieldMissing checks for missing library.properties "maintainer" field. func LibraryPropertiesMaintainerFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("maintainer", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -565,7 +577,7 @@ func LibraryPropertiesEmailFieldAsMaintainerAlias() (result checkresult.Type, ou } if !checkdata.LibraryProperties().ContainsKey("email") { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if !checkdata.LibraryProperties().ContainsKey("maintainer") { @@ -582,7 +594,7 @@ func LibraryPropertiesEmailFieldLTMinLength() (result checkresult.Type, output s } if checkdata.LibraryProperties().ContainsKey("maintainer") || !checkdata.LibraryProperties().ContainsKey("email") { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyLessThanMinLength("email", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -604,7 +616,7 @@ func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, ou email, ok := checkdata.LibraryProperties().GetOk("email") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.ValidationErrorMatch("^#/email$", "/patternObjects/notStartsWithArduino", "", "", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -616,9 +628,12 @@ func LibraryPropertiesEmailFieldStartsWithArduino() (result checkresult.Type, ou // LibraryPropertiesSentenceFieldMissing checks for missing library.properties "sentence" field. func LibraryPropertiesSentenceFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("sentence", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -651,9 +666,12 @@ func LibraryPropertiesSentenceFieldSpellCheck() (result checkresult.Type, output // LibraryPropertiesParagraphFieldMissing checks for missing library.properties "paragraph" field. func LibraryPropertiesParagraphFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("paragraph", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -688,9 +706,12 @@ func LibraryPropertiesParagraphFieldRepeatsSentence() (result checkresult.Type, // LibraryPropertiesCategoryFieldMissing checks for missing library.properties "category" field. func LibraryPropertiesCategoryFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -707,7 +728,7 @@ func LibraryPropertiesCategoryFieldInvalid() (result checkresult.Type, output st category, ok := checkdata.LibraryProperties().GetOk("category") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyEnumMismatch("category", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -725,7 +746,7 @@ func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, out category, ok := checkdata.LibraryProperties().GetOk("category") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if category == "Uncategorized" { @@ -737,9 +758,12 @@ func LibraryPropertiesCategoryFieldUncategorized() (result checkresult.Type, out // LibraryPropertiesUrlFieldMissing checks for missing library.properties "url" field. func LibraryPropertiesUrlFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("url", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -792,9 +816,12 @@ func LibraryPropertiesUrlFieldDeadLink() (result checkresult.Type, output string // LibraryPropertiesArchitecturesFieldMissing checks for missing library.properties "architectures" field. func LibraryPropertiesArchitecturesFieldMissing() (result checkresult.Type, output string) { - shouldRun, reason := runRequiredLibraryPropertiesFieldCheck() - if !shouldRun { - return checkresult.NotRun, reason + if checkdata.LibraryPropertiesLoadError() != nil { + return checkresult.NotRun, "Couldn't load library.properties" + } + + if checkdata.LoadedLibrary().IsLegacy { + return checkresult.Skip, "Library has legacy format" } if schema.RequiredPropertyMissing("architectures", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -810,7 +837,7 @@ func LibraryPropertiesArchitecturesFieldLTMinLength() (result checkresult.Type, } if !checkdata.LibraryProperties().ContainsKey("architectures") { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyLessThanMinLength("architectures", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -828,7 +855,7 @@ func LibraryPropertiesDependsFieldDisallowedCharacters() (result checkresult.Typ depends, ok := checkdata.LibraryProperties().GetOk("depends") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyPatternMismatch("depends", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -846,7 +873,7 @@ func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output depends, hasDepends := checkdata.LibraryProperties().GetOk("depends") if !hasDepends { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } dependencies := strings.Split(depends, ",") @@ -878,7 +905,7 @@ func LibraryPropertiesDotALinkageFieldInvalid() (result checkresult.Type, output dotALinkage, ok := checkdata.LibraryProperties().GetOk("dot_a_linkage") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyEnumMismatch("dot_a_linkage", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -895,7 +922,7 @@ func LibraryPropertiesDotALinkageFieldTrueWithFlatLayout() (result checkresult.T } if !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if checkdata.LoadedLibrary().DotALinkage && checkdata.LoadedLibrary().Layout == libraries.FlatLayout { @@ -912,7 +939,7 @@ func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, outpu } if !checkdata.LibraryProperties().ContainsKey("includes") { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyLessThanMinLength("includes", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -930,7 +957,7 @@ func LibraryPropertiesIncludesFieldItemNotFound() (result checkresult.Type, outp includes, ok := checkdata.LibraryProperties().GetOk("includes") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } includesList := strings.Split(includes, ",") @@ -972,7 +999,7 @@ func LibraryPropertiesPrecompiledFieldInvalid() (result checkresult.Type, output precompiled, ok := checkdata.LibraryProperties().GetOk("precompiled") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if schema.PropertyEnumMismatch("precompiled", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { @@ -990,7 +1017,7 @@ func LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout() (result checkresul precompiled, ok := checkdata.LibraryProperties().GetOk("precompiled") if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } if checkdata.LoadedLibrary().Precompiled && checkdata.LoadedLibrary().Layout == libraries.FlatLayout { @@ -1006,6 +1033,10 @@ func LibraryPropertiesLdflagsFieldLTMinLength() (result checkresult.Type, output return checkresult.NotRun, "Library not loaded" } + if !checkdata.LibraryProperties().ContainsKey("ldflags") { + return checkresult.Skip, "Field not present" + } + if schema.PropertyLessThanMinLength("ldflags", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) { return checkresult.Fail, "" } @@ -1175,7 +1206,7 @@ func LibraryFolderNameGTMaxLength() (result checkresult.Type, output string) { func IncorrectLibrarySrcFolderNameCase() (result checkresult.Type, output string) { if library.ContainsMetadataFile(checkdata.ProjectPath()) && library.ContainsHeaderFile(checkdata.ProjectPath()) { // Flat layout, so no special treatment of src subfolder. - return checkresult.NotRun, "Not applicable due to layout type" + return checkresult.Skip, "Not applicable due to layout type" } // The library is intended to have the recursive layout. @@ -1270,7 +1301,7 @@ func RecursiveLibraryWithUtilityFolder() (result checkresult.Type, output string } if checkdata.LoadedLibrary().Layout == libraries.FlatLayout { - return checkresult.NotRun, "Not applicable due to layout type" + return checkresult.Skip, "Not applicable due to layout type" } if checkdata.ProjectPath().Join("utility").Exist() { @@ -1288,7 +1319,7 @@ func spellCheckLibraryPropertiesFieldValue(fieldName string) (result checkresult fieldValue, ok := checkdata.LibraryProperties().GetOk(fieldName) if !ok { - return checkresult.NotRun, "Field not present" + return checkresult.Skip, "Field not present" } replaced, diff := checkdata.MisspelledWordsReplacer().Replace(fieldValue) @@ -1327,15 +1358,3 @@ func nameInLibraryManagerIndex(name string) bool { return false } - -func runRequiredLibraryPropertiesFieldCheck() (bool, string) { - if checkdata.LibraryPropertiesLoadError() != nil { - return false, "Couldn't load library.properties" - } - - if checkdata.LoadedLibrary().IsLegacy { - return false, "Library has legacy format" - } - - return true, "" -} diff --git a/check/checkfunctions/library_test.go b/check/checkfunctions/library_test.go index dbefeddcf..72939d91a 100644 --- a/check/checkfunctions/library_test.go +++ b/check/checkfunctions/library_test.go @@ -107,7 +107,7 @@ func TestRedundantLibraryProperties(t *testing.T) { func TestLibraryPropertiesFormat(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Invalid", "InvalidLibraryProperties", checkresult.Fail, ""}, - {"Legacy", "Legacy", checkresult.NotRun, ""}, + {"Legacy", "Legacy", checkresult.Skip, ""}, {"Valid", "Recursive", checkresult.Pass, ""}, } @@ -240,11 +240,11 @@ func TestLibraryPropertiesVersionFieldBehindTag(t *testing.T) { } testTables := []libraryCheckFunctionTestTable{ - // TODO: Test NotRun if subproject + // TODO: Test Skip if subproject {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, {"Legacy", "Legacy", checkresult.NotRun, ""}, {"Unparsable version", "VersionFormatInvalid", checkresult.NotRun, ""}, - {"Not repo", "Recursive", checkresult.NotRun, ""}, + {"Not repo", "Recursive", checkresult.Skip, ""}, {"Tag name not a version", gitInitAndTag(t, TagNotVersionPath, "foo", true), checkresult.Pass, ""}, {"Match w/ tag prefix", gitInitAndTag(t, TagMatchWithPrefixPath, "1.0.0", true), checkresult.Pass, ""}, {"Pre-release tag greater", gitInitAndTag(t, TagPrereleaseGreaterPath, "1.0.1-rc1", true), checkresult.Pass, ""}, @@ -262,7 +262,7 @@ func TestLibraryPropertiesVersionFieldBehindTag(t *testing.T) { func TestLibraryPropertiesSentenceFieldSpellCheck(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, - {"Not defined", "MissingFields", checkresult.NotRun, ""}, + {"Not defined", "MissingFields", checkresult.Skip, ""}, {"Misspelled word", "MisspelledSentenceParagraphValue", checkresult.Fail, "^grill broccoli now$"}, {"Non-nil diff but no typos", "SpuriousMisspelledSentenceParagraphValue", checkresult.Pass, ""}, {"Correct spelling", "Recursive", checkresult.Pass, ""}, @@ -274,7 +274,7 @@ func TestLibraryPropertiesSentenceFieldSpellCheck(t *testing.T) { func TestLibraryPropertiesParagraphFieldSpellCheck(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, - {"Not defined", "MissingFields", checkresult.NotRun, ""}, + {"Not defined", "MissingFields", checkresult.Skip, ""}, {"Misspelled word", "MisspelledSentenceParagraphValue", checkresult.Fail, "^There is a zebra$"}, {"Non-nil diff but no typos", "SpuriousMisspelledSentenceParagraphValue", checkresult.Pass, ""}, {"Correct spelling", "Recursive", checkresult.Pass, ""}, @@ -310,7 +310,7 @@ func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) { {"Dependency not in index", "DependsNotIndexed", checkresult.Fail, "^NotIndexed$"}, {"Dependency in index", "DependsIndexed", checkresult.Pass, ""}, {"Depends field empty", "DependsEmpty", checkresult.Pass, ""}, - {"No depends", "NoDepends", checkresult.NotRun, ""}, + {"No depends", "NoDepends", checkresult.Skip, ""}, } checkLibraryCheckFunction(LibraryPropertiesDependsFieldNotInIndex, testTables, t) @@ -319,7 +319,7 @@ func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) { func TestLibraryPropertiesDotALinkageFieldTrueWithFlatLayout(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, - {"Not defined", "MissingFields", checkresult.NotRun, ""}, + {"Not defined", "MissingFields", checkresult.Skip, ""}, {"Flat layout", "DotALinkageFlat", checkresult.Fail, ""}, {"Recursive layout", "DotALinkage", checkresult.Pass, ""}, } @@ -330,7 +330,7 @@ func TestLibraryPropertiesDotALinkageFieldTrueWithFlatLayout(t *testing.T) { func TestLibraryPropertiesIncludesFieldItemNotFound(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, - {"Not defined", "MissingFields", checkresult.NotRun, ""}, + {"Not defined", "MissingFields", checkresult.Skip, ""}, {"Missing includes", "MissingIncludes", checkresult.Fail, "^Nonexistent.h$"}, {"Present includes", "Recursive", checkresult.Pass, ""}, } @@ -341,11 +341,11 @@ func TestLibraryPropertiesIncludesFieldItemNotFound(t *testing.T) { func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, - {"Not defined", "MissingFields", checkresult.NotRun, ""}, + {"Not defined", "MissingFields", checkresult.Skip, ""}, {"Flat layout", "PrecompiledFlat", checkresult.Fail, "^true$"}, {"Recursive layout", "Precompiled", checkresult.Pass, ""}, - {"Recursive, not precompiled", "NotPrecompiled", checkresult.NotRun, ""}, - {"Flat, not precompiled", "Flat", checkresult.NotRun, ""}, + {"Recursive, not precompiled", "NotPrecompiled", checkresult.Skip, ""}, + {"Flat, not precompiled", "Flat", checkresult.Skip, ""}, } checkLibraryCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t) @@ -444,7 +444,7 @@ func TestLibraryFolderNameGTMaxLength(t *testing.T) { func TestIncorrectLibrarySrcFolderNameCase(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ - {"Flat, not precompiled", "Flat", checkresult.NotRun, ""}, + {"Flat, not precompiled", "Flat", checkresult.Skip, ""}, {"Incorrect case", "IncorrectSrcFolderNameCase", checkresult.Fail, ""}, {"Correct case", "Recursive", checkresult.Pass, ""}, } @@ -505,7 +505,7 @@ func TestIncorrectExtrasFolderNameCase(t *testing.T) { func TestRecursiveLibraryWithUtilityFolder(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, - {"Flat", "Flat", checkresult.NotRun, ""}, + {"Flat", "Flat", checkresult.Skip, ""}, {"Recursive with utility", "RecursiveWithUtilityFolder", checkresult.Fail, ""}, {"Recursive without utility", "Recursive", checkresult.Pass, ""}, } diff --git a/check/checkfunctions/sketch.go b/check/checkfunctions/sketch.go index 7ba5a5711..4844a5d89 100644 --- a/check/checkfunctions/sketch.go +++ b/check/checkfunctions/sketch.go @@ -106,7 +106,7 @@ func PdeSketchExtension() (result checkresult.Type, output string) { func SketchDotJSONJSONFormat() (result checkresult.Type, output string) { metadataPath := sketch.MetadataPath(checkdata.ProjectPath()) if metadataPath == nil { - return checkresult.NotRun, "No metadata file" + return checkresult.Skip, "No metadata file" } if isValidJSON(metadataPath) { @@ -120,7 +120,7 @@ func SketchDotJSONJSONFormat() (result checkresult.Type, output string) { func SketchDotJSONFormat() (result checkresult.Type, output string) { metadataPath := sketch.MetadataPath(checkdata.ProjectPath()) if metadataPath == nil { - return checkresult.NotRun, "No metadata file" + return checkresult.Skip, "No metadata file" } if checkdata.MetadataLoadError() == nil { diff --git a/check/checkfunctions/sketch_test.go b/check/checkfunctions/sketch_test.go index dc96dca3e..c0cc8fe1e 100644 --- a/check/checkfunctions/sketch_test.go +++ b/check/checkfunctions/sketch_test.go @@ -98,7 +98,7 @@ func TestPdeSketchExtension(t *testing.T) { func TestSketchDotJSONJSONFormat(t *testing.T) { testTables := []sketchCheckFunctionTestTable{ - {"No metadata file", "NoMetadataFile", checkresult.NotRun, ""}, + {"No metadata file", "NoMetadataFile", checkresult.Skip, ""}, {"Valid", "ValidMetadataFile", checkresult.Pass, ""}, {"Invalid", "InvalidJSONMetadataFile", checkresult.Fail, ""}, } @@ -108,7 +108,7 @@ func TestSketchDotJSONJSONFormat(t *testing.T) { func TestSketchDotJSONFormat(t *testing.T) { testTables := []sketchCheckFunctionTestTable{ - {"No metadata file", "NoMetadataFile", checkresult.NotRun, ""}, + {"No metadata file", "NoMetadataFile", checkresult.Skip, ""}, {"Valid", "ValidMetadataFile", checkresult.Pass, ""}, {"Invalid JSON", "InvalidJSONMetadataFile", checkresult.Fail, ""}, {"Invalid data", "InvalidDataMetadataFile", checkresult.Fail, ""}, From 401f029eac1c1be9b23fad86243f11ffbda53832 Mon Sep 17 00:00:00 2001 From: per1234 Date: Mon, 14 Dec 2020 06:24:03 -0800 Subject: [PATCH 2/2] Add missing tests for library check functions --- check/checkfunctions/library_test.go | 23 +++++++++++++++++++ .../EmailAndMaintainer/library.properties | 10 ++++++++ .../src/EmailAndMaintainer.h | 0 .../libraries/EmailOnly/library.properties | 9 ++++++++ .../libraries/EmailOnly/src/EmailOnly.h | 0 .../library.properties | 9 ++++++++ .../src/UncategorizedCategoryValue.h | 0 7 files changed, 51 insertions(+) create mode 100644 check/checkfunctions/testdata/libraries/EmailAndMaintainer/library.properties create mode 100644 check/checkfunctions/testdata/libraries/EmailAndMaintainer/src/EmailAndMaintainer.h create mode 100644 check/checkfunctions/testdata/libraries/EmailOnly/library.properties create mode 100644 check/checkfunctions/testdata/libraries/EmailOnly/src/EmailOnly.h create mode 100644 check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/library.properties create mode 100644 check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/src/UncategorizedCategoryValue.h diff --git a/check/checkfunctions/library_test.go b/check/checkfunctions/library_test.go index 72939d91a..098bd8e0b 100644 --- a/check/checkfunctions/library_test.go +++ b/check/checkfunctions/library_test.go @@ -283,6 +283,17 @@ func TestLibraryPropertiesParagraphFieldSpellCheck(t *testing.T) { checkLibraryCheckFunction(LibraryPropertiesParagraphFieldSpellCheck, testTables, t) } +func TestLibraryPropertiesEmailFieldAsMaintainerAlias(t *testing.T) { + testTables := []libraryCheckFunctionTestTable{ + {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, + {"No email field", "MissingFields", checkresult.Skip, ""}, + {"email in place of maintainer", "EmailOnly", checkresult.Fail, ""}, + {"email and maintainer", "EmailAndMaintainer", checkresult.Pass, ""}, + } + + checkLibraryCheckFunction(LibraryPropertiesEmailFieldAsMaintainerAlias, testTables, t) +} + func TestLibraryPropertiesParagraphFieldRepeatsSentence(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, @@ -292,6 +303,18 @@ func TestLibraryPropertiesParagraphFieldRepeatsSentence(t *testing.T) { checkLibraryCheckFunction(LibraryPropertiesParagraphFieldRepeatsSentence, testTables, t) } + +func TestLibraryPropertiesCategoryFieldUncategorized(t *testing.T) { + testTables := []libraryCheckFunctionTestTable{ + {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, + {"No category field", "MissingFields", checkresult.Skip, ""}, + {"Uncategorized category", "UncategorizedCategoryValue", checkresult.Fail, ""}, + {"Valid category value", "Recursive", checkresult.Pass, ""}, + } + + checkLibraryCheckFunction(LibraryPropertiesCategoryFieldUncategorized, testTables, t) +} + func TestLibraryPropertiesUrlFieldDeadLink(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, diff --git a/check/checkfunctions/testdata/libraries/EmailAndMaintainer/library.properties b/check/checkfunctions/testdata/libraries/EmailAndMaintainer/library.properties new file mode 100644 index 000000000..9ad2514fa --- /dev/null +++ b/check/checkfunctions/testdata/libraries/EmailAndMaintainer/library.properties @@ -0,0 +1,10 @@ +name=EmailAndMaintainer +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +email=Cristian Maglie +sentence=A library that makes coding a web server a breeze. +paragraph=Supports HTTP1.1 and you can do GET and POST. +category=Communication +url=http://example.com/ +architectures=avr diff --git a/check/checkfunctions/testdata/libraries/EmailAndMaintainer/src/EmailAndMaintainer.h b/check/checkfunctions/testdata/libraries/EmailAndMaintainer/src/EmailAndMaintainer.h new file mode 100644 index 000000000..e69de29bb diff --git a/check/checkfunctions/testdata/libraries/EmailOnly/library.properties b/check/checkfunctions/testdata/libraries/EmailOnly/library.properties new file mode 100644 index 000000000..d10347484 --- /dev/null +++ b/check/checkfunctions/testdata/libraries/EmailOnly/library.properties @@ -0,0 +1,9 @@ +name=EmailOnly +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +email=Cristian Maglie +sentence=A library that makes coding a web server a breeze. +paragraph=Supports HTTP1.1 and you can do GET and POST. +category=Communication +url=http://example.com/ +architectures=avr diff --git a/check/checkfunctions/testdata/libraries/EmailOnly/src/EmailOnly.h b/check/checkfunctions/testdata/libraries/EmailOnly/src/EmailOnly.h new file mode 100644 index 000000000..e69de29bb diff --git a/check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/library.properties b/check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/library.properties new file mode 100644 index 000000000..f311abbb3 --- /dev/null +++ b/check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/library.properties @@ -0,0 +1,9 @@ +name=UncategorizedCategoryValue +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +sentence=A library that makes coding a web server a breeze. +paragraph=Supports HTTP1.1 and you can do GET and POST. +category=Uncategorized +url=http://example.com/ +architectures=avr diff --git a/check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/src/UncategorizedCategoryValue.h b/check/checkfunctions/testdata/libraries/UncategorizedCategoryValue/src/UncategorizedCategoryValue.h new file mode 100644 index 000000000..e69de29bb