Skip to content

Commit 2194a37

Browse files
committed
Fixed FQBN selection logic in monitor/arg command
1 parent 776736a commit 2194a37

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

internal/cli/arguments/fqbn.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (f *Fqbn) Set(fqbn string) {
6464
// parameters provided by the user.
6565
// This determine the FQBN based on:
6666
// - the value of the FQBN flag if explicitly specified, otherwise
67+
// - the FQBN of the selected profile if available, otherwise
6768
// - the default FQBN value in sketch.yaml (`default_fqbn` key) if available, otherwise
6869
// - it tries to autodetect the board connected to the given port flags
6970
// If all above methods fails, it returns the empty string.
@@ -73,6 +74,9 @@ func (f *Fqbn) Set(fqbn string) {
7374
// terminates the execution
7475
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) {
7576
fqbn := fqbnArg.String()
77+
if fqbn == "" {
78+
fqbn = profile.GetFqbn()
79+
}
7680
if fqbn == "" {
7781
fqbn = defaultFQBN
7882
}

internal/cli/monitor/monitor.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ func runMonitorCmd(
110110

111111
var inst *rpc.Instance
112112
var profile *rpc.SketchProfile
113-
if fqbnArg.String() == "" {
114-
if profileArg.Get() == "" {
115-
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, sketch.GetDefaultProfile().GetName(), sketchPath)
116-
} else {
117-
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, profileArg.Get(), sketchPath)
118-
}
113+
if profileArg.Get() == "" {
114+
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, sketch.GetDefaultProfile().GetName(), sketchPath)
115+
} else {
116+
inst, profile = instance.CreateAndInitWithProfile(ctx, srv, profileArg.Get(), sketchPath)
119117
}
120118
if inst == nil {
121119
inst = instance.CreateAndInit(ctx, srv)

internal/integrationtest/monitor/monitor_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,29 @@ yun.serial.disableDTR=true
394394
require.Contains(t, string(stdout), "Configuration parity = none")
395395
require.Contains(t, string(stdout), "Configuration stop_bits = 1")
396396
})
397+
398+
t.Run("WithFQBN", func(t *testing.T) {
399+
stdout, _, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-b", "arduino:avr:yun", "-m", "uno", "--raw", sketchWithPortAndConfigAndProfile)
400+
require.NoError(t, err)
401+
require.Contains(t, string(stdout), "Opened port: /dev/ttyPROF")
402+
require.Contains(t, string(stdout), "Configuration rts = on") // This is taken from profile-installed AVR core (not patched by this test)
403+
require.Contains(t, string(stdout), "Configuration dtr = on")
404+
require.Contains(t, string(stdout), "Configuration baudrate = 19200")
405+
require.Contains(t, string(stdout), "Configuration bits = 8")
406+
require.Contains(t, string(stdout), "Configuration parity = none")
407+
require.Contains(t, string(stdout), "Configuration stop_bits = 1")
408+
})
409+
410+
t.Run("WithConfigFlag", func(t *testing.T) {
411+
stdout, _, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-c", "odd", "-m", "uno", "--raw", sketchWithPortAndConfigAndProfile)
412+
require.NoError(t, err)
413+
require.Contains(t, string(stdout), "Opened port: /dev/ttyPROF")
414+
require.Contains(t, string(stdout), "Configuration rts = on") // This is taken from profile-installed AVR core (not patched by this test)
415+
require.Contains(t, string(stdout), "Configuration dtr = on")
416+
require.Contains(t, string(stdout), "Configuration baudrate = 19200")
417+
require.Contains(t, string(stdout), "Configuration bits = 8")
418+
require.Contains(t, string(stdout), "Configuration parity = odd")
419+
require.Contains(t, string(stdout), "Configuration stop_bits = 1")
420+
})
397421
})
398422
}

0 commit comments

Comments
 (0)