Skip to content

Commit

Permalink
Added integration test for sketch-vendored libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Jan 24, 2024
1 parent 10dd714 commit 1020934
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func (cli *ArduinoCLI) SketchbookDir() *paths.Path {
return cli.sketchbookDir
}

// SetSketchbookDir sets the sketchbook directory
func (cli *ArduinoCLI) SetSketchbookDir(d *paths.Path) {
cli.sketchbookDir = d
cli.cliEnvVars["ARDUINO_SKETCHBOOK_DIR"] = d.String()
}

// WorkingDir returns the working directory
func (cli *ArduinoCLI) WorkingDir() *paths.Path {
return cli.workingDir
Expand Down
39 changes: 39 additions & 0 deletions internal/integrationtest/compile_2/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
)

func TestCompilePart4(t *testing.T) {
Expand Down Expand Up @@ -449,3 +450,41 @@ func TestCompileWithKnownPlatformNotInstalled(t *testing.T) {
// Verifies command to fix error is shown to user
require.Contains(t, string(stderr), "Try running `arduino-cli core install arduino:avr`")
}

func TestSketchWithVendoredLibraries(t *testing.T) {
sketchBook, err := paths.New("testdata", "sketchbook_1").Abs()
require.NoError(t, err)

env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

cli.SetSketchbookDir(sketchBook)

_, _, err = cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)

{
sketchWithLibsPath := sketchBook.Join("SketchWithLibraries")
// Sketch should use sketch bundled "MyLib" with and without profiles
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", sketchWithLibsPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"user"`)
out, _, err = cli.Run("compile", "--profile", "uno", sketchWithLibsPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"user"`)
}

{
sketchWithoutLibsPath := sketchBook.Join("SketchWithoutLibraries")
// This sketch should take the user-installed MyLib
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno", sketchWithoutLibsPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, out, ".builder_result.used_libraries[0].name", `"MyLib"`)
requirejson.Query(t, out, ".builder_result.used_libraries[0].author", `"upstream"`)
// This sketch should fail to compile since profiles will not see the user-installed MyLib
_, _, err = cli.Run("compile", "--profile", "uno", sketchWithoutLibsPath.String())
require.Error(t, err)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <MyLib.h>

void setup() {}
void loop() {
myFunction();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

void anotherFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name=AnotherLib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

void myFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=MyLib
author=user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
profiles:
uno:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.5)

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <MyLib.h>

void setup() {}
void loop() {
myWrongFunction();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
profiles:
uno:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.5)

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

// This is the wrong library to include (the sketch-bundled one should take priority)

void myWrongFunction() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=MyLib
author=upstream

0 comments on commit 1020934

Please sign in to comment.