Skip to content

Commit 6814a08

Browse files
Migrate TestCompileWithCustomBuildPath from test_compile_part_2.py to compile_part_2_test.go
1 parent dfa14ee commit 6814a08

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

internal/integrationtest/compile/compile_part_2_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compile_part_1_test
1818
import (
1919
"crypto/md5"
2020
"encoding/hex"
21+
"fmt"
2122
"strings"
2223
"testing"
2324

@@ -105,3 +106,49 @@ func TestCompileWithExportBinariesFlag(t *testing.T) {
105106
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
106107
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
107108
}
109+
110+
func TestCompileWithCustomBuildPath(t *testing.T) {
111+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
112+
defer env.CleanUp()
113+
114+
// Init the environment explicitly
115+
_, _, err := cli.Run("core", "update-index")
116+
require.NoError(t, err)
117+
118+
// Download latest AVR
119+
_, _, err = cli.Run("core", "install", "arduino:avr")
120+
require.NoError(t, err)
121+
122+
sketchName := "CompileWithBuildPath"
123+
sketchPath := cli.SketchbookDir().Join(sketchName)
124+
fqbn := "arduino:avr:uno"
125+
126+
// Create a test sketch
127+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
128+
require.NoError(t, err)
129+
130+
// Test the --build-path flag with absolute path
131+
buildPath := cli.DataDir().Join("test_dir", "build_dir")
132+
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String(), "--build-path", buildPath.String())
133+
fmt.Print(stderr)
134+
require.NoError(t, err)
135+
136+
// Verifies expected binaries have been built to build_path
137+
require.DirExists(t, buildPath.String())
138+
require.FileExists(t, buildPath.Join(sketchName+".ino.eep").String())
139+
require.FileExists(t, buildPath.Join(sketchName+".ino.elf").String())
140+
require.FileExists(t, buildPath.Join(sketchName+".ino.hex").String())
141+
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.bin").String())
142+
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.hex").String())
143+
144+
// Verifies there are no binaries in temp directory
145+
md5 := md5.Sum(([]byte(sketchPath.String())))
146+
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
147+
require.NotEmpty(t, sketchPathMd5)
148+
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
149+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String())
150+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String())
151+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String())
152+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
153+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
154+
}

test/test_compile_part_2.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,6 @@
1919
import simplejson as json
2020

2121

22-
def test_compile_with_custom_build_path(run_command, data_dir):
23-
# Init the environment explicitly
24-
run_command(["core", "update-index"])
25-
26-
# Download latest AVR
27-
run_command(["core", "install", "arduino:avr"])
28-
29-
sketch_name = "CompileWithBuildPath"
30-
sketch_path = Path(data_dir, sketch_name)
31-
fqbn = "arduino:avr:uno"
32-
33-
# Create a test sketch
34-
result = run_command(["sketch", "new", sketch_path])
35-
assert result.ok
36-
assert f"Sketch created in: {sketch_path}" in result.stdout
37-
38-
# Test the --build-path flag with absolute path
39-
build_path = Path(data_dir, "test_dir", "build_dir")
40-
result = run_command(["compile", "-b", fqbn, sketch_path, "--build-path", build_path])
41-
print(result.stderr)
42-
assert result.ok
43-
44-
# Verifies expected binaries have been built to build_path
45-
assert build_path.exists()
46-
assert build_path.is_dir()
47-
assert (build_path / f"{sketch_name}.ino.eep").exists()
48-
assert (build_path / f"{sketch_name}.ino.elf").exists()
49-
assert (build_path / f"{sketch_name}.ino.hex").exists()
50-
assert (build_path / f"{sketch_name}.ino.with_bootloader.bin").exists()
51-
assert (build_path / f"{sketch_name}.ino.with_bootloader.hex").exists()
52-
53-
# Verifies there are no binaries in temp directory
54-
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
55-
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
56-
assert not (build_dir / f"{sketch_name}.ino.eep").exists()
57-
assert not (build_dir / f"{sketch_name}.ino.elf").exists()
58-
assert not (build_dir / f"{sketch_name}.ino.hex").exists()
59-
assert not (build_dir / f"{sketch_name}.ino.with_bootloader.bin").exists()
60-
assert not (build_dir / f"{sketch_name}.ino.with_bootloader.hex").exists()
61-
62-
6322
def test_compile_with_export_binaries_env_var(run_command, data_dir, downloads_dir):
6423
# Init the environment explicitly
6524
run_command(["core", "update-index"])

0 commit comments

Comments
 (0)