Skip to content

Commit 99c8e9c

Browse files
Migrate TestCompileWithLibraryPriority from test_compile_part_4.py to compile_part_4_test.go
1 parent c18541f commit 99c8e9c

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

internal/integrationtest/compile/compile_part_4_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,55 @@ func TestCompileWithLibrary(t *testing.T) {
6464
require.NoError(t, err)
6565
require.Contains(t, string(stdout), "WiFi101")
6666
}
67+
68+
func TestCompileWithLibraryPriority(t *testing.T) {
69+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
70+
defer env.CleanUp()
71+
72+
_, _, err := cli.Run("update")
73+
require.NoError(t, err)
74+
75+
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
76+
require.NoError(t, err)
77+
78+
sketchName := "CompileSketchWithLibraryPriority"
79+
sketchPath := cli.SketchbookDir().Join(sketchName)
80+
fqbn := "arduino:avr:uno"
81+
82+
// Manually installs a library
83+
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
84+
manuallyInstalledLibPath := cli.SketchbookDir().Join("my-libraries", "WiFi101")
85+
_, err = git.PlainClone(manuallyInstalledLibPath.String(), false, &git.CloneOptions{
86+
URL: gitUrl,
87+
ReferenceName: plumbing.NewTagReferenceName("0.16.1"),
88+
})
89+
require.NoError(t, err)
90+
91+
// Install the same library we installed manually
92+
_, _, err = cli.Run("lib", "install", "WiFi101")
93+
require.NoError(t, err)
94+
95+
// Create new sketch and add library include
96+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
97+
require.NoError(t, err)
98+
sketchFile := sketchPath.Join(sketchName + ".ino")
99+
lines, err := sketchFile.ReadFileAsLines()
100+
require.NoError(t, err)
101+
lines = append([]string{"#include <WiFi101.h>\n"}, lines...)
102+
var data []byte
103+
for _, l := range lines {
104+
data = append(data, []byte(l)...)
105+
}
106+
err = sketchFile.WriteFile(data)
107+
require.NoError(t, err)
108+
109+
stdout, _, err := cli.Run("compile", "-b", fqbn, sketchPath.String(), "--library", manuallyInstalledLibPath.String(), "-v")
110+
require.NoError(t, err)
111+
cliInstalledLibPath := cli.SketchbookDir().Join("libraries", "WiFi101")
112+
expectedOutput := [3]string{
113+
"Multiple libraries were found for \"WiFi101.h\"",
114+
" Used: " + manuallyInstalledLibPath.String(),
115+
" Not used: " + cliInstalledLibPath.String(),
116+
}
117+
require.Contains(t, string(stdout), expectedOutput[0]+"\n"+expectedOutput[1]+"\n"+expectedOutput[2]+"\n")
118+
}

test/test_compile_part_4.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,44 +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_compile_with_library_priority(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 = "CompileSketchWithLibraryPriority"
59-
sketch_path = Path(data_dir, sketch_name)
60-
fqbn = "arduino:avr:uno"
61-
62-
# Manually installs a library
63-
git_url = "https://github.com/arduino-libraries/WiFi101.git"
64-
manually_install_lib_path = Path(data_dir, "my-libraries", "WiFi101")
65-
assert Repo.clone_from(git_url, manually_install_lib_path, multi_options=["-b 0.16.1"])
66-
67-
# Install the same library we installed manually
68-
assert run_command(["lib", "install", "WiFi101"])
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-
res = run_command(["compile", "-b", fqbn, sketch_path, "--library", manually_install_lib_path, "-v"])
81-
assert res.ok
82-
cli_installed_lib_path = Path(data_dir, "libraries", "WiFi101")
83-
expected_output = [
84-
'Multiple libraries were found for "WiFi101.h"',
85-
f" Used: {manually_install_lib_path}",
86-
f" Not used: {cli_installed_lib_path}",
87-
]
88-
assert "\n".join(expected_output) in res.stdout
89-
90-
9153
def test_recompile_with_different_library(run_command, data_dir):
9254
assert run_command(["update"])
9355

0 commit comments

Comments
 (0)