diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 487840c46aa..fcc248ce3b9 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -150,7 +150,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er if programmer == "" && pme.GetProfile() != nil { programmer = pme.GetProfile().Programmer } - if programmer == "" { + if programmer == "" && sk != nil { programmer = sk.GetDefaultProgrammer() } diff --git a/internal/integrationtest/upload_mock/upload_mock_test.go b/internal/integrationtest/upload_mock/upload_mock_test.go index c41f9db2f7d..330358bb1ba 100644 --- a/internal/integrationtest/upload_mock/upload_mock_test.go +++ b/internal/integrationtest/upload_mock/upload_mock_test.go @@ -726,3 +726,44 @@ func generateBuildDir(sketchPath *paths.Path, t *testing.T) *paths.Path { require.NoError(t, buildDir.ToAbs()) return buildDir } + +func TestUploadWithInputDirFlag(t *testing.T) { + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) + defer env.CleanUp() + + _, _, err := cli.Run("core", "install", "arduino:mbed_opta") + require.NoError(t, err) + + sketchPath := cli.SketchbookDir().Join("TestSketchForUpload") + _, _, err = cli.Run("sketch", "new", sketchPath.String()) + require.NoError(t, err) + + // Create a fake build directory + buildDir := sketchPath.Join("build") + require.NoError(t, buildDir.MkdirAll()) + require.NoError(t, buildDir.Join("TestSketchForUpload.ino.bin").WriteFile(nil)) + require.NoError(t, buildDir.Join("TestSketchForUpload.ino.elf").WriteFile(nil)) + require.NoError(t, buildDir.Join("TestSketchForUpload.ino.hex").WriteFile(nil)) + require.NoError(t, buildDir.Join("TestSketchForUpload.ino.map").WriteFile(nil)) + + // Test with input-dir flag + _, _, err = cli.Run( + "upload", + "-b", "arduino:mbed_opta:opta", + "-i", buildDir.String(), + "-t", + "-p", "/dev/ttyACM0", + "--dry-run", "-v", + sketchPath.String()) + require.NoError(t, err) + + // Test with input-dir flag and no sketch + _, _, err = cli.Run( + "upload", + "-b", "arduino:mbed_opta:opta", + "-i", buildDir.String(), + "-t", + "-p", "/dev/ttyACM0", + "--dry-run", "-v") + require.NoError(t, err) +}