Skip to content

Commit 9d80c17

Browse files
authored
Merge pull request #84 from arduino/per1234/increase-test-coverage
Increase test coverage
2 parents 5eacd49 + a3324e5 commit 9d80c17

File tree

14 files changed

+283
-10
lines changed

14 files changed

+283
-10
lines changed

check/check_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func Test_shouldRun(t *testing.T) {
6767
ProjectType: testTable.projectType,
6868
}
6969
run, err := shouldRun(checkConfiguration, project)
70-
testTable.errorAssertion(t, err)
70+
testTable.errorAssertion(t, err, testTable.testName)
7171
if err == nil {
72-
testTable.shouldRunAssertion(t, run)
72+
testTable.shouldRunAssertion(t, run, testTable.testName)
7373
}
7474
}
7575
}

check/checkdata/schema/schema.go

-7
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@ func unmarshalJSONFile(filePath *paths.Path) interface{} {
122122
return dataInterface
123123
}
124124

125-
// compile compiles the parent schema and returns the resulting jsonschema.Schema object.
126-
func compile(compiler *jsonschema.Compiler, schemaFilename string, schemasPath *paths.Path) (*jsonschema.Schema, error) {
127-
schemaPath := schemasPath.Join(schemaFilename)
128-
schemaURI := pathURI(schemaPath)
129-
return compiler.Compile(schemaURI)
130-
}
131-
132125
// pathURI returns the URI representation of the path argument.
133126
func pathURI(path *paths.Path) string {
134127
absolutePath, err := path.Abs()

check/checkdata/schema/schema_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func TestValidationErrorMatch(t *testing.T) {
177177
require.True(t, ValidationErrorMatch("^#/property2$", "/pattern$", `^"\^\[a-z\]\+\$"$`, "", validationResult, schemasPath))
178178
require.True(t, ValidationErrorMatch("", "", "", "", validationResult, schemasPath))
179179

180+
propertiesMap.Set("property3", "bAz")
181+
validationResult = Validate(propertiesMap, validSchemaWithReferences, schemasPath)
182+
require.True(t, ValidationErrorMatch("^#/property3$", "/pattern$", "", "", validationResult, schemasPath), "Match pointer below logic inversion keyword")
183+
180184
propertiesMap = properties.NewFromHashmap(validMap)
181185
propertiesMap.Remove("property1")
182186
validationResult = Validate(propertiesMap, validSchemaWithReferences, schemasPath)

check/checkdata/schema/testdata/referenced-schema-2.json

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
"enumObject": {
1313
"enum": ["baz"]
1414
},
15+
"notPatternObject": {
16+
"not": {
17+
"allOf": [
18+
{
19+
"pattern": "[A-Z]"
20+
}
21+
]
22+
}
23+
},
1524
"misspelledOptionalProperties": {
1625
"propertyNames": {
1726
"not": {

check/checkdata/schema/testdata/valid-schema-with-references.json

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
"allOf": [
2626
{
2727
"$ref": "referenced-schema-2.json#/definitions/enumObject"
28+
},
29+
{
30+
"$ref": "referenced-schema-2.json#/definitions/notPatternObject"
2831
}
2932
]
3033
}

check/checkfunctions/library_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ func TestRedundantLibraryProperties(t *testing.T) {
101101
checkLibraryCheckFunction(RedundantLibraryProperties, testTables, t)
102102
}
103103

104+
func TestLibraryPropertiesFormat(t *testing.T) {
105+
testTables := []libraryCheckFunctionTestTable{
106+
{"Invalid", "InvalidLibraryProperties", checkresult.Fail, ""},
107+
{"Valid", "Recursive", checkresult.Pass, ""},
108+
}
109+
110+
checkLibraryCheckFunction(LibraryPropertiesFormat, testTables, t)
111+
}
112+
104113
func TestLibraryPropertiesNameFieldMissingOfficialPrefix(t *testing.T) {
105114
testTables := []libraryCheckFunctionTestTable{
106115
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},

check/checkfunctions/sketch_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ func TestSketchFileNameGTMaxLength(t *testing.T) {
8686

8787
checkSketchCheckFunction(SketchFileNameGTMaxLength, testTables, t)
8888
}
89+
90+
func TestPdeSketchExtension(t *testing.T) {
91+
testTables := []sketchCheckFunctionTestTable{
92+
{"Has .pde", "Pde", checkresult.Fail, ""},
93+
{"No .pde", "Valid", checkresult.Pass, ""},
94+
}
95+
96+
checkSketchCheckFunction(PdeSketchExtension, testTables, t)
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 checkmode
17+
18+
import (
19+
"reflect"
20+
"testing"
21+
22+
"github.com/arduino/arduino-check/project/projecttype"
23+
"github.com/stretchr/testify/assert"
24+
)
25+
26+
func TestMode(t *testing.T) {
27+
defaultCheckModes := map[projecttype.Type]map[Type]bool{
28+
projecttype.Sketch: {
29+
LibraryManagerSubmission: false,
30+
LibraryManagerIndexed: false,
31+
Official: false,
32+
All: true,
33+
},
34+
projecttype.Library: {
35+
LibraryManagerSubmission: true,
36+
LibraryManagerIndexed: false,
37+
Official: false,
38+
All: true,
39+
},
40+
}
41+
42+
customCheckModes := make(map[Type]bool)
43+
44+
testProjectType := projecttype.Library
45+
46+
mergedCheckModes := Modes(defaultCheckModes, customCheckModes, testProjectType)
47+
48+
assert.True(t, reflect.DeepEqual(defaultCheckModes[testProjectType], mergedCheckModes), "Default configuration should be used when no custom configuration was set.")
49+
50+
testCheckMode := Official
51+
customCheckModes[testCheckMode] = !defaultCheckModes[testProjectType][testCheckMode]
52+
mergedCheckModes = Modes(defaultCheckModes, customCheckModes, testProjectType)
53+
assert.Equal(t, customCheckModes[testCheckMode], mergedCheckModes[testCheckMode], "Should be set to custom value")
54+
}

project/library/library_test.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ import (
2626
var testDataPath *paths.Path
2727

2828
func init() {
29-
workingDirectory, _ := os.Getwd()
29+
workingDirectory, err := os.Getwd()
30+
if err != nil {
31+
panic(err)
32+
}
3033
testDataPath = paths.New(workingDirectory, "testdata")
3134
}
3235

@@ -39,3 +42,13 @@ func TestContainsMetadataFile(t *testing.T) {
3942
assert.True(t, ContainsMetadataFile(testDataPath.Join("ContainsMetadataFile")))
4043
assert.False(t, ContainsMetadataFile(testDataPath.Join("ContainsNoMetadataFile")))
4144
}
45+
46+
func TestHasHeaderFileValidExtension(t *testing.T) {
47+
assert.True(t, HasHeaderFileValidExtension(testDataPath.Join("ContainsHeaderFile", "foo.h")))
48+
assert.False(t, HasHeaderFileValidExtension(testDataPath.Join("ContainsNoHeaderFile", "foo.bar")))
49+
}
50+
51+
func TestIsMetadataFile(t *testing.T) {
52+
assert.True(t, IsMetadataFile(testDataPath.Join("ContainsMetadataFile", "library.properties")))
53+
assert.False(t, IsMetadataFile(testDataPath.Join("ContainsNoMetadataFile", "foo.bar")))
54+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 packageindex
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/go-paths-helper"
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestHasValidExtension(t *testing.T) {
26+
assert.True(t, HasValidExtension(paths.New("/foo", "bar.json")))
27+
assert.False(t, HasValidExtension(paths.New("/foo", "bar.baz")))
28+
}
29+
30+
func TestHasValidFilename(t *testing.T) {
31+
testTables := []struct {
32+
testName string
33+
filename string
34+
officialCheckMode bool
35+
assertion assert.BoolAssertionFunc
36+
}{
37+
{"Official, primary", "package_index.json", true, assert.True},
38+
{"Official, secondary", "package_foo_index.json", true, assert.True},
39+
{"Official, invalid", "packageindex.json", true, assert.False},
40+
{"Unofficial, valid", "package_foo_index.json", false, assert.True},
41+
{"Unofficial, official", "package_index.json", false, assert.False},
42+
{"Unofficial, invalid", "packageindex.json", false, assert.False},
43+
}
44+
45+
for _, testTable := range testTables {
46+
testTable.assertion(t, HasValidFilename(paths.New("/foo", testTable.filename), testTable.officialCheckMode), testTable.testName)
47+
}
48+
}

project/platform/platform_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 platform
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/go-paths-helper"
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestIsConfigurationFile(t *testing.T) {
26+
testTables := []struct {
27+
filename string
28+
assertion assert.BoolAssertionFunc
29+
}{
30+
{"boards.txt", assert.True},
31+
{"boards.local.txt", assert.True},
32+
{"platform.txt", assert.True},
33+
{"platform.local.txt", assert.True},
34+
{"programmers.txt", assert.True},
35+
{"foo.txt", assert.False},
36+
}
37+
38+
for _, testTable := range testTables {
39+
testTable.assertion(t, IsConfigurationFile(paths.New("/foo", testTable.filename)), testTable.filename)
40+
}
41+
}
42+
43+
func TestIsRequiredConfigurationFile(t *testing.T) {
44+
assert.True(t, IsRequiredConfigurationFile(paths.New("/foo", "boards.txt")))
45+
assert.False(t, IsRequiredConfigurationFile(paths.New("/foo", "platform.txt")))
46+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 projecttype
17+
18+
import (
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
)
23+
24+
func TestMatches(t *testing.T) {
25+
testTables := []struct {
26+
typeA Type
27+
typeB Type
28+
assertion assert.BoolAssertionFunc
29+
}{
30+
{Not, Not, assert.True},
31+
{Not, Sketch, assert.False},
32+
{Not, All, assert.False},
33+
{Sketch, All, assert.True},
34+
{Sketch, Sketch, assert.True},
35+
}
36+
37+
for _, testTable := range testTables {
38+
testTable.assertion(t, testTable.typeA.Matches(testTable.typeB), testTable.typeA.String()+", "+testTable.typeB.String())
39+
}
40+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 outputformat
17+
18+
import (
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
)
23+
24+
func TestFromString(t *testing.T) {
25+
testTables := []struct {
26+
formatString string
27+
expectedFormat Type
28+
errorAssertion assert.ErrorAssertionFunc
29+
}{
30+
{"text", Text, assert.NoError},
31+
{"json", JSON, assert.NoError},
32+
{"TEXT", Text, assert.NoError},
33+
{"foo", 0, assert.Error},
34+
}
35+
36+
for _, testTable := range testTables {
37+
outputFormat, err := FromString(testTable.formatString)
38+
testTable.errorAssertion(t, err, testTable.formatString)
39+
if err == nil {
40+
assert.Equal(t, testTable.expectedFormat, outputFormat, testTable.formatString)
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)