Skip to content

Commit 4d3e22e

Browse files
Migrate TestCompileAndUploadComboWithCustomBuildPath from test_upload.py to upload_test.go
1 parent 363fcc8 commit 4d3e22e

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

internal/integrationtest/upload/upload_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,50 @@ func TestCompileAndUploadCombo(t *testing.T) {
250250
runTest(sketchMainFile.String())
251251
}
252252
}
253+
254+
func TestCompileAndUploadComboWithCustomBuildPath(t *testing.T) {
255+
if os.Getenv("CI") != "" {
256+
t.Skip("VMs have no serial ports")
257+
}
258+
259+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
260+
defer env.CleanUp()
261+
262+
// Init the environment explicitly
263+
_, _, err := cli.Run("core", "update-index")
264+
require.NoError(t, err)
265+
266+
// Create a test sketch
267+
sketchName := "CompileAndUploadCustomBuildPathIntegrationTest"
268+
sketchPath := cli.SketchbookDir().Join(sketchName)
269+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
270+
require.NoError(t, err)
271+
272+
// Build sketch for each detected board
273+
for _, board := range detectedBoards(t, cli) {
274+
fqbnNormalized := strings.ReplaceAll(board.fqbn, ":", "-")
275+
logFileName := fqbnNormalized + "-compile.log"
276+
logFilePath := cli.SketchbookDir().Join(logFileName)
277+
278+
_, _, err = cli.Run("core", "install", board.core)
279+
require.NoError(t, err)
280+
281+
waitForBoard(t, cli)
282+
283+
buildPath := cli.SketchbookDir().Join("test_dir", fqbnNormalized, "build_dir")
284+
_, _, err := cli.Run("compile", "-b", board.fqbn, "--upload", "-p", board.address, "--build-path", buildPath.String(),
285+
sketchPath.String(), "--log-format", "json", "--log-file", logFilePath.String(), "--log-level", "trace")
286+
require.NoError(t, err)
287+
logJson, err := logFilePath.ReadFile()
288+
require.NoError(t, err)
289+
290+
// check from the logs if the bin file were uploaded on the current board
291+
logJson = []byte("[" + strings.ReplaceAll(strings.TrimSuffix(string(logJson), "\n"), "\n", ",") + "]")
292+
traces := requirejson.Parse(t, logJson).Query("[ .[] | select(.level==\"trace\") | .msg ]").String()
293+
traces = strings.ReplaceAll(traces, "\\\\", "\\")
294+
require.Contains(t, traces, "Compile "+sketchPath.String()+" for "+board.fqbn+" started")
295+
require.Contains(t, traces, "Compile "+sketchName+" for "+board.fqbn+" successful")
296+
require.Contains(t, traces, "Upload "+sketchPath.String()+" on "+board.fqbn+" started")
297+
require.Contains(t, traces, "Upload successful")
298+
}
299+
}

test/test_upload.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,53 +42,6 @@ def test_upload_after_attach(run_command, data_dir, detected_boards):
4242
assert run_command(["upload", sketch_path])
4343

4444

45-
def test_compile_and_upload_combo_with_custom_build_path(run_command, data_dir, detected_boards, wait_for_board):
46-
# Init the environment explicitly
47-
run_command(["core", "update-index"])
48-
49-
# Install required core(s)
50-
run_command(["core", "install", "arduino:avr@1.8.3"])
51-
run_command(["core", "install", "arduino:samd@1.8.6"])
52-
53-
sketch_name = "CompileAndUploadCustomBuildPathIntegrationTest"
54-
sketch_path = Path(data_dir, sketch_name)
55-
assert run_command(["sketch", "new", sketch_path])
56-
57-
for board in detected_boards:
58-
fqbn_normalized = board.fqbn.replace(":", "-")
59-
log_file_name = f"{fqbn_normalized}-compile.log"
60-
log_file = Path(data_dir, log_file_name)
61-
command_log_flags = ["--log-format", "json", "--log-file", log_file, "--log-level", "trace"]
62-
63-
wait_for_board()
64-
65-
build_path = Path(data_dir, "test_dir", fqbn_normalized, "build_dir")
66-
result = run_command(
67-
[
68-
"compile",
69-
"-b",
70-
board.fqbn,
71-
"--upload",
72-
"-p",
73-
board.address,
74-
"--build-path",
75-
build_path,
76-
sketch_path,
77-
]
78-
+ command_log_flags
79-
)
80-
print(result.stderr)
81-
assert result.ok
82-
83-
# check from the logs if the bin file were uploaded on the current board
84-
log_json = open(log_file, "r")
85-
traces = parse_json_traces(log_json.readlines())
86-
assert f"Compile {sketch_path} for {board.fqbn} started" in traces
87-
assert f"Compile {sketch_name} for {board.fqbn} successful" in traces
88-
assert f"Upload {sketch_path} on {board.fqbn} started" in traces
89-
assert "Upload successful" in traces
90-
91-
9245
def test_compile_and_upload_combo_sketch_with_pde_extension(run_command, data_dir, detected_boards, wait_for_board):
9346
assert run_command(["update"])
9447

0 commit comments

Comments
 (0)