Unverified Commit 292277f0 authored by Roberto Sora's avatar Roberto Sora Committed by GitHub

Add unit and integration testing for the sketch recursive load functionality (#462)

* add testcases to cover https://github.com/arduino/arduino-cli/issues/358 (Symbolic link as sketch directory) and https://github.com/arduino/arduino-cli/issues/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
parent 44d0f4de
......@@ -82,6 +82,48 @@ func TestLoadSketchFolder(t *testing.T) {
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
}
func TestLoadSketchFolderSymlink(t *testing.T) {
// pass the path to the sketch folder
symlinkSketchPath := filepath.Join("testdata", t.Name())
srcSketchPath := t.Name() + "Src"
os.Symlink(srcSketchPath, symlinkSketchPath)
mainFilePath := filepath.Join(symlinkSketchPath, t.Name()+".ino")
s, err := builder.SketchLoad(symlinkSketchPath, "")
require.Nil(t, err)
require.NotNil(t, s)
require.Equal(t, mainFilePath, s.MainFile.Path)
require.Equal(t, symlinkSketchPath, s.LocationPath)
require.Len(t, s.OtherSketchFiles, 2)
require.Equal(t, "old.pde", filepath.Base(s.OtherSketchFiles[0].Path))
require.Equal(t, "other.ino", filepath.Base(s.OtherSketchFiles[1].Path))
require.Len(t, s.AdditionalFiles, 3)
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
// pass the path to the main file
symlinkSketchPath = mainFilePath
s, err = builder.SketchLoad(symlinkSketchPath, "")
require.Nil(t, err)
require.NotNil(t, s)
require.Equal(t, mainFilePath, s.MainFile.Path)
require.Len(t, s.OtherSketchFiles, 2)
require.Equal(t, "old.pde", filepath.Base(s.OtherSketchFiles[0].Path))
require.Equal(t, "other.ino", filepath.Base(s.OtherSketchFiles[1].Path))
require.Len(t, s.AdditionalFiles, 3)
require.Equal(t, "header.h", filepath.Base(s.AdditionalFiles[0].Path))
require.Equal(t, "s_file.S", filepath.Base(s.AdditionalFiles[1].Path))
require.Equal(t, "helper.h", filepath.Base(s.AdditionalFiles[2].Path))
}
func TestLoadSketchFolderIno(t *testing.T) {
// pass the path to the sketch folder
sketchPath := filepath.Join("testdata", t.Name())
_, err := builder.SketchLoad(sketchPath, "")
require.Error(t, err)
require.Contains(t, err.Error(), "sketch must not be a directory")
}
func TestLoadSketchFolderWrongMain(t *testing.T) {
sketchPath := filepath.Join("testdata", t.Name())
_, err := builder.SketchLoad(sketchPath, "")
......
void setup()
void loop) }
\ No newline at end of file
void setup() {
}
void loop() {
}
\ No newline at end of file
#define FOO "BAR"
\ No newline at end of file
String hello() {
return "world";
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ def test_compile_with_simple_sketch(run_command, data_dir):
result = run_command("core update-index")
assert result.ok
# # Download latest AVR
# Download latest AVR
result = run_command("core install arduino:avr")
assert result.ok
......@@ -70,6 +70,62 @@ def test_compile_with_simple_sketch(run_command, data_dir):
assert is_message_sequence_in_json_log_traces(expected_trace_sequence, json_log_lines)
def test_compile_with_sketch_with_symlink_selfloop(run_command, data_dir):
# Init the environment explicitly
result = run_command("core update-index")
assert result.ok
# Download latest AVR
result = run_command("core install arduino:avr")
assert result.ok
sketch_name = "CompileIntegrationTestSymlinkSelfLoop"
sketch_path = os.path.join(data_dir, sketch_name)
fqbn = "arduino:avr:uno"
# Create a test sketch
result = run_command("sketch new {}".format(sketch_path))
assert result.ok
assert "Sketch created in: {}".format(sketch_path) in result.stdout
# create a symlink that loops on himself
loop_file_path = os.path.join(sketch_path, "loop")
os.symlink(loop_file_path, loop_file_path)
# Build sketch for arduino:avr:uno
result = run_command(
"compile -b {fqbn} {sketch_path}".format(
fqbn=fqbn, sketch_path=sketch_path))
# The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
# returning a different error detailed message
assert "Error during sketch processing" in result.stderr
assert not result.ok
sketch_name = "CompileIntegrationTestSymlinkDirLoop"
sketch_path = os.path.join(data_dir, sketch_name)
fqbn = "arduino:avr:uno"
# Create a test sketch
result = run_command("sketch new {}".format(sketch_path))
assert result.ok
assert "Sketch created in: {}".format(sketch_path) in result.stdout
# create a symlink that loops on the upper level
loop_dir_path = os.path.join(sketch_path, "loop_dir")
os.mkdir(loop_dir_path)
loop_dir_symlink_path = os.path.join(loop_dir_path, "loop_dir_symlink")
os.symlink(loop_dir_path, loop_dir_symlink_path)
# Build sketch for arduino:avr:uno
result = run_command(
"compile -b {fqbn} {sketch_path}".format(
fqbn=fqbn, sketch_path=sketch_path))
# The assertion is a bit relaxed also in this case because macOS behaves differently from win and linux:
# the cli does not follow recursively the symlink til breaking
assert "Error during sketch processing" in result.stderr
assert not result.ok
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
def test_compile_and_compile_combo(run_command, data_dir):
# Init the environment explicitly
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment