1616package project
1717
1818import (
19+ "fmt"
1920 "os"
2021 "reflect"
2122 "testing"
@@ -53,16 +54,16 @@ func TestFindProjects(t *testing.T) {
5354
5455 testTables := []struct {
5556 testName string
56- superprojectTypeFilter string
57- recursive string
57+ superprojectTypeFilter [] string
58+ recursive [] string
5859 projectPaths []string
5960 errorAssertion assert.ErrorAssertionFunc
6061 expectedProjects []Type
6162 }{
6263 {
6364 "Sketch file" ,
64- "all" ,
65- "" ,
65+ [] string { "all" , "sketch" } ,
66+ [] string { "true" , "false" } ,
6667 []string {sketchPath .Join ("Sketch.ino" ).String ()},
6768 assert .NoError ,
6869 []Type {
@@ -75,8 +76,8 @@ func TestFindProjects(t *testing.T) {
7576 },
7677 {
7778 "Library file" ,
78- "all" ,
79- "" ,
79+ [] string { "all" , "library" } ,
80+ [] string { "true" , "false" } ,
8081 []string {libraryPath .Join ("Library.h" ).String ()},
8182 assert .NoError ,
8283 []Type {
@@ -94,8 +95,8 @@ func TestFindProjects(t *testing.T) {
9495 },
9596 {
9697 "Platform file" ,
97- "all" ,
98- "" ,
98+ [] string { "all" , "platform" } ,
99+ [] string { "true" , "false" } ,
99100 []string {platformPath .Join ("boards.txt" ).String ()},
100101 assert .NoError ,
101102 []Type {
@@ -118,8 +119,8 @@ func TestFindProjects(t *testing.T) {
118119 },
119120 {
120121 "Package index file" ,
121- "all" ,
122- "" ,
122+ [] string { "all" , "package-index" } ,
123+ [] string { "true" , "false" } ,
123124 []string {packageIndexFilePath .String ()},
124125 assert .NoError ,
125126 []Type {
@@ -132,8 +133,8 @@ func TestFindProjects(t *testing.T) {
132133 },
133134 {
134135 "Explicit file" ,
135- "sketch" ,
136- "" ,
136+ [] string { "sketch" } ,
137+ [] string { "true" , "false" } ,
137138 []string {libraryPath .Join ("Library.h" ).String ()},
138139 assert .NoError ,
139140 []Type {
@@ -146,8 +147,8 @@ func TestFindProjects(t *testing.T) {
146147 },
147148 {
148149 "Sketch folder" ,
149- "all" ,
150- "" ,
150+ [] string { "all" , "sketch" } ,
151+ [] string { "true" , "false" } ,
151152 []string {sketchPath .String ()},
152153 assert .NoError ,
153154 []Type {
@@ -160,8 +161,8 @@ func TestFindProjects(t *testing.T) {
160161 },
161162 {
162163 "Library folder" ,
163- "all" ,
164- "" ,
164+ [] string { "all" , "library" } ,
165+ [] string { "true" , "false" } ,
165166 []string {libraryPath .String ()},
166167 assert .NoError ,
167168 []Type {
@@ -179,8 +180,8 @@ func TestFindProjects(t *testing.T) {
179180 },
180181 {
181182 "Platform folder" ,
182- "all" ,
183- "" ,
183+ [] string { "all" , "platform" } ,
184+ [] string { "true" , "false" } ,
184185 []string {platformPath .String ()},
185186 assert .NoError ,
186187 []Type {
@@ -203,8 +204,8 @@ func TestFindProjects(t *testing.T) {
203204 },
204205 {
205206 "Package index folder" ,
206- "all" ,
207- "" ,
207+ [] string { "all" , "package-index" } ,
208+ [] string { "true" , "false" } ,
208209 []string {packageIndexFolderPath .String ()},
209210 assert .NoError ,
210211 []Type {
@@ -217,8 +218,8 @@ func TestFindProjects(t *testing.T) {
217218 },
218219 {
219220 "Explicit folder" ,
220- "sketch" ,
221- "false" ,
221+ [] string { "sketch" } ,
222+ [] string { "false" } ,
222223 []string {libraryPath .String ()},
223224 assert .NoError ,
224225 []Type {
@@ -230,9 +231,23 @@ func TestFindProjects(t *testing.T) {
230231 },
231232 },
232233 {
233- "Projects folder, recursive" ,
234- "all" ,
235- "true" ,
234+ "Explicit folder" ,
235+ []string {"sketch" },
236+ []string {"true" },
237+ []string {libraryPath .String ()},
238+ assert .NoError ,
239+ []Type {
240+ {
241+ Path : libraryExamplePath ,
242+ ProjectType : projecttype .Sketch ,
243+ SuperprojectType : projecttype .Sketch ,
244+ },
245+ },
246+ },
247+ {
248+ "Projects folder" ,
249+ []string {"all" },
250+ []string {"true" },
236251 []string {projectsPath .String ()},
237252 assert .NoError ,
238253 []Type {
@@ -253,18 +268,37 @@ func TestFindProjects(t *testing.T) {
253268 },
254269 },
255270 },
271+ {
272+ "Projects folder" ,
273+ []string {"sketch" },
274+ []string {"true" },
275+ []string {projectsPath .String ()},
276+ assert .NoError ,
277+ []Type {
278+ {
279+ Path : projectsPathLibraryExample ,
280+ ProjectType : projecttype .Sketch ,
281+ SuperprojectType : projecttype .Sketch ,
282+ },
283+ {
284+ Path : projectsPathSketch ,
285+ ProjectType : projecttype .Sketch ,
286+ SuperprojectType : projecttype .Sketch ,
287+ },
288+ },
289+ },
256290 {
257291 "Projects folder, non-recursive" ,
258- "all" ,
259- "false" ,
292+ [] string { "all" } ,
293+ [] string { "false" } ,
260294 []string {projectsPath .String ()},
261295 assert .Error ,
262296 []Type {},
263297 },
264298 {
265299 "Multiple target folders" ,
266- "all" ,
267- "true" ,
300+ [] string { "all" } ,
301+ [] string { "true" } ,
268302 []string {projectsPath .String (), sketchPath .String ()},
269303 assert .NoError ,
270304 []Type {
@@ -290,38 +324,32 @@ func TestFindProjects(t *testing.T) {
290324 },
291325 },
292326 },
293- {
294- "superproject type filter" ,
295- "sketch" ,
296- "true" ,
297- []string {projectsPath .String ()},
298- assert .NoError ,
299- []Type {
300- {
301- Path : projectsPathLibraryExample ,
302- ProjectType : projecttype .Sketch ,
303- SuperprojectType : projecttype .Sketch ,
304- },
305- {
306- Path : projectsPathSketch ,
307- ProjectType : projecttype .Sketch ,
308- SuperprojectType : projecttype .Sketch ,
309- },
310- },
311- },
312327 }
313328
314329 for _ , testTable := range testTables {
315- flags := test .ConfigurationFlags ()
316- flags .Set ("project-type" , testTable .superprojectTypeFilter )
317- if testTable .recursive != "" {
318- flags .Set ("recursive" , testTable .recursive )
319- }
320- configuration .Initialize (flags , testTable .projectPaths )
321- foundProjects , err := FindProjects ()
322- testTable .errorAssertion (t , err )
323- if err == nil {
324- assert .True (t , reflect .DeepEqual (foundProjects , testTable .expectedProjects ), testTable .testName )
330+ for _ , superprojectTypeFilter := range testTable .superprojectTypeFilter {
331+ for _ , recursive := range testTable .recursive {
332+ flags := test .ConfigurationFlags ()
333+ flags .Set ("project-type" , superprojectTypeFilter )
334+ if recursive != "" {
335+ flags .Set ("recursive" , recursive )
336+ }
337+ configuration .Initialize (flags , testTable .projectPaths )
338+ foundProjects , err := FindProjects ()
339+ testTable .errorAssertion (t , err )
340+ if err == nil {
341+ assert .True (
342+ t ,
343+ reflect .DeepEqual (foundProjects , testTable .expectedProjects ),
344+ fmt .Sprintf (
345+ "%s (%s project-type=%s recursive=%s)" ,
346+ testTable .testName ,
347+ testTable .projectPaths ,
348+ superprojectTypeFilter , recursive ,
349+ ),
350+ )
351+ }
352+ }
325353 }
326354 }
327355}
0 commit comments