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