@@ -19,6 +19,7 @@ import (
19
19
"crypto/md5"
20
20
"encoding/hex"
21
21
"encoding/json"
22
+ "os"
22
23
"strings"
23
24
"testing"
24
25
@@ -171,3 +172,60 @@ func TestOutputFlagDefaultPath(t *testing.T) {
171
172
require .NoError (t , err )
172
173
require .DirExists (t , target .String ())
173
174
}
175
+
176
+ func TestCompileWithSketchWithSymlinkSelfloop (t * testing.T ) {
177
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
178
+ defer env .CleanUp ()
179
+
180
+ // Init the environment explicitly
181
+ _ , _ , err := cli .Run ("core" , "update-index" )
182
+ require .NoError (t , err )
183
+
184
+ // Install Arduino AVR Boards
185
+ _ ,
_ ,
err = cli .
Run (
"core" ,
"install" ,
"arduino:[email protected] " )
186
+ require .NoError (t , err )
187
+
188
+ sketchName := "CompileIntegrationTestSymlinkSelfLoop"
189
+ sketchPath := cli .SketchbookDir ().Join (sketchName )
190
+ fqbn := "arduino:avr:uno"
191
+
192
+ // Create a test sketch
193
+ stdout , _ , err := cli .Run ("sketch" , "new" , sketchPath .String ())
194
+ require .NoError (t , err )
195
+ require .Contains (t , string (stdout ), "Sketch created in: " + sketchPath .String ())
196
+
197
+ // create a symlink that loops on himself
198
+ loopFilePath := sketchPath .Join ("loop" )
199
+ err = os .Symlink (loopFilePath .String (), loopFilePath .String ())
200
+ require .NoError (t , err )
201
+
202
+ // Build sketch for arduino:avr:uno
203
+ _ , stderr , err := cli .Run ("compile" , "-b" , fqbn , sketchPath .String ())
204
+ // The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
205
+ // returning a different error detailed message
206
+ require .Contains (t , string (stderr ), "Error opening sketch:" )
207
+ require .Error (t , err )
208
+
209
+ sketchName = "CompileIntegrationTestSymlinkDirLoop"
210
+ sketchPath = cli .SketchbookDir ().Join (sketchName )
211
+
212
+ // Create a test sketch
213
+ stdout , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
214
+ require .NoError (t , err )
215
+ require .Contains (t , string (stdout ), "Sketch created in: " + sketchPath .String ())
216
+
217
+ // create a symlink that loops on the upper level
218
+ loopDirPath := sketchPath .Join ("loop_dir" )
219
+ err = loopDirPath .Mkdir ()
220
+ require .NoError (t , err )
221
+ loopDirSymlinkPath := loopDirPath .Join ("loop_dir_symlink" )
222
+ err = os .Symlink (loopDirPath .String (), loopDirSymlinkPath .String ())
223
+ require .NoError (t , err )
224
+
225
+ // Build sketch for arduino:avr:uno
226
+ _ , stderr , err = cli .Run ("compile" , "-b" , fqbn , sketchPath .String ())
227
+ // The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
228
+ // returning a different error detailed message
229
+ require .Contains (t , string (stderr ), "Error opening sketch:" )
230
+ require .Error (t , err )
231
+ }
0 commit comments