Skip to content

Commit e82f252

Browse files
committed
Fix lib examples not showing sketches with .pde files
1 parent 5175343 commit e82f252

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

arduino/libraries/loader.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"strings"
2121

22+
"github.com/arduino/arduino-cli/arduino/sketches"
2223
"github.com/arduino/go-paths-helper"
2324
properties "github.com/arduino/go-properties-orderedmap"
2425
"github.com/pkg/errors"
@@ -172,7 +173,8 @@ func addExamplesToPathList(examplesPath *paths.Path, list *paths.PathList) error
172173
return err
173174
}
174175
for _, file := range files {
175-
if isExample(file) {
176+
_, err := sketches.NewSketchFromPath(file)
177+
if err == nil {
176178
list.Add(file)
177179
} else if file.IsDir() {
178180
if err := addExamplesToPathList(file, list); err != nil {
@@ -182,9 +184,3 @@ func addExamplesToPathList(examplesPath *paths.Path, list *paths.PathList) error
182184
}
183185
return nil
184186
}
185-
186-
// isExample returns true if examplePath contains an example
187-
func isExample(examplePath *paths.Path) bool {
188-
mainIno := examplePath.Join(examplePath.Base() + ".ino")
189-
return mainIno.Exist() && mainIno.IsNotDir()
190-
}

test/test_lib.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,3 +621,36 @@ def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, da
621621
# Verifies library are installed
622622
assert wifi_install_dir.exists()
623623
assert ble_install_dir.exists()
624+
625+
626+
def test_lib_examples(run_command, data_dir):
627+
assert run_command("update")
628+
629+
assert run_command("lib install Arduino_JSON@0.1.0")
630+
631+
res = run_command("lib examples Arduino_JSON --format json")
632+
assert res.ok
633+
data = json.loads(res.stdout)
634+
assert len(data) == 1
635+
examples = data[0]["examples"]
636+
637+
assert str(Path(data_dir, "libraries", "Arduino_JSON", "examples", "JSONArray")) in examples
638+
assert str(Path(data_dir, "libraries", "Arduino_JSON", "examples", "JSONKitchenSink")) in examples
639+
assert str(Path(data_dir, "libraries", "Arduino_JSON", "examples", "JSONObject")) in examples
640+
641+
642+
def test_lib_examples_with_pde_file(run_command, data_dir):
643+
assert run_command("update")
644+
645+
assert run_command("lib install Encoder@1.4.1")
646+
647+
res = run_command("lib examples Encoder --format json")
648+
assert res.ok
649+
data = json.loads(res.stdout)
650+
assert len(data) == 1
651+
examples = data[0]["examples"]
652+
653+
assert str(Path(data_dir, "libraries", "Encoder", "examples", "Basic")) in examples
654+
assert str(Path(data_dir, "libraries", "Encoder", "examples", "NoInterrupts")) in examples
655+
assert str(Path(data_dir, "libraries", "Encoder", "examples", "SpeedTest")) in examples
656+
assert str(Path(data_dir, "libraries", "Encoder", "examples", "TwoKnobs")) in examples

0 commit comments

Comments
 (0)