Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac517be

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

File tree

10 files changed

+54
-3
lines changed

10 files changed

+54
-3
lines changed

‎arduino/sketch/sketch_test.go‎

Lines changed: 36 additions & 0 deletions
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+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() { }
2+
void loop() { }

‎arduino/sketch/testdata/SketchWithSymlink/some_folder/helper.h‎

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() { }
2+
void loop() { }

‎arduino/sketch/testdata/SketchWithSymlinkLoop/some_folder/helper.h‎

Whitespace-only changes.

‎docsgen/go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ replace github.com/arduino/arduino-cli => ../
66

77
require (
88
github.com/arduino/arduino-cli v0.0.0
9+
github.com/arduino/go-paths-helper v1.6.1 // indirect
910
github.com/spf13/cobra v1.0.1-0.20200710201246-675ae5f5a98c
1011
)

‎docsgen/go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3
1616
github.com/arduino/go-paths-helper v1.2.0/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
1717
github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DTjj3Bijx4=
1818
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
19+
github.com/arduino/go-paths-helper v1.6.1 h1:lha+/BuuBsx0qTZ3gy6IO1kU23lObWdQ/UItkzVWQ+0=
20+
github.com/arduino/go-paths-helper v1.6.1/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
1921
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
2022
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2123
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=

‎go.mod‎

Lines changed: 1 addition & 1 deletion
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

‎go.sum‎

Lines changed: 2 additions & 0 deletions
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=

‎test/test_compile.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
130130

131131
# Build sketch for arduino:avr:uno
132132
result = run_command("compile -b {fqbn} {sketch_path}".format(fqbn=fqbn, sketch_path=sketch_path))
133-
assert result.ok
133+
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
134+
# returning a different error detailed message
135+
assert "Error during build: opening sketch" in result.stderr
136+
assert not result.ok
134137

135138
sketch_name = "CompileIntegrationTestSymlinkDirLoop"
136139
sketch_path = os.path.join(data_dir, sketch_name)
@@ -149,7 +152,10 @@ def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
149152

150153
# Build sketch for arduino:avr:uno
151154
result = run_command("compile -b {fqbn} {sketch_path}".format(fqbn=fqbn, sketch_path=sketch_path))
152-
assert result.ok
155+
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
156+
# returning a different error detailed message
157+
assert "Error during build: opening sketch" in result.stderr
158+
assert not result.ok
153159

154160

155161
def test_compile_blacklisted_sketchname(run_command, data_dir):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /