@@ -60,3 +60,55 @@ func TestCompileWithLibrary(t *testing.T) {
6060 require .NoError (t , err )
6161 require .Contains (t , string (stdout ), "WiFi101" )
6262}
63+
64+ func TestCompileWithLibraryPriority (t * testing.T ) {
65+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
66+ defer env .CleanUp ()
67+
68+ _ , _ , err := cli .Run ("update" )
69+ require .NoError (t , err )
70+
71+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
72+ require .NoError (t , err )
73+
74+ sketchName := "CompileSketchWithLibraryPriority"
75+ sketchPath := cli .SketchbookDir ().Join (sketchName )
76+ fqbn := "arduino:avr:uno"
77+
78+ // Manually installs a library
79+ gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
80+ manuallyInstalledLibPath := cli .SketchbookDir ().Join ("my-libraries" , "WiFi101" )
81+ _ , err = git .PlainClone (manuallyInstalledLibPath .String (), false , & git.CloneOptions {
82+ URL : gitUrl ,
83+ ReferenceName : plumbing .NewTagReferenceName ("0.16.1" ),
84+ })
85+ require .NoError (t , err )
86+
87+ // Install the same library we installed manually
88+ _ , _ , err = cli .Run ("lib" , "install" , "WiFi101" )
89+ require .NoError (t , err )
90+
91+ // Create new sketch and add library include
92+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
93+ require .NoError (t , err )
94+ sketchFile := sketchPath .Join (sketchName + ".ino" )
95+ lines , err := sketchFile .ReadFileAsLines ()
96+ require .NoError (t , err )
97+ lines = append ([]string {"#include <WiFi101.h>\n " }, lines ... )
98+ var data []byte
99+ for _ , l := range lines {
100+ data = append (data , []byte (l )... )
101+ }
102+ err = sketchFile .WriteFile (data )
103+ require .NoError (t , err )
104+
105+ stdout , _ , err := cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--library" , manuallyInstalledLibPath .String (), "-v" )
106+ require .NoError (t , err )
107+ cliInstalledLibPath := cli .SketchbookDir ().Join ("libraries" , "WiFi101" )
108+ expectedOutput := [3 ]string {
109+ "Multiple libraries were found for \" WiFi101.h\" " ,
110+ " Used: " + manuallyInstalledLibPath .String (),
111+ " Not used: " + cliInstalledLibPath .String (),
112+ }
113+ require .Contains (t , string (stdout ), expectedOutput [0 ]+ "\n " + expectedOutput [1 ]+ "\n " + expectedOutput [2 ]+ "\n " )
114+ }
0 commit comments