Skip to content

Commit a84b98c

Browse files
Migrate TestUploadWithInputDirContainingMultipleBinaries from test_upload.py to upload_test.go
1 parent 74574c5 commit a84b98c

File tree

2 files changed

+59
-59
lines changed

2 files changed

+59
-59
lines changed

internal/integrationtest/upload/upload_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,62 @@ func TestUploadSketchWithPdeExtension(t *testing.T) {
401401
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:")
402402
}
403403
}
404+
405+
func TestUploadWithInputDirContainingMultipleBinaries(t *testing.T) {
406+
if os.Getenv("CI") != "" {
407+
t.Skip("VMs have no serial ports")
408+
}
409+
410+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
411+
defer env.CleanUp()
412+
413+
// This tests verifies the behaviour outlined in this issue:
414+
// https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646
415+
_, _, err := cli.Run("update")
416+
require.NoError(t, err)
417+
418+
// Create two different sketches
419+
sketchOneName := "UploadMultipleBinariesSketchOne"
420+
sketchOnePath := cli.SketchbookDir().Join(sketchOneName)
421+
_, _, err = cli.Run("sketch", "new", sketchOnePath.String())
422+
require.NoError(t, err)
423+
424+
sketchTwoName := "UploadMultipleBinariesSketchTwo"
425+
sketchTwoPath := cli.SketchbookDir().Join(sketchTwoName)
426+
_, _, err = cli.Run("sketch", "new", sketchTwoPath.String())
427+
require.NoError(t, err)
428+
429+
for _, board := range detectedBoards(t, cli) {
430+
// Install core
431+
_, _, err = cli.Run("core", "install", board.core)
432+
require.NoError(t, err)
433+
434+
// Compile both sketches and copy binaries in the same build directory
435+
binariesDir := cli.SketchbookDir().Join("build", "BuiltBinaries")
436+
_, _, err = cli.Run("compile", "--clean", "-b", board.fqbn, sketchOnePath.String(), "--build-path", binariesDir.String())
437+
require.NoError(t, err)
438+
stdout, _, err := cli.Run("compile", "--clean", "-b", board.fqbn, sketchTwoPath.String(), "--format", "json")
439+
require.NoError(t, err)
440+
buildDirTwo := requirejson.Parse(t, stdout).Query(".builder_result | .build_path").String()
441+
buildDirTwo = strings.Trim(strings.ReplaceAll(buildDirTwo, "\\\\", "\\"), "\"")
442+
require.NoError(t, paths.New(buildDirTwo).Join(sketchTwoName+".ino.bin").CopyTo(binariesDir.Join(sketchTwoName+".ino.bin")))
443+
444+
waitForBoard(t, cli)
445+
// Verifies upload fails because multiple binaries are found
446+
_, stderr, err := cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binariesDir.String())
447+
require.Error(t, err)
448+
require.Contains(t, string(stderr), "Error during Upload: ")
449+
require.Contains(t, string(stderr), "Error finding build artifacts: ")
450+
require.Contains(t, string(stderr), "autodetect build artifact: ")
451+
require.Contains(t, string(stderr), "multiple build artifacts found:")
452+
453+
// Copy binaries to folder with same name of a sketch
454+
binariesDirSketch := cli.SketchbookDir().Join("build", "UploadMultipleBinariesSketchOne")
455+
require.NoError(t, binariesDir.CopyDirTo(binariesDirSketch))
456+
457+
waitForBoard(t, cli)
458+
// Verifies upload is successful using the binaries with the same name of the containing folder
459+
_, _, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binariesDirSketch.String())
460+
require.NoError(t, err)
461+
}
462+
}

test/test_upload.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -42,65 +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_upload_with_input_dir_containing_multiple_binaries(run_command, data_dir, detected_boards, wait_for_board):
46-
# This tests verifies the behaviour outlined in this issue:
47-
# https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646
48-
assert run_command(["update"])
49-
50-
# Create a two different sketches
51-
sketch_one_name = "UploadMultipleBinariesSketchOne"
52-
sketch_one_path = Path(data_dir, sketch_one_name)
53-
assert run_command(["sketch", "new", sketch_one_path])
54-
55-
sketch_two_name = "UploadMultipleBinariesSketchTwo"
56-
sketch_two_path = Path(data_dir, sketch_two_name)
57-
assert run_command(["sketch", "new", sketch_two_path])
58-
59-
for board in detected_boards:
60-
# Install core
61-
core = ":".join(board.fqbn.split(":")[:2])
62-
assert run_command(["core", "install", core])
63-
64-
# Compile both sketches and copy binaries in the same directory same build directory
65-
res = run_command(["compile", "--clean", "-b", board.fqbn, sketch_one_path, "--format", "json"])
66-
assert res.ok
67-
data = json.loads(res.stdout)
68-
build_dir_one = Path(data["builder_result"]["build_path"])
69-
res = run_command(["compile", "--clean", "-b", board.fqbn, sketch_two_path, "--format", "json"])
70-
assert res.ok
71-
data = json.loads(res.stdout)
72-
build_dir_two = Path(data["builder_result"]["build_path"])
73-
74-
# Copy binaries to same folder
75-
binaries_dir = Path(data_dir, "build", "BuiltBinaries")
76-
shutil.copytree(build_dir_one, binaries_dir, dirs_exist_ok=True)
77-
shutil.copytree(build_dir_two, binaries_dir, dirs_exist_ok=True)
78-
79-
wait_for_board()
80-
# Verifies upload fails because multiple binaries are found
81-
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binaries_dir])
82-
assert res.failed
83-
assert (
84-
"Error during Upload: "
85-
+ "Error finding build artifacts: "
86-
+ "autodetect build artifact: "
87-
+ "multiple build artifacts found:"
88-
in res.stderr
89-
)
90-
91-
# Copy binaries to folder with same name of a sketch
92-
binaries_dir = Path(data_dir, "build", "UploadMultipleBinariesSketchOne")
93-
shutil.copytree(build_dir_one, binaries_dir, dirs_exist_ok=True)
94-
shutil.copytree(build_dir_two, binaries_dir, dirs_exist_ok=True)
95-
96-
wait_for_board()
97-
# Verifies upload is successful using the binaries with the same name of the containing folder
98-
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-dir", binaries_dir])
99-
assert (
100-
"Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr
101-
)
102-
103-
10445
def test_compile_and_upload_combo_sketch_with_mismatched_casing(run_command, data_dir, detected_boards, wait_for_board):
10546
assert run_command(["update"])
10647

0 commit comments

Comments
 (0)