@@ -26,6 +26,7 @@ import (
2626 "github.com/go-git/go-git/v5"
2727 "github.com/go-git/go-git/v5/plumbing"
2828 "github.com/stretchr/testify/require"
29+ "go.bug.st/testifyjson/requirejson"
2930)
3031
3132func TestCompilePart4 (t * testing.T ) {
@@ -449,3 +450,41 @@ func TestCompileWithKnownPlatformNotInstalled(t *testing.T) {
449450 // Verifies command to fix error is shown to user
450451 require .Contains (t , string (stderr ), "Try running `arduino-cli core install arduino:avr`" )
451452}
453+
454+ func TestSketchWithVendoredLibraries (t * testing.T ) {
455+ sketchBook , err := paths .New ("testdata" , "sketchbook_1" ).Abs ()
456+ require .NoError (t , err )
457+
458+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
459+ defer env .CleanUp ()
460+
461+ cli .SetSketchbookDir (sketchBook )
462+
463+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
464+ require .NoError (t , err )
465+
466+ {
467+ sketchWithLibsPath := sketchBook .Join ("SketchWithLibraries" )
468+ // Sketch should use sketch bundled "MyLib" with and without profiles
469+ out , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:uno" , sketchWithLibsPath .String (), "--format" , "json" )
470+ require .NoError (t , err )
471+ requirejson .Query (t , out , ".builder_result.used_libraries[0].name" , `"MyLib"` )
472+ requirejson .Query (t , out , ".builder_result.used_libraries[0].author" , `"user"` )
473+ out , _ , err = cli .Run ("compile" , "--profile" , "uno" , sketchWithLibsPath .String (), "--format" , "json" )
474+ require .NoError (t , err )
475+ requirejson .Query (t , out , ".builder_result.used_libraries[0].name" , `"MyLib"` )
476+ requirejson .Query (t , out , ".builder_result.used_libraries[0].author" , `"user"` )
477+ }
478+
479+ {
480+ sketchWithoutLibsPath := sketchBook .Join ("SketchWithoutLibraries" )
481+ // This sketch should take the user-installed MyLib
482+ out , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:uno" , sketchWithoutLibsPath .String (), "--format" , "json" )
483+ require .NoError (t , err )
484+ requirejson .Query (t , out , ".builder_result.used_libraries[0].name" , `"MyLib"` )
485+ requirejson .Query (t , out , ".builder_result.used_libraries[0].author" , `"upstream"` )
486+ // This sketch should fail to compile since profiles will not see the user-installed MyLib
487+ _ , _ , err = cli .Run ("compile" , "--profile" , "uno" , sketchWithoutLibsPath .String ())
488+ require .Error (t , err )
489+ }
490+ }
0 commit comments