@@ -116,3 +116,41 @@ func TestCompilerErrOutput(t *testing.T) {
116116 compilerErr := requirejson .Parse (t , out ).Query (".compiler_err" )
117117 compilerErr .MustContain (`"error"` )
118118}
119+
120+ func TestCompileRelativeLibraryPath (t * testing.T ) {
121+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
122+ defer env .CleanUp ()
123+
124+ // Initialize configs to enable --zip-path flag
125+ _ , _ , err := cli .Run ("config" , "init" , "--dest-dir" , "." )
126+ require .NoError (t , err )
127+ _ , _ , err = cli .Run ("config" , "set" , "library.enable_unsafe_install" , "true" , "--config-file" , "arduino-cli.yaml" )
128+ require .NoError (t , err )
129+ configFile := cli .WorkingDir ().Join ("arduino-cli.yaml" )
130+
131+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
132+ require .NoError (t , err )
133+
134+ // Install library and its dependencies
135+ zipPath , err := paths .New (".." , "testdata" , "FooLib.zip" ).Abs ()
136+ require .NoError (t , err )
137+ // Manually install the library and move into one of the example's directories
138+ FooLib := cli .WorkingDir ().Join ("FooLib" )
139+ err = paths .New (".." , "testdata" , "FooLib" ).CopyDirTo (FooLib )
140+ require .NoError (t , err )
141+ cli .SetWorkingDir (FooLib .Join ("examples" , "FooSketch" ))
142+
143+ // Compile using a relative path to the library
144+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--library" , "../../" )
145+ require .NoError (t , err )
146+
147+ // Install the same library using lib install and compile again using the relative path.
148+ // The manually installed library should be chosen
149+ _ , _ , err = cli .Run ("lib" , "install" , "--zip-path" , zipPath .String (), "--config-file" , configFile .String ())
150+ require .NoError (t , err )
151+ stdout , _ , err := cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--library" , "../../" , "-v" )
152+ require .NoError (t , err )
153+ require .Contains (t , string (stdout ), "Multiple libraries were found for \" FooLib.h\" " )
154+ require .Contains (t , string (stdout ), "Used: " + FooLib .String ())
155+ require .Contains (t , string (stdout ), "Not used: " + cli .SketchbookDir ().Join ("libraries" , "FooLib" ).String ())
156+ }
0 commit comments