Skip to content

Commit 79b6ce8

Browse files
Migrate TestCompileWithOutputDirFlag from test_compile_part_2.py to compile_part_2_test.go
1 parent e404a3b commit 79b6ce8

File tree

2 files changed

+73
-40
lines changed

2 files changed

+73
-40
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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_part_1_test
17+
18+
import (
19+
"crypto/md5"
20+
"encoding/hex"
21+
"strings"
22+
"testing"
23+
24+
"github.com/arduino/arduino-cli/internal/integrationtest"
25+
"github.com/arduino/go-paths-helper"
26+
"github.com/stretchr/testify/require"
27+
)
28+
29+
func TestCompileWithOutputDirFlag(t *testing.T) {
30+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
31+
defer env.CleanUp()
32+
33+
// Init the environment explicitly
34+
_, _, err := cli.Run("core", "update-index")
35+
require.NoError(t, err)
36+
37+
// Download latest AVR
38+
_, _, err = cli.Run("core", "install", "arduino:avr")
39+
require.NoError(t, err)
40+
41+
sketchName := "CompileWithOutputDir"
42+
sketchPath := cli.SketchbookDir().Join(sketchName)
43+
fqbn := "arduino:avr:uno"
44+
45+
// Create a test sketch
46+
stdout, _, err := cli.Run("sketch", "new", sketchPath.String())
47+
require.NoError(t, err)
48+
require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String())
49+
50+
// Test the --output-dir flag with absolute path
51+
outputDir := cli.SketchbookDir().Join("test_dir", "output_dir")
52+
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--output-dir", outputDir.String())
53+
require.NoError(t, err)
54+
55+
// Verifies expected binaries have been built
56+
md5 := md5.Sum(([]byte(sketchPath.String())))
57+
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
58+
require.NotEmpty(t, sketchPathMd5)
59+
buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5)
60+
require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String())
61+
require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String())
62+
require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String())
63+
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
64+
require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
65+
66+
// Verifies binaries are exported when --output-dir flag is specified
67+
require.DirExists(t, outputDir.String())
68+
require.FileExists(t, outputDir.Join(sketchName+".ino.eep").String())
69+
require.FileExists(t, outputDir.Join(sketchName+".ino.elf").String())
70+
require.FileExists(t, outputDir.Join(sketchName+".ino.hex").String())
71+
require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.bin").String())
72+
require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.hex").String())
73+
}

test/test_compile_part_2.py

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

2121

22-
def test_compile_with_output_dir_flag(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 = "CompileWithOutputDir"
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 --output-dir flag with absolute path
39-
output_dir = Path(data_dir, "test_dir", "output_dir")
40-
result = run_command(["compile", "-b", fqbn, sketch_path, "--output-dir", output_dir])
41-
assert result.ok
42-
43-
# Verifies expected binaries have been built
44-
sketch_path_md5 = hashlib.md5(bytes(sketch_path)).hexdigest().upper()
45-
build_dir = Path(tempfile.gettempdir(), f"arduino-sketch-{sketch_path_md5}")
46-
assert (build_dir / f"{sketch_name}.ino.eep").exists()
47-
assert (build_dir / f"{sketch_name}.ino.elf").exists()
48-
assert (build_dir / f"{sketch_name}.ino.hex").exists()
49-
assert (build_dir / f"{sketch_name}.ino.with_bootloader.bin").exists()
50-
assert (build_dir / f"{sketch_name}.ino.with_bootloader.hex").exists()
51-
52-
# Verifies binaries are exported when --output-dir flag is specified
53-
assert output_dir.exists()
54-
assert output_dir.is_dir()
55-
assert (output_dir / f"{sketch_name}.ino.eep").exists()
56-
assert (output_dir / f"{sketch_name}.ino.elf").exists()
57-
assert (output_dir / f"{sketch_name}.ino.hex").exists()
58-
assert (output_dir / f"{sketch_name}.ino.with_bootloader.bin").exists()
59-
assert (output_dir / f"{sketch_name}.ino.with_bootloader.hex").exists()
60-
61-
6222
def test_compile_with_export_binaries_flag(run_command, data_dir):
6323
# Init the environment explicitly
6424
run_command(["core", "update-index"])

0 commit comments

Comments
 (0)