Skip to content

Commit eabae4a

Browse files
Migrate TestRecompileWithDifferentLibrary from test_compile_part_4.py to compile_part_4_test.go
1 parent 99c8e9c commit eabae4a

File tree

2 files changed

+62
-43
lines changed

2 files changed

+62
-43
lines changed

internal/integrationtest/compile/compile_part_4_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
package compile_test
1717

1818
import (
19+
"crypto/md5"
20+
"encoding/hex"
21+
"strings"
1922
"testing"
2023

2124
"github.com/arduino/arduino-cli/internal/integrationtest"
25+
"github.com/arduino/go-paths-helper"
2226
"github.com/stretchr/testify/require"
2327
"gopkg.in/src-d/go-git.v4"
2428
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -116,3 +120,61 @@ func TestCompileWithLibraryPriority(t *testing.T) {
116120
}
117121
require.Contains(t, string(stdout), expectedOutput[0]+"\n"+expectedOutput[1]+"\n"+expectedOutput[2]+"\n")
118122
}
123+
124+
func TestRecompileWithDifferentLibrary(t *testing.T) {
125+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
126+
defer env.CleanUp()
127+
128+
_, _, err := cli.Run("update")
129+
require.NoError(t, err)
130+
131+
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
132+
require.NoError(t, err)
133+
134+
sketchName := "RecompileCompileSketchWithDifferentLibrary"
135+
sketchPath := cli.SketchbookDir().Join(sketchName)
136+
fqbn := "arduino:avr:uno"
137+
138+
// Install library
139+
_, _, err = cli.Run("lib", "install", "WiFi101")
140+
require.NoError(t, err)
141+
142+
// Manually installs a library
143+
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
144+
manuallyInstalledLibPath := cli.SketchbookDir().Join("my-libraries", "WiFi101")
145+
_, err = git.PlainClone(manuallyInstalledLibPath.String(), false, &git.CloneOptions{
146+
URL: gitUrl,
147+
ReferenceName: plumbing.NewTagReferenceName("0.16.1"),
148+
})
149+
require.NoError(t, err)
150+
151+
// Create new sketch and add library include
152+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
153+
require.NoError(t, err)
154+
sketchFile := sketchPath.Join(sketchName + ".ino")
155+
lines, err := sketchFile.ReadFileAsLines()
156+
require.NoError(t, err)
157+
lines = append([]string{"#include <WiFi101.h>\n"}, lines...)
158+
var data []byte
159+
for _, l := range lines {
160+
data = append(data, []byte(l)...)
161+
}
162+
err = sketchFile.WriteFile(data)
163+
require.NoError(t, err)
164+
165+
md5 := md5.Sum(([]byte(sketchPath.String())))
166+
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
167+
require.NotEmpty(t, sketchPathMd5)
168+
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
169+
170+
// Compile sketch using library not managed by CLI
171+
stdout, _, err := cli.Run("compile", "-b", fqbn, "--library", manuallyInstalledLibPath.String(), sketchPath.String(), "-v")
172+
require.NoError(t, err)
173+
objPath := buildDir.Join("libraries", "WiFi101", "WiFi.cpp.o")
174+
require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String())
175+
176+
// Compile again using library installed from CLI
177+
stdout, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "-v")
178+
require.NoError(t, err)
179+
require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String())
180+
}

test/test_compile_part_4.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,6 @@ def test_compile_manually_installed_platform_using_boards_local_txt(run_command,
5050
assert run_command(["compile", "--clean", "-b", fqbn, sketch_path])
5151

5252

53-
def test_recompile_with_different_library(run_command, data_dir):
54-
assert run_command(["update"])
55-
56-
assert run_command(["core", "install", "arduino:avr@1.8.3"])
57-
58-
sketch_name = "RecompileCompileSketchWithDifferentLibrary"
59-
sketch_path = Path(data_dir, sketch_name)
60-
fqbn = "arduino:avr:uno"
61-
62-
# Install library
63-
assert run_command(["lib", "install", "WiFi101"])
64-
65-
# Manually installs the same library already installed
66-
git_url = "https://github.com/arduino-libraries/WiFi101.git"
67-
manually_install_lib_path = Path(data_dir, "my-libraries", "WiFi101")
68-
assert Repo.clone_from(git_url, manually_install_lib_path, multi_options=["-b 0.16.1"])
69-
70-
# Create new sketch and add library include
71-
assert run_command(["sketch", "new", sketch_path])
72-
sketch_file = sketch_path / f"{sketch_name}.ino"
73-
lines = []
74-
with open(sketch_file, "r") as f:
75-
lines = f.readlines()
76-
lines = ["#include <WiFi101.h>"] + lines
77-
with open(sketch_file, "w") as f:
78-
f.writelines(lines)
79-
80-
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
81-
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
82-
83-
# Compile sketch using library not managed by CLI
84-
res = run_command(["compile", "-b", fqbn, "--library", manually_install_lib_path, sketch_path, "-v"])
85-
assert res.ok
86-
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
87-
assert f"Using previously compiled file: {obj_path}" not in res.stdout
88-
89-
# Compile again using library installed from CLI
90-
res = run_command(["compile", "-b", fqbn, sketch_path, "-v"])
91-
assert res.ok
92-
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
93-
assert f"Using previously compiled file: {obj_path}" not in res.stdout
94-
95-
9653
def test_compile_with_conflicting_libraries_include(run_command, data_dir, copy_sketch):
9754
assert run_command(["update"])
9855

0 commit comments

Comments
 (0)