Skip to content

Commit 259ae3f

Browse files
committed
Add dedicated file for tests of the functions in check/checkfunctions/checkfunctions.go
check/checkfunctions/checkfunctions.go will contain check functions that aren't specific to a single project type. There are a large, ever increasing, number of tests for check functions, and each group of check function types may have different testing requirements, so it's helpful to split them up a bit.
1 parent c042ba4 commit 259ae3f

File tree

7 files changed

+77
-32
lines changed

7 files changed

+77
-32
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
{"Readme", "readme", projecttype.Sketch, projecttype.Sketch, checkresult.Pass, ""},
68+
{"No readme", "no-readme", projecttype.Sketch, projecttype.Sketch, checkresult.Fail, ""},
69+
}
70+
71+
checkCheckFunction(MissingReadme, testTables, t)
72+
}

check/checkfunctions/library_test.go

+5-14
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import (
2929
"github.com/stretchr/testify/require"
3030
)
3131

32-
var testDataPath *paths.Path
32+
var librariesTestDataPath *paths.Path
3333
var schemasPath *paths.Path
3434

3535
func init() {
3636
workingDirectory, _ := os.Getwd()
37-
testDataPath = paths.New(workingDirectory, "testdata", "libraries")
37+
librariesTestDataPath = paths.New(workingDirectory, "testdata", "libraries")
3838
schemasPath = paths.New(workingDirectory, "..", "..", "etc", "schemas")
3939
}
4040

@@ -50,7 +50,7 @@ func checkLibraryCheckFunction(checkFunction Type, testTables []libraryCheckFunc
5050
expectedOutputRegexp := regexp.MustCompile(testTable.expectedOutputQuery)
5151

5252
testProject := project.Type{
53-
Path: testDataPath.Join(testTable.libraryFolderName),
53+
Path: librariesTestDataPath.Join(testTable.libraryFolderName),
5454
ProjectType: projecttype.Library,
5555
SuperprojectType: projecttype.Library,
5656
}
@@ -263,9 +263,9 @@ func TestLibraryHasSubmodule(t *testing.T) {
263263

264264
func TestLibraryContainsSymlinks(t *testing.T) {
265265
testLibrary := "Recursive"
266-
symlinkPath := testDataPath.Join(testLibrary, "test-symlink")
266+
symlinkPath := librariesTestDataPath.Join(testLibrary, "test-symlink")
267267
// It's probably most friendly to developers using Windows to create the symlink needed for the test on demand.
268-
err := os.Symlink(testDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
268+
err := os.Symlink(librariesTestDataPath.Join(testLibrary, "library.properties").String(), symlinkPath.String())
269269
require.Nil(t, err, "This test must be run as administrator on Windows to have symlink creation privilege.")
270270
defer symlinkPath.RemoveAll() // clean up
271271

@@ -392,12 +392,3 @@ func TestRecursiveLibraryWithUtilityFolder(t *testing.T) {
392392

393393
checkLibraryCheckFunction(RecursiveLibraryWithUtilityFolder, testTables, t)
394394
}
395-
396-
func TestMissingReadme(t *testing.T) {
397-
testTables := []libraryCheckFunctionTestTable{
398-
{"Readme", "Readme", checkresult.Pass, ""},
399-
{"No readme", "NoReadme", checkresult.Fail, ""},
400-
}
401-
402-
checkLibraryCheckFunction(MissingReadme, testTables, t)
403-
}

check/checkfunctions/testdata/libraries/NoReadme/library.properties

-9
This file was deleted.

check/checkfunctions/testdata/libraries/Readme/library.properties

-9
This file was deleted.

check/checkfunctions/testdata/libraries/Readme/src/Readme.h

Whitespace-only changes.

0 commit comments

Comments
 (0)