From d5ab61211a0bde502b89065578bedc0e13cd176a Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Thu, 31 Aug 2023 10:14:44 +0200 Subject: [PATCH] use the new function in all the tests --- .../add_additional_entries_to_context_test.go | 30 +++++++------- legacy/builder/test/hardware_loader_test.go | 15 +++---- legacy/builder/test/libraries_loader_test.go | 40 +++++++++++++++++-- legacy/builder/test/recipe_runner_test.go | 10 ++++- .../test/setup_build_properties_test.go | 30 +++++++------- 5 files changed, 85 insertions(+), 40 deletions(-) diff --git a/legacy/builder/test/add_additional_entries_to_context_test.go b/legacy/builder/test/add_additional_entries_to_context_test.go index fc1edb5acb2..e39cc2a4984 100644 --- a/legacy/builder/test/add_additional_entries_to_context_test.go +++ b/legacy/builder/test/add_additional_entries_to_context_test.go @@ -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)) } diff --git a/legacy/builder/test/hardware_loader_test.go b/legacy/builder/test/hardware_loader_test.go index f900ad38ac3..120ceb2148c 100644 --- a/legacy/builder/test/hardware_loader_test.go +++ b/legacy/builder/test/hardware_loader_test.go @@ -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() diff --git a/legacy/builder/test/libraries_loader_test.go b/legacy/builder/test/libraries_loader_test.go index 143c1866221..180a5374c63 100644 --- a/legacy/builder/test/libraries_loader_test.go +++ b/legacy/builder/test/libraries_loader_test.go @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/legacy/builder/test/recipe_runner_test.go b/legacy/builder/test/recipe_runner_test.go index 6fb90bf7e68..ad21730ce1d 100644 --- a/legacy/builder/test/recipe_runner_test.go +++ b/legacy/builder/test/recipe_runner_test.go @@ -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"}, } diff --git a/legacy/builder/test/setup_build_properties_test.go b/legacy/builder/test/setup_build_properties_test.go index 1b595d5d69c..4d577da17b7 100644 --- a/legacy/builder/test/setup_build_properties_test.go +++ b/legacy/builder/test/setup_build_properties_test.go @@ -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 @@ -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