Skip to content

Commit 979f7a7

Browse files
Migrate TestCompileWithExportBinariesConfig from test_compile_part_2.py
to compile_part_2_test.go
1 parent 4478cdf commit 979f7a7

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

internal/integrationtest/compile/compile_part_2_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/arduino/arduino-cli/internal/integrationtest"
2525
"github.com/arduino/go-paths-helper"
2626
"github.com/stretchr/testify/require"
27+
"go.bug.st/testifyjson/requirejson"
2728
)
2829

2930
func TestCompileWithOutputDirFlag(t *testing.T) {
@@ -188,6 +189,56 @@ func TestCompileWithExportBinariesEnvVar(t *testing.T) {
188189
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
189190
}
190191

192+
func TestCompileWithExportBinariesConfig(t *testing.T) {
193+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
194+
defer env.CleanUp()
195+
196+
// Init the environment explicitly
197+
_, _, err := cli.Run("core", "update-index")
198+
require.NoError(t, err)
199+
200+
// Download latest AVR
201+
_, _, err = cli.Run("core", "install", "arduino:avr")
202+
require.NoError(t, err)
203+
204+
sketchName := "CompileWithExportBinariesEnvVar"
205+
sketchPath := cli.SketchbookDir().Join(sketchName)
206+
fqbn := "arduino:avr:uno"
207+
208+
// Create a test sketch
209+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
210+
require.NoError(t, err)
211+
212+
// Create settings with export binaries set to true
213+
envVar := cli.GetDefaultEnv()
214+
envVar["ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES"] = "true"
215+
_, _, err = cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".")
216+
require.NoError(t, err)
217+
218+
// Test if arduino-cli config file written in the previous run has the `always_export_binaries` flag set.
219+
stdout, _, err := cli.Run("config", "dump", "--format", "json")
220+
require.NoError(t, err)
221+
requirejson.Contains(t, stdout, `
222+
{
223+
"sketch": {
224+
"always_export_binaries": "true"
225+
}
226+
}`)
227+
228+
// Test compilation with export binaries env var set
229+
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String())
230+
require.NoError(t, err)
231+
require.DirExists(t, sketchPath.Join("build").String())
232+
233+
// Verifies binaries are exported when export binaries env var is set
234+
fqbn = strings.ReplaceAll(fqbn, ":", ".")
235+
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.eep").String())
236+
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.elf").String())
237+
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.hex").String())
238+
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.bin").String())
239+
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
240+
}
241+
191242
func TestCompileWithInvalidUrl(t *testing.T) {
192243
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
193244
defer env.CleanUp()

test/test_compile_part_2.py

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

2121

22-
def test_compile_with_export_binaries_config(run_command, data_dir, downloads_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 = "CompileWithExportBinariesConfig"
30-
sketch_path = Path(data_dir, sketch_name)
31-
fqbn = "arduino:avr:uno"
32-
33-
# Create a test sketch
34-
assert run_command(["sketch", "new", sketch_path])
35-
36-
# Create settings with export binaries set to true
37-
env = {
38-
"ARDUINO_DATA_DIR": data_dir,
39-
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
40-
"ARDUINO_SKETCHBOOK_DIR": data_dir,
41-
"ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES": "true",
42-
}
43-
assert run_command(["config", "init", "--dest-dir", "."], custom_env=env)
44-
45-
# Test compilation with export binaries env var set
46-
result = run_command(["compile", "-b", fqbn, sketch_path])
47-
assert result.ok
48-
assert Path(sketch_path, "build").exists()
49-
assert Path(sketch_path, "build").is_dir()
50-
51-
# Verifies binaries are exported when export binaries env var is set
52-
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.eep").exists()
53-
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.elf").exists()
54-
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.hex").exists()
55-
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.bin").exists()
56-
assert (sketch_path / "build" / fqbn.replace(":", ".") / f"{sketch_name}.ino.with_bootloader.hex").exists()
57-
58-
5922
def test_compile_with_custom_libraries(run_command, copy_sketch):
6023
# Creates config with additional URL to install necessary core
6124
url = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"

0 commit comments

Comments
 (0)