Skip to content

Commit 870a48f

Browse files
authored
Fixed nil pointer excpetion in upload (#2548)
1 parent 65fb6e5 commit 870a48f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Diff for: commands/upload/upload.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
150150
if programmer == "" && pme.GetProfile() != nil {
151151
programmer = pme.GetProfile().Programmer
152152
}
153-
if programmer == "" {
153+
if programmer == "" && sk != nil {
154154
programmer = sk.GetDefaultProgrammer()
155155
}
156156

Diff for: internal/integrationtest/upload_mock/upload_mock_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,44 @@ func generateBuildDir(sketchPath *paths.Path, t *testing.T) *paths.Path {
726726
require.NoError(t, buildDir.ToAbs())
727727
return buildDir
728728
}
729+
730+
func TestUploadWithInputDirFlag(t *testing.T) {
731+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
732+
defer env.CleanUp()
733+
734+
_, _, err := cli.Run("core", "install", "arduino:mbed_opta")
735+
require.NoError(t, err)
736+
737+
sketchPath := cli.SketchbookDir().Join("TestSketchForUpload")
738+
_, _, err = cli.Run("sketch", "new", sketchPath.String())
739+
require.NoError(t, err)
740+
741+
// Create a fake build directory
742+
buildDir := sketchPath.Join("build")
743+
require.NoError(t, buildDir.MkdirAll())
744+
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.bin").WriteFile(nil))
745+
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.elf").WriteFile(nil))
746+
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.hex").WriteFile(nil))
747+
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.map").WriteFile(nil))
748+
749+
// Test with input-dir flag
750+
_, _, err = cli.Run(
751+
"upload",
752+
"-b", "arduino:mbed_opta:opta",
753+
"-i", buildDir.String(),
754+
"-t",
755+
"-p", "/dev/ttyACM0",
756+
"--dry-run", "-v",
757+
sketchPath.String())
758+
require.NoError(t, err)
759+
760+
// Test with input-dir flag and no sketch
761+
_, _, err = cli.Run(
762+
"upload",
763+
"-b", "arduino:mbed_opta:opta",
764+
"-i", buildDir.String(),
765+
"-t",
766+
"-p", "/dev/ttyACM0",
767+
"--dry-run", "-v")
768+
require.NoError(t, err)
769+
}

0 commit comments

Comments
 (0)