Skip to content

Commit

Permalink
Added integration tests for all default_profile cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Aug 23, 2023
1 parent 4d3bb2c commit 8b37244
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
79 changes: 69 additions & 10 deletions internal/integrationtest/profiles/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
)

func TestCompileWithProfiles(t *testing.T) {
Expand Down Expand Up @@ -78,16 +79,74 @@ func TestCompileWithDefaultProfile(t *testing.T) {
_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)

// copy sketch_with_profile into the working directory
sketchPath := cli.CopySketch("sketch_with_profile")

// compile using the default profile with its fqbn
stdout, _, err := cli.Run("compile", sketchPath.String())
// Installa core/libs globally
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
require.NoError(t, err)
require.Contains(t, string(stdout), "arduino:avr")

// compile using a different fbqn -> should have priority over the one in the default profile
stdout, _, err = cli.Run("compile", "-b", "arduino:samd:mkr1000", sketchPath.String())
require.NoError(t, err)
require.Contains(t, string(stdout), "arduino:samd")
// copy sketch_with_profile into the working directory
sketchWithoutDefProfilePath := cli.CopySketch("sketch_without_default_profile")
sketchWithDefProfilePath := cli.CopySketch("sketch_with_default_profile")

{
// no default profile -> error missing FQBN
_, _, err := cli.Run("compile", sketchWithoutDefProfilePath.String(), "--format", "json")
require.Error(t, err)
}
{
// specified fbqn -> compile with specified FQBN and use global installation
stdout, _, err := cli.Run("compile", "-b", "arduino:avr:nano", sketchWithoutDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.3"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`)
}
{
// specified profile -> use the specified profile
stdout, _, err := cli.Run("compile", "--profile", "avr1", sketchWithoutDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:uno" ]`)
}
{
// specified profile and fqbn -> use the specified profile and override fqbn
stdout, _, err := cli.Run("compile", "--profile", "avr1", "-b", "arduino:avr:nano", sketchWithoutDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`)
}

{
// default profile -> use default profile
stdout, _, err := cli.Run("compile", sketchWithDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.5"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:leonardo" ]`)
}
{
// default profile, specified fbqn -> use default profile, override fqbn
stdout, _, err := cli.Run("compile", "-b", "arduino:avr:nano", sketchWithDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.5"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`)
}
{
// default profile, specified different profile -> use the specified profile
stdout, _, err := cli.Run("compile", "--profile", "avr1", sketchWithDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:uno" ]`)
}
{
// default profile, specified different profile and fqbn -> use the specified profile and override fqbn
stdout, _, err := cli.Run("compile", "--profile", "avr1", "-b", "arduino:avr:nano", sketchWithDefProfilePath.String(), "--format", "json")
require.NoError(t, err)
jsonOut := requirejson.Parse(t, stdout)
jsonOut.Query(".builder_result.build_platform").MustContain(`{"id":"arduino:avr", "version":"1.8.4"}`)
jsonOut.Query(".builder_result.build_properties").MustContain(`[ "build.fqbn=arduino:avr:nano" ]`)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
profiles:
avr1:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.4)

avr2:
fqbn: arduino:avr:leonardo
platforms:
- platform: arduino:avr (1.8.5)

default_profile: avr2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void setup() {}
void loop() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
profiles:
avr1:
fqbn: arduino:avr:uno
platforms:
- platform: arduino:avr (1.8.4)

avr2:
fqbn: arduino:avr:leonardo
platforms:
- platform: arduino:avr (1.8.5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
void setup() {}
void loop() {}

0 comments on commit 8b37244

Please sign in to comment.