Unverified Commit 870a48fc authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Fixed nil pointer excpetion in upload (#2548)

parent 65fb6e5e
......@@ -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()
}
......
......@@ -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)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment