Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions arduino/builder/sketch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void setup() {

}

void loop() {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void setup()
void loop) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void setup() {

}

void loop() {

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define FOO "BAR"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
String hello() {
return "world";
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <testlib4.h>
#error "Whattya looking at?"
Empty file.
58 changes: 58 additions & 0 deletions test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,64 @@ 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" \
"".format(
loop_file_path=loop_file_path) 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
Expand Down