Commit b65df52c authored by Cristian Maglie's avatar Cristian Maglie

debug: Enforce programmer selection (#2394)

* debug: Enforce programmer selection

* Fixed unit tests

* Increase code coverage
parent c1db8cb6
......@@ -108,14 +108,15 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl
}
}
if req.GetProgrammer() != "" {
if p, ok := platformRelease.Programmers[req.GetProgrammer()]; ok {
toolProperties.Merge(p.Properties)
} else if refP, ok := referencedPlatformRelease.Programmers[req.GetProgrammer()]; ok {
toolProperties.Merge(refP.Properties)
} else {
return nil, &arduino.ProgrammerNotFoundError{Programmer: req.GetProgrammer()}
}
if req.GetProgrammer() == "" {
return nil, &arduino.MissingProgrammerError{}
}
if p, ok := platformRelease.Programmers[req.GetProgrammer()]; ok {
toolProperties.Merge(p.Properties)
} else if refP, ok := referencedPlatformRelease.Programmers[req.GetProgrammer()]; ok {
toolProperties.Merge(refP.Properties)
} else {
return nil, &arduino.ProgrammerNotFoundError{Programmer: req.GetProgrammer()}
}
var importPath *paths.Path
......
......@@ -63,6 +63,21 @@ func TestGetCommandLine(t *testing.T) {
pm := pmb.Build()
pme, release := pm.NewExplorer()
defer release()
{
// Check programmer required
_, err := getCommandLine(req, pme)
require.Error(t, err)
}
{
// Check programmer not found
req.Programmer = "not-existent"
_, err := getCommandLine(req, pme)
require.Error(t, err)
}
req.Programmer = "edbg"
command, err := getCommandLine(req, pme)
require.Nil(t, err)
commandToTest := strings.Join(command, " ")
......@@ -76,6 +91,7 @@ func TestGetCommandLine(t *testing.T) {
SketchPath: sketchPath.String(),
Interpreter: "mi1",
ImportDir: sketchPath.Join("build", "arduino-test.samd.mkr1000").String(),
Programmer: "edbg",
}
goldCommand2 := fmt.Sprintf("%s/arduino-test/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb%s", dataDir, toolExtension) +
......
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