@@ -22,15 +22,32 @@ import (
22
22
"github.com/arduino/arduino-cli/internal/integrationtest"
23
23
"github.com/arduino/go-paths-helper"
24
24
"github.com/stretchr/testify/require"
25
+ "go.bug.st/testifyjson/requirejson"
25
26
)
26
27
27
28
func TestSketchProfileDump (t * testing.T ) {
28
29
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
29
- defer env .CleanUp ( )
30
+ t . Cleanup ( env .CleanUp )
30
31
31
- sketch , err := paths .New ("testdata" , "SketchWithLibrary" ).Abs ()
32
+ // Prepare the sketch with libraries
33
+ tmpDir , err := paths .MkTempDir ("" , "" )
32
34
require .NoError (t , err )
35
+ t .Cleanup (func () { _ = tmpDir .RemoveAll })
33
36
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
34
51
_ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.6" )
35
52
require .NoError (t , err )
36
53
_ , _ , err = cli .Run ("lib" , "install" , "Adafruit BusIO@1.17.1" )
@@ -44,9 +61,8 @@ func TestSketchProfileDump(t *testing.T) {
44
61
// - keeps libraries in the sketch with a relative path
45
62
// - keeps libraries outside the sketch with an absolute path
46
63
// - keeps libraries installed in the system with just the name and version
47
- libOutside := sketch .Join (".." , "MyLibOutside" )
48
64
out , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:uno" ,
49
- "--library" , sketch . Join ( "libraries" , "MyLib" ) .String (),
65
+ "--library" , libInside .String (),
50
66
"--library" , libOutside .String (),
51
67
"--dump-profile" ,
52
68
sketch .String ())
@@ -64,4 +80,20 @@ profiles:
64
80
- Adafruit GFX Library (1.12.1)
65
81
- Adafruit BusIO (1.17.1)
66
82
` ), 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
+ }` )
67
99
}
0 commit comments