8000 Porting `legacy` tests to new integration-test infra (part 3...) by cmaglie · Pull Request #2300 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Porting legacy tests to new integration-test infra (part 3...) #2300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 8, 2023
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
8000
Prev Previous commit
Next Next commit
Removed useless NoError helper function
  • Loading branch information
cmaglie committed Sep 7, 2023
commit 3d979d3c569fe1d598ae1e6f4832fd44a6c18ded
10 changes: 5 additions & 5 deletions legacy/builder/test/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
}
if ctx.BuildPath == nil {
buildPath, err := paths.MkTempDir("", "test_build_path")
NoError(t, err)
require.NoError(t, err)
ctx.BuildPath = buildPath
}

buildPath := ctx.BuildPath
sketchBuildPath, err := buildPath.Join(constants.FOLDER_SKETCH).Abs()
NoError(t, err)
require.NoError(t, err)
librariesBuildPath, err := buildPath.Join(constants.FOLDER_LIBRARIES).Abs()
NoError(t, err)
require.NoError(t, err)
coreBuildPath, err 8000 := buildPath.Join(constants.FOLDER_CORE).Abs()
NoError(t, err)
require.NoError(t, err)

ctx.SketchBuildPath = sketchBuildPath
ctx.LibrariesBuildPath = librariesBuildPath
Expand Down Expand Up @@ -128,7 +128,7 @@ func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *pat
ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs,
ctx.ActualPlatform, ctx.TargetPlatform,
)
NoError(t, err)
require.NoError(t, err)

ctx.SketchLibrariesDetector = detector.NewSketchLibrariesDetector(
lm, libsResolver,
Expand Down
16 changes: 8 additions & 8 deletions legacy/builder/test/builder_utils_test.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func tempFile(t *testing.T, prefix string) *paths.Path {
file, err := os.CreateTemp("", prefix)
file.Close()
NoError(t, err)
require.NoError(t, err)
return paths.New(file.Name())
}

Expand All @@ -37,7 +37,7 @@ func TestObjFileIsUpToDateObjMissing(t *testing.T) {
defer sourceFile.RemoveAll()

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, nil, nil)
NoError(t, err)
require.NoError(t, err)
require.False(t, upToDate)
}

Expand All @@ -49,7 +49,7 @@ func TestObjFileIsUpToDateDepMissing(t *testing.T) {
defer objFile.RemoveAll()

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, objFile, nil)
NoError(t, err)
require.NoError(t, err)
require.False(t, upToDate)
}

Expand All @@ -65,7 +65,7 @@ func TestObjFileIsUpToDateObjOlder(t *testing.T) {
defer sourceFile.RemoveAll()

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
NoError(t, err)
require.NoError(t, err)
require.False(t, upToDate)
}

Expand All @@ -81,7 +81,7 @@ func TestObjFileIsUpToDateObjNewer(t *testing.T) {
defer depFile.RemoveAll()

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
NoError(t, err)
require.NoError(t, err)
require.True(t, upToDate)
}

Expand All @@ -105,7 +105,7 @@ func TestObjFileIsUpToDateDepIsNewer(t *testing.T) {
depFile.WriteFile([]byte(data))

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
NoError(t, err)
require.NoError(t, err)
require.False(t, upToDate)
}

Expand All @@ -127,7 +127,7 @@ func TestObjFileIsUpToDateDepIsOlder(t *testing.T) {
depFile.WriteFile([]byte(res))

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
NoError(t, err)
require.NoError(t, err)
require.True(t, upToDate)
}

