Skip to content

Commit d5055cc

Browse files
authored
Merge pull request #752 from arduino/example-not-folder
Fix example file causing panic
2 parents 75e13b1 + a4d7dd9 commit d5055cc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: internal/project/project.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
193193
var immediateSubprojects []Type
194194
for _, subprojectsFolderName := range subprojectsFolderNames {
195195
subprojectsPath := superproject.Path.Join(subprojectsFolderName)
196-
if subprojectsPath.Exist() {
196+
if subprojectsPath.IsDir() {
197197
directoryListing, err := subprojectsPath.ReadDir()
198198
if err != nil {
199199
panic(err)

Diff for: internal/project/project_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,19 @@ func TestFindProjects(t *testing.T) {
429429
}
430430
}
431431
}
432+
433+
func TestExamplefile(t *testing.T) {
434+
// Set up directory structure of test library.
435+
libraryPath, err := paths.TempDir().MkTempDir("TestExampleFile")
436+
defer libraryPath.RemoveAll() // Clean up after the test.
437+
require.Nil(t, err)
438+
err = libraryPath.Join("TestExample.h").WriteFile([]byte{})
439+
require.Nil(t, err)
440+
// Create an example file in the library folder. This should not cause a panic and should be ignored since it's not a folder containing the examples
441+
err = libraryPath.Join("example").WriteFile([]byte{})
442+
require.Nil(t, err)
443+
444+
configuration.Initialize(test.ConfigurationFlags(), []string{libraryPath.String()})
445+
446+
assert.NotPanics(t, func() { FindProjects() }, "Example file should not cause panic")
447+
}

0 commit comments

Comments
 (0)