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