Skip to content

Commit

Permalink
use the new function in all the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Aug 31, 2023
1 parent dbe7d8a commit e2dfe67
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 40 deletions.
30 changes: 16 additions & 14 deletions legacy/builder/test/add_additional_entries_to_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,32 @@ import (
func TestAddAdditionalEntriesToContextNoBuildPath(t *testing.T) {
ctx := &types.Context{}

command := builder.AddAdditionalEntriesToContext{}
NoError(t, command.Run(ctx))
sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)

require.Empty(t, ctx.SketchBuildPath)
require.Empty(t, ctx.LibrariesBuildPath)
require.Empty(t, ctx.CoreBuildPath)
require.Empty(t, sketchBuildPath)
require.Empty(t, librariesBuildPath)
require.Empty(t, coreBuildPath)

require.NotNil(t, ctx.WarningsLevel)
require.NotNil(t, warningsLevel)

require.Equal(t, 0, len(ctx.LibrariesResolutionResults))
require.Equal(t, 0, len(librariesResolutionResults))
}

func TestAddAdditionalEntriesToContextWithBuildPath(t *testing.T) {
ctx := &types.Context{}
ctx.BuildPath = paths.New("folder")

command := builder.AddAdditionalEntriesToContext{}
NoError(t, command.Run(ctx))
sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)

require.Equal(t, Abs(t, paths.New("folder", constants.FOLDER_SKETCH)), ctx.SketchBuildPath)
require.Equal(t, Abs(t, paths.New("folder", "libraries")), ctx.LibrariesBuildPath)
require.Equal(t, Abs(t, paths.New("folder", constants.FOLDER_CORE)), ctx.CoreBuildPath)
require.Equal(t, Abs(t, paths.New("folder", constants.FOLDER_SKETCH)), sketchBuildPath)
require.Equal(t, Abs(t, paths.New("folder", "libraries")), librariesBuildPath)
require.Equal(t, Abs(t, paths.New("folder", constants.FOLDER_CORE)), coreBuildPath)

require.NotNil(t, ctx.WarningsLevel)
require.NotNil(t, warningsLevel)

require.Equal(t, 0, len(ctx.LibrariesResolutionResults))
require.Equal(t, 0, len(librariesResolutionResults))
}
15 changes: 8 additions & 7 deletions legacy/builder/test/hardware_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, nil, "")
defer cleanUpBuilderTestContext(t, ctx)

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
}
for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}
sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

packages := ctx.PackageManager.GetPackages()

Expand Down
40 changes: 36 additions & 4 deletions legacy/builder/test/libraries_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ func TestLoadLibrariesAVR(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, nil, "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)

sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
&builder.LibrariesLoader{},
}
for _, command := range commands {
Expand Down Expand Up @@ -153,8 +161,16 @@ func TestLoadLibrariesSAM(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, nil, "arduino:sam:arduino_due_x_dbg")
defer cleanUpBuilderTestContext(t, ctx)

sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
&builder.LibrariesLoader{},
}
for _, command := range commands {
Expand Down Expand Up @@ -232,8 +248,16 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, nil, "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)

sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
&builder.LibrariesLoader{},
}
for _, command := range commands {
Expand All @@ -257,8 +281,16 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, nil, "my_avr_platform:avr:custom_yun")
defer cleanUpBuilderTestContext(t, ctx)

sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
&builder.LibrariesLoader{},
}
for _, command := range commands {
Expand Down
10 changes: 9 additions & 1 deletion legacy/builder/test/recipe_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ func TestRecipeRunner(t *testing.T) {

buildProperties.Set("recipe.hooks.prebuild.1.pattern", "echo")

sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
&builder.RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.prebuild", Suffix: ".pattern"},
}

Expand Down
30 changes: 16 additions & 14 deletions legacy/builder/test/setup_build_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ func TestSetupBuildProperties(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
defer cleanUpBuilderTestContext(t, ctx)

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
}
for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}
sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

buildProperties := ctx.BuildProperties

Expand Down Expand Up @@ -108,13 +109,14 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) {
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "my_avr_platform:avr:custom_yun")
defer cleanUpBuilderTestContext(t, ctx)

commands := []types.Command{
&builder.AddAdditionalEntriesToContext{},
}
for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}
sketchBuildPath, librariesBuildPath, coreBuildPath,
warningsLevel, librariesResolutionResults, err := builder.AddAdditionalEntriesToContext(ctx.BuildPath, ctx.WarningsLevel)
NoError(t, err)
ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
ctx.CoreBuildPath = coreBuildPath
ctx.WarningsLevel = warningsLevel
ctx.LibrariesResolutionResults = librariesResolutionResults

buildProperties := ctx.BuildProperties

Expand Down

0 comments on commit e2dfe67

Please sign in to comment.