Skip to content

Commit c18541f

Browse files
Migrate TestCompileWithLibrary from test_compile_part_4.py to compile_part_4_test.go
1 parent e53d2f5 commit c18541f

File tree

2 files changed

+66
-28
lines changed

2 files changed

+66
-28
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package compile_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/internal/integrationtest"
22+
"github.com/stretchr/testify/require"
23+
"gopkg.in/src-d/go-git.v4"
24+
"gopkg.in/src-d/go-git.v4/plumbing"
25+
)
26+
27+
func TestCompileWithLibrary(t *testing.T) {
28+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
29+
defer env.CleanUp()
30+
31+
_, _, err := cli.Run("update")
32+
require.NoError(t, err)
33+
34+
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
35+
require.NoError(t, err)
36+
37+
sketchName := "CompileSketchWithWiFi101Dependency"
38+
sketchPath := cli.SketchbookDir().Join(sketchName)
39+
fqbn := "arduino:avr:uno"
40+
// Create new sketch and add library include
41+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
42+
require.NoError(t, err)
43+
sketchFile := sketchPath.Join(sketchName + ".ino")
44+
lines, err := sketchFile.ReadFileAsLines()
45+
require.NoError(t, err)
46+
lines = append([]string{"#include <WiFi101.h>\n"}, lines...)
47+
var data []byte
48+
for _, l := range lines {
49+
data = append(data, []byte(l)...)
50+
}
51+
err = sketchFile.WriteFile(data)
52+
require.NoError(t, err)
53+
54+
// Manually installs a library
55+
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
56+
libPath := cli.SketchbookDir().Join("my-libraries", "WiFi101")
57+
_, err = git.PlainClone(libPath.String(), false, &git.CloneOptions{
58+
URL: gitUrl,
59+
ReferenceName: plumbing.NewTagReferenceName("0.16.1"),
60+
})
61+
require.NoError(t, err)
62+
63+
stdout, _, err := cli.Run("compile", "-b", fqbn, sketchPath.String(), "--library", libPath.String(), "-v")
64+
require.NoError(t, err)
65+
require.Contains(t, string(stdout), "WiFi101")
66+
}

test/test_compile_part_4.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +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(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 = "CompileSketchWithWiFi101Dependency"
59-
sketch_path = Path(data_dir, sketch_name)
60-
fqbn = "arduino:avr:uno"
61-
# Create new sketch and add library include
62-
assert run_command(["sketch", "new", sketch_path])
63-
sketch_file = sketch_path / f"{sketch_name}.ino"
64-
lines = []
65-
with open(sketch_file, "r") as f:
66-
lines = f.readlines()
67-
lines = ["#include <WiFi101.h>\n"] + lines
68-
with open(sketch_file, "w") as f:
69-
f.writelines(lines)
70-
71-
# Manually installs a library
72-
git_url = "https://github.com/arduino-libraries/WiFi101.git"
73-
lib_path = Path(data_dir, "my-libraries", "WiFi101")
74-
assert Repo.clone_from(git_url, lib_path, multi_options=["-b 0.16.1"])
75-
76-
res = run_command(["compile", "-b", fqbn, sketch_path, "--library", lib_path, "-v"])
77-
assert res.ok
78-
assert "WiFi101" in res.stdout
79-
80-
8153
def test_compile_with_library_priority(run_command, data_dir):
8254
assert run_command(["update"])
8355

0 commit comments

Comments
 (0)