Skip to content

Commit 1d46837

Browse files
committed
Improved integration tests
1 parent cdd7f4e commit 1d46837

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
@@ -22,15 +22,32 @@ import (
2222
"github.com/arduino/arduino-cli/internal/integrationtest"
2323
"github.com/arduino/go-paths-helper"
2424
"github.com/stretchr/testify/require"
25+
"go.bug.st/testifyjson/requirejson"
2526
)
2627

2728
func TestSketchProfileDump(t *testing.T) {
2829
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
29-
defer env.CleanUp()
30+
t.Cleanup(env.CleanUp)
3031

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

37+
sketchTemplate, err := paths.New("testdata", "SketchWithLibrary").Abs()
38+
require.NoError(t, err)
39+
40+
sketch := tmpDir.Join("SketchWithLibrary")
41+
libInside := sketch.Join("libraries", "MyLib")
42+
err = sketchTemplate.CopyDirTo(sketch)
43+
require.NoError(t, err)
44+
45+
libOutsideTemplate := sketchTemplate.Join("..", "MyLibOutside")
46+
libOutside := sketch.Join("..", "MyLibOutside")
47+
err = libOutsideTemplate.CopyDirTo(libOutside)
48+
require.NoError(t, err)
49+
50+
// Install the required core and libraries
3451
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")
3552
require.NoError(t, err)
3653
_, _, err = cli.Run("lib", "install", "Adafruit BusIO@1.17.1")
@@ -44,9 +61,8 @@ func TestSketchProfileDump(t *testing.T) {
4461
// - keeps libraries in the sketch with a relative path
4562
// - keeps libraries outside the sketch with an absolute path
4663
// - keeps libraries installed in the system with just the name and version
47-
libOutside := sketch.Join("..", "MyLibOutside")
4864
out, _, err := cli.Run("compile", "-b", "arduino:avr:uno",
49-
"--library", sketch.Join("libraries", "MyLib").String(),
65+
"--library", libInside.String(),
5066
"--library", libOutside.String(),
5167
"--dump-profile",
5268
sketch.String())
@@ -64,4 +80,20 @@ profiles:
6480
- Adafruit GFX Library (1.12.1)
6581
- Adafruit BusIO (1.17.1)
6682
`), strings.TrimSpace(string(out)))
83+
84+
// Dump the profile in the sketch directory and compile with it again
85+
err = sketch.Join("sketch.yaml").WriteFile(out)
86+
out, _, err = cli.Run("compile", "-m", "uno", "--json", sketch.String())
87+
require.NoError(t, err)
88+
// Check if local libraries are picked up correctly
89+
j := requirejson.Parse(t, out)
90+
j.MustContain(`
91+
{
92+
"builder_result": {
93+
"used_libraries": [
94+
{"name": "MyLib", "install_dir": "` + libInside.String() + `"},
95+
{"name": "MyLibOutside", "install_dir": "` + libOutside.String() + `"}
96+
]
97+
}
98+
}`)
6799
}

0 commit comments

Comments
 (0)