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 1589119

Browse files
committed
Improved integration tests
1 parent 9483f8d commit 1589119

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

‎internal/integrationtest/sketch/profiles_test.go‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,39 @@
1616
package sketch_test
1717

1818
import (
19+
"encoding/json"
1920
"strings"
2021
"testing"
2122

2223
"github.com/arduino/arduino-cli/internal/integrationtest"
2324
"github.com/arduino/go-paths-helper"
2425
"github.com/stretchr/testify/require"
26+
"go.bug.st/testifyjson/requirejson"
2527
)
2628

2729
func TestSketchProfileDump(t *testing.T) {
2830
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
29-
deferenv.CleanUp()
31+
t.Cleanup(env.CleanUp)
3032

31-
sketch, err := paths.New("testdata", "SketchWithLibrary").Abs()
33+
// Prepare the sketch with libraries
34+
tmpDir, err := paths.MkTempDir("", "")
3235
require.NoError(t, err)
36+
t.Cleanup(func() { _ = tmpDir.RemoveAll })
3337

38+
sketchTemplate, err := paths.New("testdata", "SketchWithLibrary").Abs()
39+
require.NoError(t, err)
40+
41+
sketch := tmpDir.Join("SketchWithLibrary")
42+
libInside := sketch.Join("libraries", "MyLib")
43+
err = sketchTemplate.CopyDirTo(sketch)
44+
require.NoError(t, err)
45+
46+
libOutsideTemplate := sketchTemplate.Join("..", "MyLibOutside")
47+
libOutside := sketch.Join("..", "MyLibOutside")
48+
err = libOutsideTemplate.CopyDirTo(libOutside)
49+
require.NoError(t, err)
50+
51+
// Install the required core and libraries
3452
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")
3553
require.NoError(t, err)
3654
_, _, err = cli.Run("lib", "install", "Adafruit BusIO@1.17.1")
@@ -44,9 +62,8 @@ func TestSketchProfileDump(t *testing.T) {
4462
// - keeps libraries in the sketch with a relative path
4563
// - keeps libraries outside the sketch with an absolute path
4664
// - keeps libraries installed in the system with just the name and version
47-
libOutside := sketch.Join("..", "MyLibOutside")
4865
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno",
49-
"--library", sketch.Join("libraries", "MyLib").String(),
66+
"--library", libInside.String(),
5067
"--library", libOutside.String(),
5168
"--dump-profile",
5269
sketch.String())
@@ -64,4 +81,19 @@ profiles:
6481
- Adafruit GFX Library (1.12.1)
6582
- Adafruit BusIO (1.17.1)
6683
`), strings.TrimSpace(string(out)))
84+
85+
// Dump the profile in the sketch directory and compile with it again
86+
err = sketch.Join("sketch.yaml").WriteFile(out)
87+
require.NoError(t, err)
88+
out, _, err = cli.Run("compile", "-m", "uno", "--json", sketch.String())
89+
require.NoError(t, err)
90+
// Check if local libraries are picked up correctly
91+
libInsideJson, _ := json.Marshal(libInside.String())
92+
libOutsideJson, _ := json.Marshal(libOutside.String())
93+
j := requirejson.Parse(t, out).Query(".builder_result.used_libraries")
94+
j.MustContain(`
95+
[
96+
{"name": "MyLib", "install_dir": ` + string(libInsideJson) + `},
97+
{"name": "MyLibOutside", "install_dir": ` + string(libOutsideJson) + `}
98+
]`)
6799
}

0 commit comments

Comments
(0)

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