Skip to content

Commit

Permalink
Merge pull request #752 from arduino/example-not-folder
Browse files Browse the repository at this point in the history
Fix example file causing panic
  • Loading branch information
per1234 authored Jul 28, 2024
2 parents 75e13b1 + a4d7dd9 commit d5055cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
var immediateSubprojects []Type
for _, subprojectsFolderName := range subprojectsFolderNames {
subprojectsPath := superproject.Path.Join(subprojectsFolderName)
if subprojectsPath.Exist() {
if subprojectsPath.IsDir() {
directoryListing, err := subprojectsPath.ReadDir()
if err != nil {
panic(err)
Expand Down
16 changes: 16 additions & 0 deletions internal/project/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,19 @@ func TestFindProjects(t *testing.T) {
}
}
}

func TestExamplefile(t *testing.T) {
// Set up directory structure of test library.
libraryPath, err := paths.TempDir().MkTempDir("TestExampleFile")
defer libraryPath.RemoveAll() // Clean up after the test.
require.Nil(t, err)
err = libraryPath.Join("TestExample.h").WriteFile([]byte{})
require.Nil(t, err)
// 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
err = libraryPath.Join("example").WriteFile([]byte{})
require.Nil(t, err)

configuration.Initialize(test.ConfigurationFlags(), []string{libraryPath.String()})

assert.NotPanics(t, func() { FindProjects() }, "Example file should not cause panic")
}

0 comments on commit d5055cc

Please sign in to comment.