Skip to content

Commit 876deb6

Browse files
Migrate TestCompileWithSketchWithSymlinkSelfloop from test_compile_part_1.py to compile_part_1_test.go
1 parent 63e6be1 commit 876deb6

File tree

2 files changed

+58
-50
lines changed

2 files changed

+58
-50
lines changed

internal/integrationtest/compile/compile_part_1_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"crypto/md5"
2020
"encoding/hex"
2121
"encoding/json"
22+
"os"
2223
"strings"
2324
"testing"
2425

@@ -171,3 +172,60 @@ func TestOutputFlagDefaultPath(t *testing.T) {
171172
require.NoError(t, err)
172173
require.DirExists(t, target.String())
173174
}
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+
}

test/test_compile_part_1.py

-50
Original file line numberDiff line numberDiff line change
@@ -25,56 +25,6 @@
2525
from .common import running_on_ci
2626

2727

28-
def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
29-
# Init the environment explicitly
30-
run_command(["core", "update-index"])
31-
32-
# Install Arduino AVR Boards
33-
run_command(["core", "install", "arduino:[email protected]"])
34-
35-
sketch_name = "CompileIntegrationTestSymlinkSelfLoop"
36-
sketch_path = os.path.join(data_dir, sketch_name)
37-
fqbn = "arduino:avr:uno"
38-
39-
# Create a test sketch
40-
result = run_command(["sketch", "new", sketch_path])
41-
assert result.ok
42-
assert "Sketch created in: {}".format(sketch_path) in result.stdout
43-
44-
# create a symlink that loops on himself
45-
loop_file_path = os.path.join(sketch_path, "loop")
46-
os.symlink(loop_file_path, loop_file_path)
47-
48-
# Build sketch for arduino:avr:uno
49-
result = run_command(["compile", "-b", fqbn, sketch_path])
50-
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
51-
# returning a different error detailed message
52-
assert "Error opening sketch:" in result.stderr
53-
assert not result.ok
54-
55-
sketch_name = "CompileIntegrationTestSymlinkDirLoop"
56-
sketch_path = os.path.join(data_dir, sketch_name)
57-
fqbn = "arduino:avr:uno"
58-
59-
# Create a test sketch
60-
result = run_command(["sketch", "new", sketch_path])
61-
assert result.ok
62-
assert "Sketch created in: {}".format(sketch_path) in result.stdout
63-
64-
# create a symlink that loops on the upper level
65-
loop_dir_path = os.path.join(sketch_path, "loop_dir")
66-
os.mkdir(loop_dir_path)
67-
loop_dir_symlink_path = os.path.join(loop_dir_path, "loop_dir_symlink")
68-
os.symlink(loop_dir_path, loop_dir_symlink_path)
69-
70-
# Build sketch for arduino:avr:uno
71-
result = run_command(["compile", "-b", fqbn, sketch_path])
72-
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
73-
# returning a different error detailed message
74-
assert "Error opening sketch:" in result.stderr
75-
assert not result.ok
76-
77-
7828
def test_compile_blacklisted_sketchname(run_command, data_dir):
7929
"""
8030
Compile should ignore folders named `RCS`, `.git` and the likes, but

0 commit comments

Comments
 (0)