Expand All @@ -151,6 +151,6 @@ func TestObjFileIsUpToDateDepIsWrong(t *testing.T) {
depFile.WriteFile([]byte(res))

upToDate, err := utils.ObjFileIsUpToDate(sourceFile, objFile, depFile)
NoError(t, err)
require.NoError(t, err)
require.False(t, upToDate)
}
2 changes: 1 addition & 1 deletion legacy/builder/test/create_build_options_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestCreateBuildOptionsMap(t *testing.T) {

create := builder.CreateBuildOptionsMap{}
err := create.Run(ctx)
NoError(t, err)
require.NoError(t, err)

require.Equal(t, `{
"additionalFiles": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ func TestFailIfBuildPathEqualsSketchPathSketchPathDiffers(t *testing.T) {
}

command := builder.FailIfBuildPathEqualsSketchPath{}
NoError(t, command.Run(ctx))
require.NoError(t, command.Run(ctx))
}
15 changes: 3 additions & 12 deletions legacy/builder/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,32 @@
package test

import (
"fmt"
"testing"

"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/arduino-cli/legacy/builder/constants"
"github.com/arduino/arduino-cli/legacy/builder/types"
paths "github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Abs(t *testing.T, rel *paths.Path) *paths.Path {
absPath, err := rel.Abs()
NoError(t, err)
require.NoError(t, err)
return absPath
}

func NoError(t *testing.T, err error, msgAndArgs ...interface{}) {
if !assert.NoError(t, err, msgAndArgs...) {
fmt.Printf("%+v\n", err) // Outputs stack trace in case of wrapped error
t.FailNow()
}
}

func SetupBuildPath(t *testing.T, ctx *types.Context) *paths.Path {
buildPath, err := paths.MkTempDir("", "test_build_path")
NoError(t, err)
require.NoError(t, err)
ctx.BuildPath = buildPath
return buildPath
}

func SetupBuildCachePath(t *testing.T, ctx *types.Context) *paths.Path {
buildCachePath, err := paths.MkTempDir(constants.EMPTY_STRING, "test_build_cache")
NoError(t, err)
require.NoError(t, err)
ctx.CoreBuildCachePath = buildCachePath
return buildCachePath
}
Expand Down
33 changes: 17 additions & 16 deletions legacy/builder/test/helper_tools_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -136,9 +137,9 @@ func DownloadCoresAndToolsAndLibraries(t *testing.T) {

func patchFiles(t *testing.T) {
err := patchesFolder.MkdirAll()
NoError(t, err)
require.NoError(t, err)
files, err := patchesFolder.ReadDir()
NoError(t, err)
require.NoError(t, err)

for _, file := range files {
if file.Ext() == ".patch" {
Expand All @@ -147,9 +148,9 @@ func patchFiles(t *testing.T) {
// https://github.com/arduino/arduino-builder/issues/147
/*
data, err := ioutil.ReadFile(Abs(t, filepath.Join(PATCHES_FOLDER, file.Name())))
NoError(t, err)
require.NoError(t, err)
patchSet, err := patch.Parse(data)
NoError(t, err)
require.NoError(t, err)
operations, err := patchSet.Apply(ioutil.ReadFile)
for _, op := range operations {
utils.WriteFileBytes(op.Dst, op.Data)
Expand All @@ -161,7 +162,7 @@ func patchFiles(t *testing.T) {

func download(t *testing.T, cores, boardsManagerCores, boardsManagerRedBearCores []Core, tools, toolsMultipleVersions, boardsManagerTools, boardsManagerRFduinoTools []Tool, libraries []Library) {
allCoresDownloaded, err := allCoresAlreadyDownloadedAndUnpacked(hardwareFolder, cores)
NoError(t, err)
require.NoError(t, err)
if allCoresDownloaded &&
allBoardsManagerCoresAlreadyDownloadedAndUnpacked(boardManagerFolder, boardsManagerCores) &&
allBoardsManagerCoresAlreadyDownloadedAndUnpacked(boardManagerFolder, boardsManagerRedBearCores) &&
Expand All @@ -174,37 +175,37 @@ func download(t *testing.T, cores, boardsManagerCores, boardsManagerRedBearCores
}

index, err := downloadIndex("http://downloads.arduino.cc/packages/package_index.json")
NoError(t, err)
require.NoError(t, err)

err = downloadCores(cores, index)
NoError(t, err)
require.NoError(t, err)

err = downloadBoardManagerCores(boardsManagerCores, index)
NoError(t, err)
require.NoError(t, err)

err = downloadTools(tools, index)
NoError(t, err)
require.NoError(t, err)

err = downloadToolsMultipleVersions(toolsMultipleVersions, index)
NoError(t, err)
require.NoError(t, err)

err = downloadBoardsManagerTools(boardsManagerTools, index)
NoError(t, err)
require.NoError(t, err)

rfduinoIndex, err := downloadIndex("http://downloads.arduino.cc/packages/test_package_rfduino_index.json")
NoError(t, err)
require.NoError(t, err)

err = downloadBoardsManagerTools(boardsManagerRFduinoTools, rfduinoIndex)
NoError(t, err)
require.NoError(t, err)

err = downloadBoardManagerCores(boardsManagerRedBearCores, nil)
NoError(t, err)
require.NoError(t, err)

librariesIndex, err := downloadIndex("http://downloads.arduino.cc/libraries/library_index.json")
NoError(t, err)
require.NoError(t, err)

err = downloadLibraries(libraries, librariesIndex)
NoError(t, err)
require.NoError(t, err)
}

func downloadIndex(url string) (map[string]interface{}, error) {
Expand Down
8 changes: 4 additions & 4 deletions legacy/builder/test/libraries_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestLoadLibrariesAVR(t *testing.T) {
ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs,
ctx.ActualPlatform, ctx.TargetPlatform,
)
NoError(t, err)
require.NoError(t, err)

librariesFolders := lm.LibrariesDir
require.Equal(t, 3, len(librariesFolders))
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestLoadLibrariesSAM(t *testing.T) {
ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs,
ctx.ActualPlatform, ctx.TargetPlatform,
)
NoError(t, err)
require.NoError(t, err)

librariesFolders := lm.LibrariesDir
require.Equal(t, 3, len(librariesFolders))
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) {
ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs,
ctx.ActualPlatform, ctx.TargetPlatform,
)
NoError(t, err)
require.NoError(t, err)

librariesFolders := lm.LibrariesDir
require.Equal(t, 3, len(librariesFolders))
Expand All @@ -256,7 +256,7 @@ func TestLoadLibrariesMyAVRPlatform(t *testing.T) {
ctx.BuiltInLibrariesDirs, ctx.LibraryDirs, ctx.OtherLibrariesDirs,
ctx.ActualPlatform, ctx.TargetPlatform,
)
NoError(t, err)
require.NoError(t, err)

librariesFolders := lm.LibrariesDir
require.Equal(t, 4, len(librariesFolders))
Expand Down
6 changes: 3 additions & 3 deletions legacy/builder/test/load_previous_build_options_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func TestLoadPreviousBuildOptionsMap(t *testing.T) {
defer buildPath.RemoveAll()

err := buildPath.Join(constants.BUILD_OPTIONS_FILE).WriteFile([]byte("test"))
NoError(t, err)
require.NoError(t, err)

command := builder.LoadPreviousBuildOptionsMap{}
err = command.Run(ctx)
NoError(t, err)
require.NoError(t, err)

require.Equal(t, "test", ctx.BuildOptionsJsonPrevious)
}
Expand All @@ -48,7 +48,7 @@ func TestLoadPreviousBuildOptionsMapMissingFile(t *testing.T) {

command := builder.LoadPreviousBuildOptionsMap{}
err := command.Run(ctx)
NoError(t, err)
require.NoError(t, err)

require.Empty(t, ctx.BuildOptionsJsonPrevious)
}
Loading
0