Skip to content

Commit c6ea437

Browse files
Migrate TestCompileWithLibraryPriority from test_compile_part_4.py to compile_part_4_test.go
1 parent 44981a2 commit c6ea437

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

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)