Skip to content

Commit f852cf7

Browse files
committed
Add tests loading Sketch with symlinks
1 parent 7d00b83 commit f852cf7

File tree

7 files changed

+43
-1
lines changed

7 files changed

+43
-1
lines changed

Diff for: arduino/sketch/sketch_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,39 @@ func TestCheckForPdeFiles(t *testing.T) {
300300
require.Len(t, files, 1)
301301
require.Equal(t, sketchPath.Parent().Join("SketchMultipleMainFiles.pde"), files[0])
302302
}
303+
304+
func TestNewSketchWithSymlink(t *testing.T) {
305+
sketchPath, _ := paths.New("testdata", "SketchWithSymlink").Abs()
306+
mainFilePath := sketchPath.Join("SketchWithSymlink.ino")
307+
helperFilePath := sketchPath.Join("some_folder", "helper.h")
308+
helperFileSymlinkPath := sketchPath.Join("src", "helper.h")
309+
srcPath := sketchPath.Join("src")
310+
311+
// Create a symlink in the Sketch folder
312+
os.Symlink(sketchPath.Join("some_folder").String(), srcPath.String())
313+
defer srcPath.Remove()
314+
315+
sketch, err := New(sketchPath)
316+
require.NoError(t, err)
317+
require.NotNil(t, sketch)
318+
require.True(t, sketch.MainFile.EquivalentTo(mainFilePath))
319+
require.True(t, sketch.FullPath.EquivalentTo(sketchPath))
320+
require.Equal(t, sketch.OtherSketchFiles.Len(), 0)
321+
require.Equal(t, sketch.AdditionalFiles.Len(), 2)
322+
require.True(t, sketch.AdditionalFiles.Contains(helperFilePath))
323+
require.True(t, sketch.AdditionalFiles.Contains(helperFileSymlinkPath))
324+
require.Equal(t, sketch.RootFolderFiles.Len(), 0)
325+
}
326+
327+
func TestNewSketchWithSymlinkLoop(t *testing.T) {
328+
sketchPath, _ := paths.New("testdata", "SketchWithSymlinkLoop").Abs()
329+
someSymlinkPath := sketchPath.Join("some_folder", "some_symlink")
330+
331+
// Create a recursive Sketch symlink
332+
os.Symlink(sketchPath.String(), someSymlinkPath.String())
333+
defer someSymlinkPath.Remove()
334+
335+
sketch, err := New(sketchPath)
336+
require.Error(t, err)
337+
require.Nil(t, sketch)
338+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() { }
2+
void loop() { }

Diff for: arduino/sketch/testdata/SketchWithSymlink/some_folder/helper.h

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() { }
2+
void loop() { }

Diff for: arduino/sketch/testdata/SketchWithSymlinkLoop/some_folder/helper.h

Whitespace-only changes.

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
7-
github.com/arduino/go-paths-helper v1.6.0
7+
github.com/arduino/go-paths-helper v1.6.1
88
github.com/arduino/go-properties-orderedmap v1.5.0
99
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1010
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ github.com/arduino/go-paths-helper v1.5.0 h1:RVo189hD+GhUS1rQ3gixwK1nSbvVR8MGIGa
2020
github.com/arduino/go-paths-helper v1.5.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
2121
github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DTjj3Bijx4=
2222
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
23+
github.com/arduino/go-paths-helper v1.6.1 h1:lha+/BuuBsx0qTZ3gy6IO1kU23lObWdQ/UItkzVWQ+0=
24+
github.com/arduino/go-paths-helper v1.6.1/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
2325
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
2426
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2527
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=

0 commit comments

Comments
 (0)