Skip to content

Commit f22ed88

Browse files
authored
Merge pull request #90 from arduino/per1234/fix-check-configurations
Correct and improve checks
2 parents 64db290 + 12170ff commit f22ed88

File tree

11 files changed

+204
-133
lines changed

11 files changed

+204
-133
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ var configurations = []Type{
9797
DisableModes: nil,
9898
EnableModes: []checkmode.Type{checkmode.Default},
9999
InfoModes: nil,
100-
WarningModes: []checkmode.Type{checkmode.Permissive},
101-
ErrorModes: []checkmode.Type{checkmode.Default},
100+
WarningModes: []checkmode.Type{checkmode.Default},
101+
ErrorModes: []checkmode.Type{checkmode.Strict},
102102
CheckFunction: checkfunctions.MisspelledLibraryPropertiesFileName,
103103
},
104104
{
@@ -198,7 +198,7 @@ var configurations = []Type{
198198
ID: "LP003",
199199
Brief: "disallowed characters",
200200
Description: "",
201-
MessageTemplate: "disallowed characters in library.properties name field. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
201+
MessageTemplate: "disallowed characters in library.properties name value: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
202202
DisableModes: nil,
203203
EnableModes: []checkmode.Type{checkmode.Default},
204204
InfoModes: nil,
@@ -232,8 +232,8 @@ var configurations = []Type{
232232
DisableModes: []checkmode.Type{checkmode.Official},
233233
EnableModes: []checkmode.Type{checkmode.Default},
234234
InfoModes: nil,
235-
WarningModes: []checkmode.Type{checkmode.Permissive},
236-
ErrorModes: []checkmode.Type{checkmode.Default},
235+
WarningModes: []checkmode.Type{checkmode.Default},
236+
ErrorModes: []checkmode.Type{checkmode.LibraryManagerSubmission, checkmode.Strict},
237237
CheckFunction: checkfunctions.LibraryPropertiesNameFieldStartsWithArduino,
238238
},
239239
{
@@ -247,8 +247,8 @@ var configurations = []Type{
247247
DisableModes: []checkmode.Type{checkmode.Default},
248248
EnableModes: []checkmode.Type{checkmode.Official},
249249
InfoModes: nil,
250-
WarningModes: nil,
251-
ErrorModes: []checkmode.Type{checkmode.Official},
250+
WarningModes: []checkmode.Type{checkmode.Default},
251+
ErrorModes: []checkmode.Type{checkmode.Strict},
252252
CheckFunction: checkfunctions.LibraryPropertiesNameFieldMissingOfficialPrefix,
253253
},
254254
{
@@ -1008,7 +1008,7 @@ var configurations = []Type{
10081008
ID: "",
10091009
Brief: "incorrect src folder case",
10101010
Description: "",
1011-
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",
1011+
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",
10121012
DisableModes: nil,
10131013
EnableModes: []checkmode.Type{checkmode.Default},
10141014
InfoModes: nil,
@@ -1098,12 +1098,12 @@ var configurations = []Type{
10981098
ID: "",
10991099
Brief: "incorrect src folder case",
11001100
Description: "",
1101-
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",
1101+
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",
11021102
DisableModes: nil,
11031103
EnableModes: []checkmode.Type{checkmode.Default},
11041104
InfoModes: nil,
1105-
WarningModes: []checkmode.Type{checkmode.Default},
1106-
ErrorModes: []checkmode.Type{checkmode.Strict},
1105+
WarningModes: []checkmode.Type{checkmode.Permissive},
1106+
ErrorModes: []checkmode.Type{checkmode.Default},
11071107
CheckFunction: checkfunctions.IncorrectSketchSrcFolderNameCase,
11081108
},
11091109
{

Diff for: check/checkdata/checkdata.go

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
// Initialize gathers the check data for the specified project.
3030
func Initialize(project project.Type, schemasPath *paths.Path) {
31+
superprojectType = project.SuperprojectType
3132
projectType = project.ProjectType
3233
projectPath = project.Path
3334
switch project.ProjectType {
@@ -48,6 +49,13 @@ func Initialize(project project.Type, schemasPath *paths.Path) {
4849
}
4950
}
5051

52+
var superprojectType projecttype.Type
53+
54+
// SuperProjectType returns the type of the project being checked.
55+
func SuperProjectType() projecttype.Type {
56+
return superprojectType
57+
}
58+
5159
var projectType projecttype.Type
5260

5361
// ProjectType returns the type of the project being checked.

Diff for: check/checkfunctions/checkfunctions.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName stri
6969

7070
// MissingReadme checks if the project has a readme that will be recognized by GitHub.
7171
func MissingReadme() (result checkresult.Type, output string) {
72+
if checkdata.ProjectType() != checkdata.SuperProjectType() {
73+
return checkresult.NotRun, "Readme not required for subprojects"
74+
}
75+
7276
// https://github.com/github/markup/blob/master/README.md
73-
readmeRegexp := regexp.MustCompile(`(?i)^readme\.(markdown)|(mdown)|(mkdn)|(md)|(textile)|(rdoc)|(org)|(creole)|(mediawiki)|(wiki)|(rst)|(asciidoc)|(adoc)|(asc)|(pod)|(txt)`)
77+
readmeRegexp := regexp.MustCompile(`(?i)^readme\.(markdown)|(mdown)|(mkdn)|(md)|(textile)|(rdoc)|(org)|(creole)|(mediawiki)|(wiki)|(rst)|(asciidoc)|(adoc)|(asc)|(pod)|(txt)$`)
7478

7579
// https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-readmes#about-readmes
7680
if pathContainsReadme(checkdata.ProjectPath(), readmeRegexp) ||

Diff for: check/checkfunctions/checkfunctions_test.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package checkfunctions
17+
18+
import (
19+
"os"
20+
"regexp"
21+
"testing"
22+
23+
"github.com/arduino/arduino-check/check/checkdata"
24+
"github.com/arduino/arduino-check/check/checkresult"
25+
"github.com/arduino/arduino-check/project"
26+
"github.com/arduino/arduino-check/project/projecttype"
27+
"github.com/arduino/go-paths-helper"
28+
"github.com/stretchr/testify/assert"
29+
)
30+
31+
var testDataPath *paths.Path
32+
33+
func init() {
34+
workingDirectory, _ := os.Getwd()
35+
testDataPath = paths.New(workingDirectory, "testdata", "general")
36+
}
37+
38+
type checkFunctionTestTable struct {
39+
testName string
40+
projectFolderName string
41+
projectType projecttype.Type
42+
superProjectType projecttype.Type
43+
expectedCheckResult checkresult.Type
44+
expectedOutputQuery string
45+
}
46+
47+
func checkCheckFunction(checkFunction Type, testTables []checkFunctionTestTable, t *testing.T) {
48+
for _, testTable := range testTables {
49+
expectedOutputRegexp := regexp.MustCompile(testTable.expectedOutputQuery)
50+
51+
testProject := project.Type{
52+
Path: testDataPath.Join(testTable.projectFolderName),
53+
ProjectType: testTable.projectType,
54+
SuperprojectType: testTable.superProjectType,
55+
}
56+
57+
checkdata.Initialize(testProject, schemasPath)
58+
59+
result, output := checkFunction()
60+
assert.Equal(t, testTable.expectedCheckResult, result, testTable.testName)
61+
assert.True(t, expectedOutputRegexp.MatchString(output), testTable.testName)
62+
}
63+
}
64+
65+
func TestMissingReadme(t *testing.T) {
66+
testTables := []checkFunctionTestTable{
67+
{"Subproject", "readme", projecttype.Sketch, projecttype.Library, checkresult.NotRun, ""},
68+
{"Readme", "readme", projecttype.Sketch, projecttype.Sketch, checkresult.Pass, ""},
69+
{"No readme", "no-readme", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""},
70+
}
71+
72+
checkCheckFunction(MissingReadme, testTables, t)
73+
}

0 commit comments

Comments
 (0)