Skip to content

Commit 5dc08e0

Browse files
committed
Add check for missing boards.txt
1 parent f27a8cc commit 5dc08e0

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,21 @@ var configurations = []Type{
11511151
ErrorModes: []checkmode.Type{checkmode.Strict},
11521152
CheckFunction: checkfunctions.MissingReadme,
11531153
},
1154+
{
1155+
ProjectType: projecttype.Platform,
1156+
Category: "configuration files",
1157+
Subcategory: "boards.txt",
1158+
ID: "",
1159+
Brief: "missing",
1160+
Description: "",
1161+
MessageTemplate: "Required boards.txt is missing. Expected at: {{.}}",
1162+
DisableModes: nil,
1163+
EnableModes: []checkmode.Type{checkmode.Default},
1164+
InfoModes: nil,
1165+
WarningModes: nil,
1166+
ErrorModes: []checkmode.Type{checkmode.Default},
1167+
CheckFunction: checkfunctions.BoardsTxtMissing,
1168+
},
11541169
{
11551170
ProjectType: projecttype.PackageIndex,
11561171
Category: "data",

Diff for: check/checkfunctions/platform.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
"github.com/arduino/arduino-check/check/checkdata"
20+
"github.com/arduino/arduino-check/check/checkresult"
21+
)
22+
23+
// The check functions for platforms.
24+
25+
// BoardsTxtMissing checks whether the platform contains a boards.txt
26+
func BoardsTxtMissing() (result checkresult.Type, output string) {
27+
boardsTxtPath := checkdata.ProjectPath().Join("boards.txt")
28+
exist, err := boardsTxtPath.ExistCheck()
29+
if err != nil {
30+
panic(err)
31+
}
32+
33+
if exist {
34+
return checkresult.Pass, ""
35+
}
36+
37+
return checkresult.Fail, boardsTxtPath.String()
38+
}
39+

Diff for: check/checkfunctions/platform_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+
"regexp"
20+
"testing"
21+
22+
"github.com/arduino/arduino-check/check/checkdata"
23+
"github.com/arduino/arduino-check/check/checkresult"
24+
"github.com/arduino/arduino-check/project"
25+
"github.com/arduino/arduino-check/project/projecttype"
26+
"github.com/arduino/go-paths-helper"
27+
"github.com/stretchr/testify/assert"
28+
)
29+
30+
var platformTestDataPath *paths.Path
31+
32+
func init() {
33+
workingDirectory, err := paths.Getwd()
34+
if err != nil {
35+
panic(err)
36+
}
37+
platformTestDataPath = workingDirectory.Join("testdata", "platforms")
38+
}
39+
40+
type platformCheckFunctionTestTable struct {
41+
testName string
42+
platformFolderName string
43+
expectedCheckResult checkresult.Type
44+
expectedOutputQuery string
45+
}
46+
47+
func checkPlatformCheckFunction(checkFunction Type, testTables []platformCheckFunctionTestTable, t *testing.T) {
48+
for _, testTable := range testTables {
49+
expectedOutputRegexp := regexp.MustCompile(testTable.expectedOutputQuery)
50+
51+
testProject := project.Type{
52+
Path: platformTestDataPath.Join(testTable.platformFolderName),
53+
ProjectType: projecttype.Platform,
54+
SuperprojectType: projecttype.Platform,
55+
}
56+
57+
checkdata.Initialize(testProject, nil)
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 TestBoardsTxtMissing(t *testing.T) {
66+
testTables := []platformCheckFunctionTestTable{
67+
{"Present", "valid-boards.txt", checkresult.Pass, ""},
68+
{"Missing", "missing-boards.txt", checkresult.Fail, ""},
69+
}
70+
71+
checkPlatformCheckFunction(BoardsTxtMissing, testTables, t)
72+
}
73+

Diff for: check/checkfunctions/testdata/platforms/missing-boards.txt/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
uno.name=Arduino Uno
2+
3+
uno.build.core=arduino
4+
uno.build.variant=standard
5+
6+
uno.upload.tool=avrdude
7+
uno.upload.maximum_size=32256
8+
uno.upload.maximum_data_size=2048

0 commit comments

Comments
 (0)