Skip to content

Commit 9b116b3

Browse files
Migrate TestUploadSketchWithPdeExtension from test_upload.py to upload_test.go
1 parent 16a164a commit 9b116b3

File tree

2 files changed

+61
-49
lines changed

2 files changed

+61
-49
lines changed

internal/integrationtest/upload/upload_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/arduino/arduino-cli/internal/integrationtest"
27+
"github.com/arduino/go-paths-helper"
2728
"github.com/stretchr/testify/require"
2829
"go.bug.st/testifyjson/requirejson"
2930
)
@@ -340,3 +341,63 @@ func TestCompileAndUploadComboSketchWithPdeExtension(t *testing.T) {
340341
require.Contains(t, string(stderr), sketchFile.String())
341342
}
342343
}
344+
345+
func TestUploadSketchWithPdeExtension(t *testing.T) {
346+
if os.Getenv("CI") != "" {
347+
t.Skip("VMs have no serial ports")
348+
}
349+
350+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
351+
defer env.CleanUp()
352+
353+
_, _, err := cli.Run("update")
354+
require.NoError(t, err)
355+
356+
sketchName := "UploadPdeSketch"
357+
sketchPath := cli.SketchbookDir().Join(sketchName)
358+
359+
// Create a test sketch
360+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
361+
require.NoError(t, err)
362+
363+
// Renames sketch file to pde
364+
sketchFile := sketchPath.Join(sketchName + ".pde")
365+
require.NoError(t, sketchPath.Join(sketchName+".ino").Rename(sketchFile))
366+
367+
for _, board := range detectedBoards(t, cli) {
368+
// Install core
369+
_, _, err = cli.Run("core", "install", board.core)
370+
require.NoError(t, err)
371+
372+
// Compile sketch first
373+
stdout, _, err := cli.Run("compile", "--clean", "-b", board.fqbn, sketchPath.String(), "--format", "json")
374+
require.NoError(t, err)
375+
buildDir := requirejson.Parse(t, stdout).Query(".builder_result | .build_path").String()
376+
buildDir = strings.Trim(strings.ReplaceAll(buildDir, "\\\\", "\\"), "\"")
377+
378+
// Upload from sketch folder
379+
waitForBoard(t, cli)
380+
_, _, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, sketchPath.String())
381+
require.NoError(t, err)
382+
383+
// Upload from sketch file
384+
waitForBoard(t, cli)
385+
_, _, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, sketchFile.String())
386+
require.NoError(t, err)
387+
388+
waitForBoard(t, cli)
389+
_, stderr, err := cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-dir", buildDir)
390+
require.NoError(t, err)
391+
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:")
392+
393+
// Upload from binary file
394+
waitForBoard(t, cli)
395+
// We don't need a specific file when using the --input-file flag to upload since
396+
// it's just used to calculate the directory, so it's enough to get a random file
397+
// that's inside that directory
398+
binaryFile := paths.New(buildDir, sketchName+".pde.bin")
399+
_, stderr, err = cli.Run("upload", "-b", board.fqbn, "-p", board.address, "--input-file", binaryFile.String())
400+
require.NoError(t, err)
401+
require.Contains(t, string(stderr), "Sketches with .pde extension are deprecated, please rename the following files to .ino:")
402+
}
403+
}

test/test_upload.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,55 +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_sketch_with_pde_extension(run_command, data_dir, detected_boards, wait_for_board):
46-
assert run_command(["update"])
47-
48-
sketch_name = "UploadPdeSketch"
49-
sketch_path = Path(data_dir, sketch_name)
50-
51-
# Create a test sketch
52-
assert run_command(["sketch", "new", sketch_path])
53-
54-
# Renames sketch file to pde
55-
sketch_file = Path(sketch_path, f"{sketch_name}.ino").rename(sketch_path / f"{sketch_name}.pde")
56-
57-
for board in detected_boards:
58-
# Install core
59-
core = ":".join(board.fqbn.split(":")[:2])
60-
assert run_command(["core", "install", core])
61-
62-
# Compile sketch first
63-
res = run_command(["compile", "--clean", "-b", board.fqbn, sketch_path, "--format", "json"])
64-
assert res.ok
65-
data = json.loads(res.stdout)
66-
build_dir = Path(data["builder_result"]["build_path"])
67-
68-
# Upload from sketch folder
69-
wait_for_board()
70-
assert run_command(["upload", "-b", board.fqbn, "-p", board.address, sketch_path])
71-
72-
# Upload from sketch file
73-
wait_for_board()
74-
assert run_command(["upload", "-b", board.fqbn, "-p", board.address, sketch_file])
75-
76-
wait_for_board()
77-
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-dir", build_dir])
78-
assert (
79-
"Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr
80-
)
81-
82-
# Upload from binary file
83-
wait_for_board()
84-
# We don't need a specific file when using the --input-file flag to upload since
85-
# it's just used to calculate the directory, so it's enough to get a random file
86-
# that's inside that directory
87-
binary_file = next(build_dir.glob(f"{sketch_name}.pde.*"))
88-
res = run_command(["upload", "-b", board.fqbn, "-p", board.address, "--input-file", binary_file])
89-
assert (
90-
"Sketches with .pde extension are deprecated, please rename the following files to .ino:" not in res.stderr
91-
)
92-
93-
9445
def test_upload_with_input_dir_containing_multiple_binaries(run_command, data_dir, detected_boards, wait_for_board):
9546
# This tests verifies the behaviour outlined in this issue:
9647
# https://github.com/arduino/arduino-cli/issues/765#issuecomment-699678646

0 commit comments

Comments
 (0)