Skip to content

Commit 1b0148c

Browse files
Migrated TestCompileWithSimpleSketch from test_compile_part_1.py to compile_part_1_test.go
1 parent abcf8dc commit 1b0148c

File tree

2 files changed

+59
-46
lines changed

2 files changed

+59
-46
lines changed

internal/integrationtest/compile/compile_part_1_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
package compile_part_1_test
1717

1818
import (
19+
"crypto/md5"
20+
"encoding/hex"
21+
"encoding/json"
22+
"strings"
1923
"testing"
2024

2125
"github.com/arduino/arduino-cli/internal/integrationtest"
@@ -84,3 +88,58 @@ func TestCompileErrorMessage(t *testing.T) {
8488
require.Error(t, err)
8589
require.Contains(t, string(stderr), "main file missing from sketch:")
8690
}
91+
92+
func TestCompileWithSimpleSketch(t *testing.T) {
93+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
94+
defer env.CleanUp()
95+
96+
// Init the environment explicitly
97+
_, _, err := cli.Run("core", "update-index")
98+
require.NoError(t, err)
99+
100+
// Download latest AVR
101+
_, _, err = cli.Run("core", "install", "arduino:avr")
102+
require.NoError(t, err)
103+
104+
sketchName := "CompileIntegrationTest"
105+
sketchPath := cli.SketchbookDir().Join(sketchName)
106+
fqbn := "arduino:avr:uno"
107+
108+
// Create a test sketch
109+
stdout, _, err := cli.Run("sketch", "new", sketchPath.String())
110+
require.NoError(t, err)
111+
require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String())
112+
113+
// Build sketch for arduino:avr:uno
114+
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String())
115+
require.NoError(t, err)
116+
117+
// Build sketch for arduino:avr:uno with json output
118+
stdout, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--format", "json")
119+
require.NoError(t, err)
120+
// check is a valid json and contains requested data
121+
var compileOutput map[string]interface{}
122+
err = json.Unmarshal(stdout, &compileOutput)
123+
require.NoError(t, err)
124+
require.NotEmpty(t, compileOutput["compiler_out"])
125+
require.Empty(t, compileOutput["compiler_err"])
126+
127+
// Verifies expected binaries have been built
128+
md5 := md5.Sum(([]byte(sketchPath.String())))
129+
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
130+
require.NotEmpty(t, sketchPathMd5)
131+
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
132+
require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String())
133+
require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String())
134+
require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String())
135+
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
136+
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
137+
138+
// Verifies binaries are not exported by default to Sketch folder
139+
sketchBuildDir := sketchPath.Join("build" + strings.ReplaceAll(fqbn, ":", "."))
140+
require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.eep").String())
141+
require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.elf").String())
142+
require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.hex").String())
143+
require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.with_bootloader.bin").String())
144+
require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.with_bootloader.hex").String())
145+
}

test/test_compile_part_1.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,6 @@
2525
from .common import running_on_ci
2626

2727

28-
def test_compile_with_simple_sketch(run_command, data_dir, working_dir):
29-
# Init the environment explicitly
30-
run_command(["core", "update-index"])
31-
32-
# Download latest AVR
33-
run_command(["core", "install", "arduino:avr"])
34-
35-
sketch_name = "CompileIntegrationTest"
36-
sketch_path = Path(data_dir, sketch_name)
37-
fqbn = "arduino:avr:uno"
38-
39-
# Create a test sketch
40-
result = run_command(["sketch", "new", sketch_path])
41-
assert result.ok
42-
assert f"Sketch created in: {sketch_path}" in result.stdout
43-
44-
# Build sketch for arduino:avr:uno
45-
result = run_command(["compile", "-b", fqbn, sketch_path])
46-
assert result.ok
47-
48-
# Build sketch for arduino:avr:uno with json output
49-
result = run_command(["compile", "-b", fqbn, sketch_path, "--format", "json"])
50-
assert result.ok
51-
# check is a valid json and contains requested data
52-
compile_output = json.loads(result.stdout)
53-
assert compile_output["compiler_out"] != ""
54-
assert compile_output["compiler_err"] == ""
55-
56-
# Verifies expected binaries have been built
57-
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
58-
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
59-
assert (build_dir / f"{sketch_name}.ino.eep").exists()
60-
assert (build_dir / f"{sketch_name}.ino.elf").exists()
61-
assert (build_dir / f"{sketch_name}.ino.hex").exists()
62-
assert (build_dir / f"{sketch_name}.ino.with_bootloader.bin").exists()
63-
assert (build_dir / f"{sketch_name}.ino.with_bootloader.hex").exists()
64-
65-
# Verifies binaries are not exported by default to Sketch folder
66-
sketch_build_dir = Path(sketch_path, "build", fqbn.replace(":", "."))
67-
assert not (sketch_build_dir / f"{sketch_name}.ino.eep").exists()
68-
assert not (sketch_build_dir / f"{sketch_name}.ino.elf").exists()
69-
assert not (sketch_build_dir / f"{sketch_name}.ino.hex").exists()
70-
assert not (sketch_build_dir / f"{sketch_name}.ino.with_bootloader.bin").exists()
71-
assert not (sketch_build_dir / f"{sketch_name}.ino.with_bootloader.hex").exists()
72-
73-
7428
@pytest.mark.skipif(
7529
running_on_ci() and platform.system() == "Windows",
7630
reason="Test disabled on Github Actions Win VM until tmpdir inconsistent behavior bug is fixed",

0 commit comments

Comments
 (0)