Skip to content

Commit 560baa3

Browse files
Migrate TestRecompileWithDifferentLibrary from test_compile_part_4.py to compile_part_4_test.go
1 parent c6ea437 commit 560baa3

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

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)