Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
better handle some edge cases
  • Loading branch information
alessio-perugini committed Oct 24, 2023
commit 00d89407cd594f560c3e65cadc8e81202cc86297
7 changes: 7 additions & 0 deletions internal/cli/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func runMonitorCmd(
defaultPort, defaultProtocol string
)

// Flags takes maximum precedence over sketch.yaml
// If {--port --fqbn --profile} are set we ignore the profile.
// If both {--port --profile} are set we read the fqbn in the following order: profile -> default_fqbn -> discovery
// If only --port is set we read the fqbn in the following order: default_fqbn -> discovery
// If only --fqbn is set we read the port in the following order: default_port
sketchPath := arguments.InitSketchPath(sketchPathArg)
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
if err != nil && !portArgs.IsPortFlagSet() {
Expand All @@ -108,6 +113,8 @@ func runMonitorCmd(
}
if sketch != nil {
defaultPort, defaultProtocol = sketch.GetDefaultPort(), sketch.GetDefaultProtocol()
}
if fqbnArg.String() == "" {
if profileArg.Get() == "" {
inst, profile = instance.CreateAndInitWithProfile(sketch.GetDefaultProfile().GetName(), sketchPath)
} else {
Expand Down
30 changes: 30 additions & 0 deletions internal/integrationtest/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ yun.serial.disableDTR=true
require.Contains(t, string(stdout), "Configuration rts = off")
require.Contains(t, string(stdout), "Configuration dtr = off")
})

t.Run("FQBNFromSpecificProfile", func(t *testing.T) {
// The only way to assert we're picking up the fqbn specified from the profile is to provide a wrong value
_, stderr, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "--raw", "--profile", "profile1", sketchWithPortAndFQBN)
require.Error(t, err)
require.Contains(t, string(stderr), "not an FQBN: broken_fqbn")
})
})

t.Run("WithPortFlag", func(t *testing.T) {
Expand Down Expand Up @@ -188,6 +195,13 @@ yun.serial.disableDTR=true
require.Contains(t, string(stdout), "Configuration rts = off")
require.Contains(t, string(stdout), "Configuration dtr = off")
})

t.Run("FQBNFromSpecificProfile", func(t *testing.T) {
// The only way to assert we're picking up the fqbn specified from the profile is to provide a wrong value
_, stderr, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-p", "/dev/ttyARGS", "--raw", "--profile", "profile1", sketchWithPortAndFQBN)
require.Error(t, err)
require.Contains(t, string(stderr), "not an FQBN: broken_fqbn")
})
})

t.Run("WithFQBNFlag", func(t *testing.T) {
Expand Down Expand Up @@ -218,6 +232,14 @@ yun.serial.disableDTR=true
require.Contains(t, string(stdout), "Configuration rts = off")
require.Contains(t, string(stdout), "Configuration dtr = on")
})

t.Run("IgnoreProfile", func(t *testing.T) {
stdout, _, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-b", "arduino:avr:uno", "--raw", "--profile", "profile1", sketchWithPortAndFQBN)
require.NoError(t, err)
require.Contains(t, string(stdout), "Opened port: /dev/ttyDEF")
require.Contains(t, string(stdout), "Configuration rts = off")
require.Contains(t, string(stdout), "Configuration dtr = on")
})
})

t.Run("WithPortAndFQBNFlags", func(t *testing.T) {
Expand Down Expand Up @@ -252,5 +274,13 @@ yun.serial.disableDTR=true
require.Contains(t, string(stdout), "Configuration rts = off")
require.Contains(t, string(stdout), "Configuration dtr = on")
})

t.Run("IgnoreProfile", func(t *testing.T) {
stdout, _, err := cli.RunWithCustomInput(quitMonitor(), "monitor", "-p", "/dev/ttyARGS", "-b", "arduino:avr:uno", "--raw", "--profile", "profile1", sketchWithPortAndFQBN)
require.NoError(t, err)
require.Contains(t, string(stdout), "Opened port: /dev/ttyARGS")
require.Contains(t, string(stdout), "Configuration rts = off")
require.Contains(t, string(stdout), "Configuration dtr = on")
})
})
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
default_port: /dev/ttyDEF
default_fqbn: arduino:avr:yun
profiles:
profile1:
fqbn: "broken_fqbn"