Skip to content

Commit

Permalink
remove container_setup and adjust relative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 1, 2023
1 parent 7edeb03 commit a086232
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 159 deletions.
26 changes: 0 additions & 26 deletions legacy/builder/container_setup.go

This file was deleted.

35 changes: 34 additions & 1 deletion legacy/builder/test/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,18 @@ func cleanUpBuilderTestContext(t *testing.T, ctx *types.Context) {
}
}

func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *paths.Path, fqbn string) *types.Context {
type skipContextPreparationStepName string

const skipLibraries = skipContextPreparationStepName("libraries")

func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *paths.Path, fqbn string, skips ...skipContextPreparationStepName) *types.Context {
DownloadCoresAndToolsAndLibraries(t)

stepToSkip := map[skipContextPreparationStepName]bool{}
for _, skip := range skips {
stepToSkip[skip] = true
}

if ctx == nil {
ctx = &types.Context{}
}
Expand Down Expand Up @@ -113,6 +122,30 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.RequiredTools = requiredTools
}

if ctx.Sketch != nil {
require.False(t, ctx.BuildPath.Canonical().EqualsTo(ctx.Sketch.FullPath.Canonical()))
}

if !stepToSkip[skipLibraries] {
lm, libsResolver, _, err := bldr.LibrariesLoader(
ctx.UseCachedLibrariesResolution, ctx.LibrariesManager,
ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs,
ctx.ActualPlatform, ctx.TargetPlatform,
)
NoError(t, err)

ctx.LibrariesManager = lm
ctx.LibrariesResolver = libsResolver
ctx.SketchLibrariesDetector = bldr.NewSketchLibrariesDetector(
lm, libsResolver,
ctx.ImportedLibraries,
ctx.Verbose,
ctx.UseCachedLibrariesResolution,
func(msg string) { ctx.Info(msg) },
func(msg string) { ctx.Warn(msg) },
)
}

return ctx
}

Expand Down
11 changes: 4 additions & 7 deletions legacy/builder/test/ctags_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@ import (
"testing"

"github.com/arduino/arduino-cli/arduino/builder/preprocessor"
"github.com/arduino/arduino-cli/legacy/builder"
"github.com/arduino/arduino-cli/legacy/builder/types"
paths "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)

func ctagsRunnerTestTemplate(t *testing.T, sketchLocation *paths.Path) []byte {
ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo")
ctx := &types.Context{Verbose: true}
ctx = prepareBuilderTestContext(t, ctx, sketchLocation, "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)
ctx.Verbose = true

err := (&builder.ContainerSetupHardwareToolsLibsSketchAndProps{}).Run(ctx)
NoError(t, err)

_, err = ctx.Builder.PrepareSketchBuildPath(nil, ctx.SketchBuildPath)
_, err := ctx.Builder.PrepareSketchBuildPath(nil, ctx.SketchBuildPath)
NoError(t, err)

source := loadPreprocessedSketch(t, ctx)
Expand Down
9 changes: 5 additions & 4 deletions legacy/builder/test/hardware_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func TestLoadHardware(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList("downloaded_hardware", filepath.Join("..", "hardware")),
}
ctx = prepareBuilderTestContext(t, ctx, nil, "")

ctx = prepareBuilderTestContext(t, ctx, nil, "", skipLibraries)
defer cleanUpBuilderTestContext(t, ctx)

packages := ctx.PackageManager.GetPackages()
Expand Down Expand Up @@ -65,7 +66,7 @@ func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList("downloaded_hardware", filepath.Join("..", "hardware"), "user_hardware"),
}
ctx = prepareBuilderTestContext(t, ctx, nil, "")
ctx = prepareBuilderTestContext(t, ctx, nil, "", skipLibraries)
defer cleanUpBuilderTestContext(t, ctx)

packages := ctx.PackageManager.GetPackages()
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList("downloaded_board_manager_stuff"),
}
ctx = prepareBuilderTestContext(t, ctx, nil, "")
ctx = prepareBuilderTestContext(t, ctx, nil, "", skipLibraries)
defer cleanUpBuilderTestContext(t, ctx)

packages := ctx.PackageManager.GetPackages()
Expand Down Expand Up @@ -166,7 +167,7 @@ func TestLoadLotsOfHardware(t *testing.T) {
ctx := &types.Context{
HardwareDirs: paths.NewPathList("downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "user_hardware"),
}
ctx = prepareBuilderTestContext(t, ctx, nil, "")
ctx = prepareBuilderTestContext(t, ctx, nil, "", skipLibraries)
defer cleanUpBuilderTestContext(t, ctx)

packages := ctx.PackageManager.GetPackages()
Expand Down
27 changes: 10 additions & 17 deletions legacy/builder/test/includes_to_include_folders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ import (
)

func TestIncludesToIncludeFolders(t *testing.T) {
ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
ctx := &types.Context{Verbose: true}
ctx = prepareBuilderTestContext(t, ctx, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)
ctx.Verbose = true

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand All @@ -51,13 +50,12 @@ func TestIncludesToIncludeFolders(t *testing.T) {
}

func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
ctx := prepareBuilderTestContext(t, nil, paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), "arduino:avr:leonardo")
ctx := &types.Context{Verbose: true}
ctx = prepareBuilderTestContext(t, ctx, paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)
ctx.Verbose = true

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand All @@ -74,13 +72,12 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
}

func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch9", "sketch9.ino"), "arduino:avr:leonardo")
ctx := &types.Context{Verbose: true}
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch9", "sketch9.ino"), "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)
ctx.Verbose = true

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand All @@ -100,13 +97,12 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
}

func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch10", "sketch10.ino"), "arduino:avr:leonardo")
ctx := &types.Context{Verbose: true}
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch10", "sketch10.ino"), "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)
ctx.Verbose = true

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand Down Expand Up @@ -137,7 +133,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand Down Expand Up @@ -169,7 +164,6 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand Down Expand Up @@ -201,7 +195,6 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand All @@ -221,13 +214,13 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
}

func TestIncludesToIncludeFoldersSubfolders(t *testing.T) {
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:leonardo")
ctx := &types.Context{Verbose: true}
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:leonardo")
defer cleanUpBuilderTestContext(t, ctx)
ctx.Verbose = true

var _err error
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
types.BareCommand(func(ctx *types.Context) error {
ctx.LineOffset, _err = ctx.Builder.PrepareSketchBuildPath(ctx.SourceOverride, ctx.SketchBuildPath)
return _err
Expand Down
12 changes: 0 additions & 12 deletions legacy/builder/test/merge_sketch_with_bootloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func TestMergeSketchWithBootloader(t *testing.T) {
NoError(t, err)

commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
&builder.MergeSketchWithBootloader{},
}

Expand Down Expand Up @@ -129,7 +128,6 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {
NoError(t, err)

commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
&builder.MergeSketchWithBootloader{},
}

Expand All @@ -152,15 +150,6 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {
defer cleanUpBuilderTestContext(t, ctx)

buildPath := ctx.BuildPath
commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
}

for _, command := range commands {
err := command.Run(ctx)
NoError(t, err)
}

buildProperties := ctx.BuildProperties
buildProperties.Remove(constants.BUILD_PROPERTIES_BOOTLOADER_NOBLINK)
buildProperties.Remove(constants.BUILD_PROPERTIES_BOOTLOADER_FILE)
Expand Down Expand Up @@ -222,7 +211,6 @@ func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) {
NoError(t, err)

commands := []types.Command{
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
&builder.MergeSketchWithBootloader{},
}

Expand Down
Loading

0 comments on commit a086232

Please sign in to comment.