Skip to content

Correct and improve checks #90

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 8 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions check/checkconfigurations/checkconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ var configurations = []Type{
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
WarningModes: []checkmode.Type{checkmode.Default},
ErrorModes: []checkmode.Type{checkmode.Strict},
CheckFunction: checkfunctions.MisspelledLibraryPropertiesFileName,
},
{
Expand Down Expand Up @@ -198,7 +198,7 @@ var configurations = []Type{
ID: "LP003",
Brief: "disallowed characters",
Description: "",
MessageTemplate: "disallowed characters in library.properties name field. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
MessageTemplate: "disallowed characters in library.properties name value: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
Expand Down Expand Up @@ -232,8 +232,8 @@ var configurations = []Type{
DisableModes: []checkmode.Type{checkmode.Official},
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
WarningModes: []checkmode.Type{checkmode.Default},
ErrorModes: []checkmode.Type{checkmode.LibraryManagerSubmission, checkmode.Strict},
CheckFunction: checkfunctions.LibraryPropertiesNameFieldStartsWithArduino,
},
{
Expand All @@ -247,8 +247,8 @@ var configurations = []Type{
DisableModes: []checkmode.Type{checkmode.Default},
EnableModes: []checkmode.Type{checkmode.Official},
InfoModes: nil,
WarningModes: nil,
ErrorModes: []checkmode.Type{checkmode.Official},
WarningModes: []checkmode.Type{checkmode.Default},
ErrorModes: []checkmode.Type{checkmode.Strict},
CheckFunction: checkfunctions.LibraryPropertiesNameFieldMissingOfficialPrefix,
},
{
Expand Down Expand Up @@ -1008,7 +1008,7 @@ var configurations = []Type{
ID: "",
Brief: "incorrect src folder case",
Description: "",
MessageTemplate: "Incorrect src folder case. This will cause the library to not be recognized on case-sensitive operating systems. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-root-folder",
MessageTemplate: "Incorrect src folder case: {{.}}. This will cause the library to not be recognized on case-sensitive operating systems. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-root-folder",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
Expand Down Expand Up @@ -1098,12 +1098,12 @@ var configurations = []Type{
ID: "",
Brief: "incorrect src folder case",
Description: "",
MessageTemplate: "Incorrect src folder case. This will cause the source files under it to not be compiled on case-sensitive operating systems. See: https://arduino.github.io/arduino-cli/latest/sketch-specification/#src-subfolder",
MessageTemplate: "Incorrect src folder case: {{.}}. This will cause the source files under it to not be compiled on case-sensitive operating systems. See: https://arduino.github.io/arduino-cli/latest/sketch-specification/#src-subfolder",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.Default},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.Default},
ErrorModes: []checkmode.Type{checkmode.Strict},
WarningModes: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
CheckFunction: checkfunctions.IncorrectSketchSrcFolderNameCase,
},
{
Expand Down
8 changes: 8 additions & 0 deletions check/checkdata/checkdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

// Initialize gathers the check data for the specified project.
func Initialize(project project.Type, schemasPath *paths.Path) {
superprojectType = project.SuperprojectType
projectType = project.ProjectType
projectPath = project.Path
switch project.ProjectType {
Expand All @@ -48,6 +49,13 @@ func Initialize(project project.Type, schemasPath *paths.Path) {
}
}

var superprojectType projecttype.Type

// SuperProjectType returns the type of the project being checked.
func SuperProjectType() projecttype.Type {
return superprojectType
}

var projectType projecttype.Type

// ProjectType returns the type of the project being checked.
Expand Down
6 changes: 5 additions & 1 deletion check/checkfunctions/checkfunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ 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"
}

// https://github.com/github/markup/blob/master/README.md
readmeRegexp := regexp.MustCompile(`(?i)^readme\.(markdown)|(mdown)|(mkdn)|(md)|(textile)|(rdoc)|(org)|(creole)|(mediawiki)|(wiki)|(rst)|(asciidoc)|(adoc)|(asc)|(pod)|(txt)`)
readmeRegexp := regexp.MustCompile(`(?i)^readme\.(markdown)|(mdown)|(mkdn)|(md)|(textile)|(rdoc)|(org)|(creole)|(mediawiki)|(wiki)|(rst)|(asciidoc)|(adoc)|(asc)|(pod)|(txt)$`)

// https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-readmes#about-readmes
if pathContainsReadme(checkdata.ProjectPath(), readmeRegexp) ||
Expand Down
73 changes: 73 additions & 0 deletions check/checkfunctions/checkfunctions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// This file is part of arduino-check.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-check.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package checkfunctions

import (
"os"
"regexp"
"testing"

"github.com/arduino/arduino-check/check/checkdata"
"github.com/arduino/arduino-check/check/checkresult"
"github.com/arduino/arduino-check/project"
"github.com/arduino/arduino-check/project/projecttype"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
)

var testDataPath *paths.Path

func init() {
workingDirectory, _ := os.Getwd()
testDataPath = paths.New(workingDirectory, "testdata", "general")
}

type checkFunctionTestTable struct {
testName string
projectFolderName string
projectType projecttype.Type
superProjectType projecttype.Type
expectedCheckResult checkresult.Type
expectedOutputQuery string
}

func checkCheckFunction(checkFunction Type, testTables []checkFunctionTestTable, t *testing.T) {
for _, testTable := range testTables {
expectedOutputRegexp := regexp.MustCompile(testTable.expectedOutputQuery)

testProject := project.Type{
Path: testDataPath.Join(testTable.projectFolderName),
ProjectType: testTable.projectType,
SuperprojectType: testTable.superProjectType,
}

checkdata.Initialize(testProject, schemasPath)

result, output := checkFunction()
assert.Equal(t, testTable.expectedCheckResult, result, testTable.testName)
assert.True(t, expectedOutputRegexp.MatchString(output), testTable.testName)
}
}

func TestMissingReadme(t *testing.T) {
testTables := []checkFunctionTestTable{
{"Subproject", "readme", projecttype.Sketch, projecttype.Library, checkresult.NotRun, ""},
{"Readme", "readme", projecttype.Sketch, projecttype.Sketch, checkresult.Pass, ""},
{"No readme", "no-readme", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""},
}

checkCheckFunction(MissingReadme, testTables, t)
}
Loading