Skip to content

Commit ba5c3cb

Browse files
committed
Add tests for the project package
1 parent 2cdc0ac commit ba5c3cb

File tree

12 files changed

+298
-0
lines changed

12 files changed

+298
-0
lines changed

project/project_test.go

+298
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
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 license@arduino.cc.
15+
16+
package project
17+
18+
import (
19+
"os"
20+
"reflect"
21+
"testing"
22+
23+
"github.com/arduino/arduino-check/configuration"
24+
"github.com/arduino/arduino-check/project/projecttype"
25+
"github.com/arduino/arduino-check/util/test"
26+
"github.com/arduino/go-paths-helper"
27+
"github.com/stretchr/testify/assert"
28+
)
29+
30+
var testDataPath *paths.Path
31+
32+
func init() {
33+
workingDirectory, err := os.Getwd()
34+
if err != nil {
35+
panic(err)
36+
}
37+
testDataPath = paths.New(workingDirectory, "testdata")
38+
}
39+
40+
func TestFindProjects(t *testing.T) {
41+
sketchPath := testDataPath.Join("Sketch")
42+
libraryPath := testDataPath.Join("Library")
43+
libraryExamplePath := testDataPath.Join("Library", "examples", "Example")
44+
platformPath := testDataPath.Join("Platform")
45+
platformBundledLibraryPath := testDataPath.Join("Platform", "libraries", "Library")
46+
platformBundledLibraryExamplePath := testDataPath.Join("Platform", "libraries", "Library", "examples", "Example")
47+
packageIndexPath := testDataPath.Join("PackageIndex")
48+
projectsPath := testDataPath.Join("Projects")
49+
projectsPathSketch := testDataPath.Join("Projects", "Sketch")
50+
projectsPathLibrary := testDataPath.Join("Projects", "Library")
51+
projectsPathLibraryExample := testDataPath.Join("Projects", "Library", "examples", "Example")
52+
53+
testTables := []struct {
54+
testName string
55+
superprojectTypeFilter string
56+
recursive string
57+
projectPaths []string
58+
errorAssertion assert.ErrorAssertionFunc
59+
expectedProjects []Type
60+
}{
61+
{
62+
"Sketch file",
63+
"all",
64+
"",
65+
[]string{sketchPath.Join("Sketch.ino").String()},
66+
assert.NoError,
67+
[]Type{
68+
{
69+
Path: sketchPath,
70+
ProjectType: projecttype.Sketch,
71+
SuperprojectType: projecttype.Sketch,
72+
},
73+
},
74+
},
75+
{
76+
"Library file",
77+
"all",
78+
"",
79+
[]string{libraryPath.Join("Library.h").String()},
80+
assert.NoError,
81+
[]Type{
82+
{
83+
Path: libraryPath,
84+
ProjectType: projecttype.Library,
85+
SuperprojectType: projecttype.Library,
86+
},
87+
{
88+
Path: libraryExamplePath,
89+
ProjectType: projecttype.Sketch,
90+
SuperprojectType: projecttype.Library,
91+
},
92+
},
93+
},
94+
{
95+
"Platform file",
96+
"all",
97+
"",
98+
[]string{platformPath.Join("boards.txt").String()},
99+
assert.NoError,
100+
[]Type{
101+
{
102+
Path: platformPath,
103+
ProjectType: projecttype.Platform,
104+
SuperprojectType: projecttype.Platform,
105+
},
106+
{
107+
Path: platformBundledLibraryPath,
108+
ProjectType: projecttype.Library,
109+
SuperprojectType: projecttype.Platform,
110+
},
111+
{
112+
Path: platformBundledLibraryExamplePath,
113+
ProjectType: projecttype.Sketch,
114+
SuperprojectType: projecttype.Platform,
115+
},
116+
},
117+
},
118+
{
119+
"Package index file",
120+
"all",
121+
"",
122+
[]string{packageIndexPath.Join("package_foo_index.json").String()},
123+
assert.NoError,
124+
[]Type{
125+
{
126+
Path: packageIndexPath,
127+
ProjectType: projecttype.PackageIndex,
128+
SuperprojectType: projecttype.PackageIndex,
129+
},
130+
},
131+
},
132+
{
133+
"Sketch folder",
134+
"all",
135+
"",
136+
[]string{sketchPath.String()},
137+
assert.NoError,
138+
[]Type{
139+
{
140+
Path: sketchPath,
141+
ProjectType: projecttype.Sketch,
142+
SuperprojectType: projecttype.Sketch,
143+
},
144+
},
145+
},
146+
{
147+
"Library folder",
148+
"all",
149+
"",
150+
[]string{libraryPath.String()},
151+
assert.NoError,
152+
[]Type{
153+
{
154+
Path: libraryPath,
155+
ProjectType: projecttype.Library,
156+
SuperprojectType: projecttype.Library,
157+
},
158+
{
159+
Path: libraryExamplePath,
160+
ProjectType: projecttype.Sketch,
161+
SuperprojectType: projecttype.Library,
162+
},
163+
},
164+
},
165+
{
166+
"Platform folder",
167+
"all",
168+
"",
169+
[]string{platformPath.String()},
170+
assert.NoError,
171+
[]Type{
172+
{
173+
Path: platformPath,
174+
ProjectType: projecttype.Platform,
175+
SuperprojectType: projecttype.Platform,
176+
},
177+
{
178+
Path: platformBundledLibraryPath,
179+
ProjectType: projecttype.Library,
180+
SuperprojectType: projecttype.Platform,
181+
},
182+
{
183+
Path: platformBundledLibraryExamplePath,
184+
ProjectType: projecttype.Sketch,
185+
SuperprojectType: projecttype.Platform,
186+
},
187+
},
188+
},
189+
{
190+
"Package index folder",
191+
"all",
192+
"",
193+
[]string{packageIndexPath.String()},
194+
assert.NoError,
195+
[]Type{
196+
{
197+
Path: packageIndexPath,
198+
ProjectType: projecttype.PackageIndex,
199+
SuperprojectType: projecttype.PackageIndex,
200+
},
201+
},
202+
},
203+
{
204+
"Projects folder, recursive",
205+
"all",
206+
"true",
207+
[]string{projectsPath.String()},
208+
assert.NoError,
209+
[]Type{
210+
{
211+
Path: projectsPathLibrary,
212+
ProjectType: projecttype.Library,
213+
SuperprojectType: projecttype.Library,
214+
},
215+
{
216+
Path: projectsPathLibraryExample,
217+
ProjectType: projecttype.Sketch,
218+
SuperprojectType: projecttype.Library,
219+
},
220+
{
221+
Path: projectsPathSketch,
222+
ProjectType: projecttype.Sketch,
223+
SuperprojectType: projecttype.Sketch,
224+
},
225+
},
226+
},
227+
{
228+
"Projects folder, non-recursive",
229+
"all",
230+
"false",
231+
[]string{projectsPath.String()},
232+
assert.Error,
233+
[]Type{},
234+
},
235+
{
236+
"Multiple target folders",
237+
"all",
238+
"true",
239+
[]string{projectsPath.String(), sketchPath.String()},
240+
assert.NoError,
241+
[]Type{
242+
{
243+
Path: projectsPathLibrary,
244+
ProjectType: projecttype.Library,
245+
SuperprojectType: projecttype.Library,
246+
},
247+
{
248+
Path: projectsPathLibraryExample,
249+
ProjectType: projecttype.Sketch,
250+
SuperprojectType: projecttype.Library,
251+
},
252+
{
253+
Path: projectsPathSketch,
254+
ProjectType: projecttype.Sketch,
255+
SuperprojectType: projecttype.Sketch,
256+
},
257+
{
258+
Path: sketchPath,
259+
ProjectType: projecttype.Sketch,
260+
SuperprojectType: projecttype.Sketch,
261+
},
262+
},
263+
},
264+
{
265+
"superproject type filter",
266+
"sketch",
267+
"true",
268+
[]string{projectsPath.String()},
269+
assert.NoError,
270+
[]Type{
271+
{
272+
Path: projectsPathLibraryExample,
273+
ProjectType: projecttype.Sketch,
274+
SuperprojectType: projecttype.Sketch,
275+
},
276+
{
277+
Path: projectsPathSketch,
278+
ProjectType: projecttype.Sketch,
279+
SuperprojectType: projecttype.Sketch,
280+
},
281+
},
282+
},
283+
}
284+
285+
for _, testTable := range testTables {
286+
flags := test.ConfigurationFlags()
287+
flags.Set("project-type", testTable.superprojectTypeFilter)
288+
if testTable.recursive != "" {
289+
flags.Set("recursive", testTable.recursive)
290+
}
291+
configuration.Initialize(flags, testTable.projectPaths)
292+
foundProjects, err := FindProjects()
293+
testTable.errorAssertion(t, err)
294+
if err == nil {
295+
assert.True(t, reflect.DeepEqual(foundProjects, testTable.expectedProjects), testTable.testName)
296+
}
297+
}
298+
}

project/testdata/Library/Library.h

Whitespace-only changes.

project/testdata/Library/examples/Example/Example.ino

Whitespace-only changes.

project/testdata/PackageIndex/package_foo_index.json

Whitespace-only changes.

project/testdata/Platform/boards.txt

Whitespace-only changes.

project/testdata/Platform/libraries/Library/Library.h

Whitespace-only changes.

project/testdata/Platform/libraries/Library/examples/Example/Example.ino

Whitespace-only changes.

project/testdata/Platform/libraries/Library/library.properties

Whitespace-only changes.

project/testdata/Projects/Library/Library.h

Whitespace-only changes.

project/testdata/Projects/Library/examples/Example/Example.ino

Whitespace-only changes.

project/testdata/Projects/Sketch/Sketch.ino

Whitespace-only changes.

project/testdata/Sketch/Sketch.ino

Whitespace-only changes.

0 commit comments

Comments
 (0)