Skip to content

Commit

Permalink
Fixed FQBN selection logic in monitor/arg command
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Oct 7, 2024
1 parent 776736a commit 2194a37
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions internal/cli/arguments/fqbn.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (f *Fqbn) Set(fqbn string) {
// parameters provided by the user.
// This determine the FQBN based on:
// - the value of the FQBN flag if explicitly specified, otherwise
// - the FQBN of the selected profile if available, otherwise
// - the default FQBN value in sketch.yaml (`default_fqbn` key) if available, otherwise
// - it tries to autodetect the board connected to the given port flags
// If all above methods fails, it returns the empty string.
Expand All @@ -73,6 +74,9 @@ func (f *Fqbn) Set(fqbn string) {
// terminates the execution
func CalculateFQBNAndPort(ctx context.Context, portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultFQBN, defaultAddress, defaultProtocol string, profile *rpc.SketchProfile) (string, *rpc.Port) {
fqbn := fqbnArg.String()
if fqbn == "" {
fqbn = profile.GetFqbn()
}
if fqbn == "" {
fqbn = defaultFQBN
}
Expand Down
10 changes: 4 additions & 6 deletions internal/cli/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ func runMonitorCmd(

var inst *rpc.Instance
var profile *rpc.SketchProfile
if fqbnArg.String() == "" {
if profileArg.Get() == "" {
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, sketch.GetDefaultProfile().GetName(), sketchPath)
} else {
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, profileArg.Get(), sketchPath)
}
if profileArg.Get() == "" {
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, sketch.GetDefaultProfile().GetName(), sketchPath)
} else {
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, profileArg.Get(), sketchPath)
}
if inst == nil {
inst = instance.CreateAndInit(ctx, srv)
Expand Down
24 changes: 24 additions & 0 deletions internal/integrationtest/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,29 @@ yun.serial.disableDTR=true
require.Contains(t, string(stdout), "Configuration parity = none")
require.Contains(t, string(stdout), "Configuration stop_bits = 1")
})

t.Run("WithFQBN", func(t *testing.T) {
stdout, _, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-b", "arduino:avr:yun", "-m", "uno", "--raw", sketchWithPortAndConfigAndProfile)
require.NoError(t, err)
require.Contains(t, string(stdout), "Opened port: /dev/ttyPROF")
require.Contains(t, string(stdout), "Configuration rts = on") // This is taken from profile-installed AVR core (not patched by this test)
require.Contains(t, string(stdout), "Configuration dtr = on")
require.Contains(t, string(stdout), "Configuration baudrate = 19200")
require.Contains(t, string(stdout), "Configuration bits = 8")
require.Contains(t, string(stdout), "Configuration parity = none")
require.Contains(t, string(stdout), "Configuration stop_bits = 1")
})

t.Run("WithConfigFlag", func(t *testing.T) {
stdout, _, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-c", "odd", "-m", "uno", "--raw", sketchWithPortAndConfigAndProfile)
require.NoError(t, err)
require.Contains(t, string(stdout), "Opened port: /dev/ttyPROF")
require.Contains(t, string(stdout), "Configuration rts = on") // This is taken from profile-installed AVR core (not patched by this test)
require.Contains(t, string(stdout), "Configuration dtr = on")
require.Contains(t, string(stdout), "Configuration baudrate = 19200")
require.Contains(t, string(stdout), "Configuration bits = 8")
require.Contains(t, string(stdout), "Configuration parity = odd")
require.Contains(t, string(stdout), "Configuration stop_bits = 1")
})
})
}

0 comments on commit 2194a37

Please sign in to comment.