Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dcc216f

Browse files
committed
Added integration test for sketch-vendored libraries
1 parent 89afc67 commit dcc216f

File tree

12 files changed

+85
-0
lines changed

12 files changed

+85
-0
lines changed

‎internal/integrationtest/arduino-cli.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
158158
return cli.sketchbookDir
159159
}
160160

161+
// SetSketchbookDir sets the sketchbook directory
162+
func (cli *ArduinoCLI) SetSketchbookDir(d *paths.Path) {
163+
cli.sketchbookDir = d
164+
cli.cliEnvVars["ARDUINO_SKETCHBOOK_DIR"] = d.String()
165+
}
166+
161167
// WorkingDir returns the working directory
162168
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
163169
return cli.workingDir

‎internal/integrationtest/compile_2/compile_test.go‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/go-git/go-git/v5"
2727
"github.com/go-git/go-git/v5/plumbing"
2828
"github.com/stretchr/testify/require"
29+
"go.bug.st/testifyjson/requirejson"
2930
)
3031

3132
func TestCompilePart4(t *testing.T) {
@@ -449,3 +450,41 @@ func TestCompileWithKnownPlatformNotInstalled(t *testing.T) {
449450
// Verifies command to fix error is shown to user
450451
require.Contains(t, string(stderr), "Try running `arduino-cli core install arduino:avr`")
451452
}
453+
454+
func TestSketchWithVendoredLibraries(t *testing.T) {
455+
sketchBook, err := paths.New("testdata", "sketchbook_1").Abs()
456+
require.NoError(t, err)
457+
458+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
459+
defer env.CleanUp()
460+
461+
cli.SetSketchbookDir(sketchBook)
462+
463+
_, _, err = cli.Run("core", "install", "arduino:avr")
464+
require.NoError(t, err)
465+
466+
{
467+
sketchWithLibsPath := sketchBook.Join("SketchWithLibraries")
468+
// Sketch should use sketch bundled "MyLib" with and without profiles
469+
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", sketchWithLibsPath.String(), "--format", "json")
470+
require.NoError(t, err)
471+
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
472+
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"user"`)
473+
out, _, err = cli.Run("compile", "--profile", "uno", sketchWithLibsPath.String(), "--format", "json")
474+
require.NoError(t, err)
475+
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
476+
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"user"`)
477+
}
478+
479+
{
480+
sketchWithoutLibsPath := sketchBook.Join("SketchWithoutLibraries")
481+
// This sketch should take the user-installed MyLib
482+
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", sketchWithoutLibsPath.String(), "--format", "json")
483+
require.NoError(t, err)
484+
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
485+
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"upstream"`)
486+
// This sketch should fail to compile since profiles will not see the user-installed MyLib
487+
_, _, err = cli.Run("compile", "--profile", "uno", sketchWithoutLibsPath.String())
488+
require.Error(t, err)
489+
}
490+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <MyLib.h>
2+
3+
void setup() {}
4+
void loop() {
5+
myFunction();
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
void anotherFunction() {
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name=AnotherLib
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
void myFunction() {
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name=MyLib
2+
author=user
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
profiles:
2+
uno:
3+
fqbn: arduino:avr:uno
4+
platforms:
5+
- platform: arduino:avr (1.8.5)
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <MyLib.h>
2+
3+
void setup() {}
4+
void loop() {
5+
myWrongFunction();
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
profiles:
2+
uno:
3+
fqbn: arduino:avr:uno
4+
platforms:
5+
- platform: arduino:avr (1.8.5)
6+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /