Skip to content

Commit 292277f

Browse files
author
Roberto Sora
authored
Add unit and integration testing for the sketch recursive load functionality (#462)
* add testcases to cover #358 (Symbolic link as sketch directory) and #424 (folder with .ino extension) * add test to check error throw on symlink loop detection * create symlink via test code to ensure cross platform creation * fixed assert to make the check cross platform * fixed all symlink check asserts to make the check cross platform * nitpicking
1 parent 44d0f4d commit 292277f

File tree

12 files changed

+121
-1
lines changed

12 files changed

+121
-1
lines changed

arduino/builder/sketch_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,48 @@ func TestLoadSketchFolder(t *testing.T) {
8282
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
8383
}
8484

85+
func TestLoadSketchFolderSymlink(t *testing.T) {
86+
// pass the path to the sketch folder
87+
symlinkSketchPath := filepath.Join("testdata", t.Name())
88+
srcSketchPath := t.Name() + "Src"
89+
os.Symlink(srcSketchPath, symlinkSketchPath)
90+
mainFilePath := filepath.Join(symlinkSketchPath, t.Name()+".ino")
91+
s, err := builder.SketchLoad(symlinkSketchPath, "")
92+
require.Nil(t, err)
93+
require.NotNil(t, s)
94+
require.Equal(t, mainFilePath, s.MainFile.Path)
95+
require.Equal(t, symlinkSketchPath, s.LocationPath)
96+
require.Len(t, s.OtherSketchFiles, 2)
97+
require.Equal(t, "old.pde", filepath.Base(s.OtherSketchFiles[0].Path))
98+
require.Equal(t, "other.ino", filepath.Base(s.OtherSketchFiles[1].Path))
99+
require.Len(t, s.AdditionalFiles, 3)
100+
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
101+
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
102+
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
103+
104+
// pass the path to the main file
105+
symlinkSketchPath = mainFilePath
106+
s, err = builder.SketchLoad(symlinkSketchPath, "")
107+
require.Nil(t, err)
108+
require.NotNil(t, s)
109+
require.Equal(t, mainFilePath, s.MainFile.Path)
110+
require.Len(t, s.OtherSketchFiles, 2)
111+
require.Equal(t, "old.pde", filepath.Base(s.OtherSketchFiles[0].Path))
112+
require.Equal(t, "other.ino", filepath.Base(s.OtherSketchFiles[1].Path))
113+
require.Len(t, s.AdditionalFiles, 3)
114+
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
115+
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
116+
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
117+
}
118+
119+
func TestLoadSketchFolderIno(t *testing.T) {
120+
// pass the path to the sketch folder
121+
sketchPath := filepath.Join("testdata", t.Name())
122+
_, err := builder.SketchLoad(sketchPath, "")
123+
require.Error(t, err)
124+
require.Contains(t, err.Error(), "sketch must not be a directory")
125+
}
126+
85127
func TestLoadSketchFolderWrongMain(t *testing.T) {
86128
sketchPath := filepath.Join("testdata", t.Name())
87129
_, err := builder.SketchLoad(sketchPath, "")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void setup() {
2+
3+
}
4+
5+
void loop() {
6+
7+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup()
2+
void loop) }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void setup() {
2+
3+
}
4+
5+
void loop() {
6+
7+
}

arduino/builder/testdata/TestLoadSketchFolderSymlinkSrc/doc.txt

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define FOO "BAR"

arduino/builder/testdata/TestLoadSketchFolderSymlinkSrc/old.pde

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
String hello() {
2+
return "world";
3+
}

arduino/builder/testdata/TestLoadSketchFolderSymlinkSrc/s_file.S

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <testlib4.h>
2+
#error "Whattya looking at?"

0 commit comments

Comments
 (0)