Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
44981a2
Migrate TestCompileWithLibrary from test_compile_part_4.py to compile…
MatteoPologruto Sep 30, 2022
c6ea437
Migrate TestCompileWithLibraryPriority from test_compile_part_4.py to…
MatteoPologruto Sep 30, 2022
560baa3
Migrate TestRecompileWithDifferentLibrary from test_compile_part_4.py…
MatteoPologruto Sep 30, 2022
266723e
Migrate TestCompileWithConflictingLibrariesInclude from test_compile_…
MatteoPologruto Sep 30, 2022
28d1020
Migrate TestCompileWithInvalidBuildOptionJson from test_compile_part_…
MatteoPologruto Sep 30, 2022
e072c98
Migrate TestCompileWithEsp32BundledLibraries from test_compile_part_4…
MatteoPologruto Sep 30, 2022
9ca8a7b
Migrate TestCompileWithEsp8266BundledLibraries from test_compile_part…
MatteoPologruto Sep 30, 2022
116bfd9
Migrate TestGenerateCompileCommandsJsonResilience from test_compile_p…
MatteoPologruto Sep 30, 2022
53fb571
Migrate TestCompileSketchWithTppFileInclude from test_compile_part_4.…
MatteoPologruto Sep 30, 2022
bfacc80
Migrate TestCompileSketchWithIppFileInclude from test_compile_part_4.…
MatteoPologruto Sep 30, 2022
34b9f78
Migrate TestCompileWithoutUploadAndFqbn from test_compile_part_4.py t…
MatteoPologruto Sep 30, 2022
2b2f491
Migrate TestCompileNonInstalledPlatformWithWrongPackagerAndArch from …
MatteoPologruto Sep 30, 2022
79961f1
Migrate TestCompileWithKnownPlatformNotInstalled from test_compile_pa…
MatteoPologruto Sep 30, 2022
0e32825
Migrate TestCompileManuallyInstalledPlatformUsingBoardsLocalTxt from …
MatteoPologruto Oct 5, 2022
9cc05ac
Migrate TestCompileWithRelativeBuildPath from test_compile_part_4.py …
MatteoPologruto Oct 5, 2022
d145c30
Migrate TestCompileWithFakeSecureBootCore to compile_part_4_test.go a…
MatteoPologruto Oct 6, 2022
517a54e
Rearrange compile tests to share the same environment
MatteoPologruto Oct 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate TestRecompileWithDifferentLibrary from test_compile_part_4.py…
… to compile_part_4_test.go
  • Loading branch information
MatteoPologruto committed Nov 10, 2022
commit 560baa36a1120f4f9903fd901bf421165a75cc7c
62 changes: 62 additions & 0 deletions internal/integrationtest/compile/compile_part_4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
package compile_test

import (
"crypto/md5"
"encoding/hex"
"strings"
"testing"

"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
Expand Down Expand Up @@ -112,3 +116,61 @@ func TestCompileWithLibraryPriority(t *testing.T) {
}
require.Contains(t, string(stdout), expectedOutput[0]+"\n"+expectedOutput[1]+"\n"+expectedOutput[2]+"\n")
}

func TestRecompileWithDifferentLibrary(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("update")
require.NoError(t, err)

_, _, err = cli.Run("core", "install", "arduino:avr@1.8.3")
require.NoError(t, err)

sketchName := "RecompileCompileSketchWithDifferentLibrary"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"

// Install library
_, _, err = cli.Run("lib", "install", "WiFi101")
require.NoError(t, err)

// Manually installs a library
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
manuallyInstalledLibPath := cli.SketchbookDir().Join("my-libraries", "WiFi101")
_, err = git.PlainClone(manuallyInstalledLibPath.String(), false, &git.CloneOptions{
URL: gitUrl,
ReferenceName: plumbing.NewTagReferenceName("0.16.1"),
})
require.NoError(t, err)

// Create new sketch and add library include
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
sketchFile := sketchPath.Join(sketchName + ".ino")
lines, err := sketchFile.ReadFileAsLines()
require.NoError(t, err)
lines = append([]string{"#include <WiFi101.h>\n"}, lines...)
var data []byte
for _, l := range lines {
data = append(data, []byte(l)...)
}
err = sketchFile.WriteFile(data)
require.NoError(t, err)

md5 := md5.Sum(([]byte(sketchPath.String())))
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
require.NotEmpty(t, sketchPathMd5)
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)

// Compile sketch using library not managed by CLI
stdout, _, err := cli.Run("compile", "-b", fqbn, "--library", manuallyInstalledLibPath.String(), sketchPath.String(), "-v")
require.NoError(t, err)
objPath := buildDir.Join("libraries", "WiFi101", "WiFi.cpp.o")
require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String())

// Compile again using library installed from CLI
stdout, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "-v")
require.NoError(t, err)
require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String())
}
43 changes: 0 additions & 43 deletions test/test_compile_part_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,49 +50,6 @@ def test_compile_manually_installed_platform_using_boards_local_txt(run_command,
assert run_command(["compile", "--clean", "-b", fqbn, sketch_path])


def test_recompile_with_different_library(run_command, data_dir):
assert run_command(["update"])

assert run_command(["core", "install", "arduino:avr@1.8.3"])

sketch_name = "RecompileCompileSketchWithDifferentLibrary"
sketch_path = Path(data_dir, sketch_name)
fqbn = "arduino:avr:uno"

# Install library
assert run_command(["lib", "install", "WiFi101"])

# Manually installs the same library already installed
git_url = "https://github.com/arduino-libraries/WiFi101.git"
manually_install_lib_path = Path(data_dir, "my-libraries", "WiFi101")
assert Repo.clone_from(git_url, manually_install_lib_path, multi_options=["-b 0.16.1"])

# Create new sketch and add library include
assert run_command(["sketch", "new", sketch_path])
sketch_file = sketch_path / f"{sketch_name}.ino"
lines = []
with open(sketch_file, "r") as f:
lines = f.readlines()
lines = ["#include <WiFi101.h>"] + lines
with open(sketch_file, "w") as f:
f.writelines(lines)

sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")

# Compile sketch using library not managed by CLI
res = run_command(["compile", "-b", fqbn, "--library", manually_install_lib_path, sketch_path, "-v"])
assert res.ok
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
assert f"Using previously compiled file: {obj_path}" not in res.stdout

# Compile again using library installed from CLI
res = run_command(["compile", "-b", fqbn, sketch_path, "-v"])
assert res.ok
obj_path = build_dir / "libraries" / "WiFi101" / "WiFi.cpp.o"
assert f"Using previously compiled file: {obj_path}" not in res.stdout


def test_compile_with_conflicting_libraries_include(run_command, data_dir, copy_sketch):
assert run_command(["update"])

Expand Down