Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f47a7bf

Browse files
committedApr 15, 2023
Removed legacy TargetBoardResolver and refactored unit-tests
1 parent 1652b8b commit f47a7bf

15 files changed

+278
-771
lines changed
 

‎commands/compile/compile.go

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/arduino/arduino-cli/arduino"
2626
bldr "github.com/arduino/arduino-cli/arduino/builder"
2727
"github.com/arduino/arduino-cli/arduino/cores"
28-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2928
"github.com/arduino/arduino-cli/arduino/sketch"
3029
"github.com/arduino/arduino-cli/buildcache"
3130
"github.com/arduino/arduino-cli/commands"
@@ -90,18 +89,21 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
9089
if err != nil {
9190
return nil, &arduino.InvalidFQBNError{Cause: err}
9291
}
93-
94-
targetPlatform := pme.FindPlatform(&packagemanager.PlatformReference{
95-
Package: fqbn.Package,
96-
PlatformArchitecture: fqbn.PlatformArch,
97-
})
98-
if targetPlatform == nil || pme.GetInstalledPlatformRelease(targetPlatform) == nil {
99-
return nil, &arduino.PlatformNotFoundError{
100-
Platform: fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch),
101-
Cause: fmt.Errorf(tr("platform not installed")),
92+
targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := pme.ResolveFQBN(fqbn)
93+
if err != nil {
94+
if targetPlatform == nil {
95+
return nil, &arduino.PlatformNotFoundError{
96+
Platform: fmt.Sprintf("%s:%s", fqbn.Package, fqbn.PlatformArch),
97+
Cause: fmt.Errorf(tr("platform not installed")),
98+
}
10299
}
100+
return nil, &arduino.InvalidFQBNError{Cause: err}
103101
}
104102

103+
r = &rpc.CompileResponse{}
104+
r.BoardPlatform = targetPlatform.ToRPCPlatformReference()
105+
r.BuildPlatform = buildPlatform.ToRPCPlatformReference()
106+
105107
// At the current time we do not have a way of knowing if a board supports the secure boot or not,
106108
// so, if the flags to override the default keys are used, we try override the corresponding platform property nonetheless.
107109
// It's not possible to use the default name for the keys since there could be more tools to sign and encrypt.
@@ -111,11 +113,22 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
111113
securityKeysOverride = append(securityKeysOverride, "build.keys.keychain="+req.KeysKeychain, "build.keys.sign_key="+req.GetSignKey(), "build.keys.encrypt_key="+req.EncryptKey)
112114
}
113115

116+
requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
117+
if err != nil {
118+
return nil, err
119+
}
120+
114121
builderCtx := &types.Context{}
115122
builderCtx.PackageManager = pme
116123
if pme.GetProfile() != nil {
117124
builderCtx.LibrariesManager = lm
118125
}
126+
builderCtx.TargetBoard = targetBoard
127+
builderCtx.TargetBoardBuildProperties = buildProperties
128+
builderCtx.TargetPlatform = targetPlatform
129+
builderCtx.TargetPackage = targetPackage
130+
builderCtx.ActualPlatform = buildPlatform
131+
builderCtx.RequiredTools = requiredTools
119132
builderCtx.UseCachedLibrariesResolution = req.GetSkipLibrariesDiscovery()
120133
builderCtx.FQBN = fqbn
121134
builderCtx.Sketch = sk
@@ -186,17 +199,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
186199
builderCtx.OnlyUpdateCompilationDatabase = req.GetCreateCompilationDatabaseOnly()
187200
builderCtx.SourceOverride = req.GetSourceOverride()
188201

189-
r = &rpc.CompileResponse{}
190202
defer func() {
191203
if p := builderCtx.BuildPath; p != nil {
192204
r.BuildPath = p.String()
193205
}
194-
if pl := builderCtx.TargetPlatform; pl != nil {
195-
r.BoardPlatform = pl.ToRPCPlatformReference()
196-
}
197-
if pl := builderCtx.ActualPlatform; pl != nil {
198-
r.BuildPlatform = pl.ToRPCPlatformReference()
199-
}
200206
}()
201207

202208
defer func() {
@@ -243,6 +249,30 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
243249
}()
244250

245251
// if it's a regular build, go on...
252+
253+
if req.GetVerbose() {
254+
core := buildProperties.Get("build.core")
255+
if core == "" {
256+
core = "arduino"
257+
}
258+
// select the core name in case of "package:core" format
259+
normalizedFQBN, err := pme.NormalizeFQBN(fqbn)
260+
if err != nil {
261+
outStream.Write([]byte(fmt.Sprintf("Could not normalize FQBN: %s\n", err)))
262+
normalizedFQBN = fqbn
263+
}
264+
outStream.Write([]byte(fmt.Sprintf("FQBN: %s\n", normalizedFQBN)))
265+
core = core[strings.Index(core, ":")+1:]
266+
outStream.Write([]byte(tr("Using board '%[1]s' from platform in folder: %[2]s", targetBoard.BoardID, targetPlatform.InstallDir) + "\n"))
267+
outStream.Write([]byte(tr("Using core '%[1]s' from platform in folder: %[2]s", core, buildPlatform.InstallDir) + "\n"))
268+
outStream.Write([]byte("\n"))
269+
}
270+
if !targetBoard.Properties.ContainsKey("build.board") {
271+
outStream.Write([]byte(
272+
tr("Warning: Board %[1]s doesn't define a %[2]s preference. Auto-set to: %[3]s",
273+
targetBoard.String(), "'build.board'", buildProperties.Get("build.board")) + "\n"))
274+
}
275+
246276
if err := builder.RunBuilder(builderCtx); err != nil {
247277
return r, &arduino.CompileFailedError{Message: err.Error()}
248278
}

‎legacy/builder/container_setup.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context)
3131
&AddAdditionalEntriesToContext{},
3232
&FailIfBuildPathEqualsSketchPath{},
3333
&HardwareLoader{},
34-
&TargetBoardResolver{},
3534
&LibrariesLoader{},
3635
}
3736

‎legacy/builder/hardware_loader.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,12 @@
1616
package builder
1717

1818
import (
19-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2019
"github.com/arduino/arduino-cli/legacy/builder/types"
2120
)
2221

2322
type HardwareLoader struct{}
2423

2524
func (s *HardwareLoader) Run(ctx *types.Context) error {
26-
if ctx.PackageManager == nil {
27-
// This should happen only on legacy arduino-builder.
28-
// Hopefully this piece will be removed once the legacy package will be cleanedup.
29-
pmb := packagemanager.NewBuilder(nil, nil, nil, nil, "arduino-builder")
30-
errs := pmb.LoadHardwareFromDirectories(ctx.HardwareDirs)
31-
if ctx.Verbose {
32-
// With the refactoring of the initialization step of the CLI we changed how
33-
// errors are returned when loading platforms and libraries, that meant returning a list of
34-
// errors instead of a single one to enhance the experience for the user.
35-
// I have no intention right now to start a refactoring of the legacy package too, so
36-
// here's this shitty solution for now.
37-
// When we're gonna refactor the legacy package this will be gone.
38-
for _, err := range errs {
39-
ctx.Info(tr("Error loading hardware platform: %[1]s", err.Error()))
40-
}
41-
}
42-
43-
if !ctx.CanUseCachedTools {
44-
if ctx.BuiltInToolsDirs != nil {
45-
pmb.LoadToolsFromBundleDirectories(ctx.BuiltInToolsDirs)
46-
}
47-
48-
ctx.CanUseCachedTools = true
49-
}
50-
51-
pm := pmb.Build()
52-
pme, _ /* never release... */ := pm.NewExplorer()
53-
ctx.PackageManager = pme
54-
}
55-
5625
ctx.AllTools = ctx.PackageManager.GetAllInstalledToolsReleases()
5726
ctx.Hardware = ctx.PackageManager.GetPackages()
5827
return nil

‎legacy/builder/target_board_resolver.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

‎legacy/builder/test/builder_test.go

Lines changed: 85 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
package test
1717

1818
import (
19+
"fmt"
1920
"os/exec"
2021
"path/filepath"
2122
"testing"
2223
"time"
2324

25+
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2426
"github.com/arduino/arduino-cli/arduino/sketch"
2527
"github.com/arduino/arduino-cli/legacy/builder"
2628
"github.com/arduino/arduino-cli/legacy/builder/constants"
@@ -31,24 +33,63 @@ import (
3133
"github.com/stretchr/testify/require"
3234
)
3335

34-
func prepareBuilderTestContext(t *testing.T, sketchPath *paths.Path, fqbn string) *types.Context {
35-
sk, err := sketch.New(sketchPath)
36-
require.NoError(t, err)
37-
return &types.Context{
38-
Sketch: sk,
39-
FQBN: parseFQBN(t, fqbn),
40-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
41-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
42-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
43-
OtherLibrariesDirs: paths.NewPathList("libraries"),
44-
Verbose: false,
36+
func prepareBuilderTestContext(t *testing.T, ctx *types.Context, sketchPath *paths.Path, fqbn string) *types.Context {
37+
DownloadCoresAndToolsAndLibraries(t)
38+
39+
if ctx == nil {
40+
ctx = &types.Context{
41+
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
42+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
43+
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
44+
OtherLibrariesDirs: paths.NewPathList("libraries"),
45+
}
46+
}
47+
48+
// Create a Package Manager from the given context
49+
// This should happen only on legacy arduino-builder.
50+
// Hopefully this piece will be removed once the legacy package will be cleanedup.
51+
pmb := packagemanager.NewBuilder(nil, nil, nil, nil, "arduino-builder")
52+
for _, err := range pmb.LoadHardwareFromDirectories(ctx.HardwareDirs) {
53+
// NoError(t, err)
54+
fmt.Println(err)
55+
}
56+
if !ctx.CanUseCachedTools {
57+
if ctx.BuiltInToolsDirs != nil {
58+
pmb.LoadToolsFromBundleDirectories(ctx.BuiltInToolsDirs)
59+
}
60+
ctx.CanUseCachedTools = true
61+
}
62+
pm := pmb.Build()
63+
pme, _ /* never release... */ := pm.NewExplorer()
64+
ctx.PackageManager = pme
65+
66+
if sketchPath != nil {
67+
sk, err := sketch.New(sketchPath)
68+
require.NoError(t, err)
69+
ctx.Sketch = sk
4570
}
71+
72+
if fqbn != "" {
73+
ctx.FQBN = parseFQBN(t, fqbn)
74+
targetPackage, targetPlatform, targetBoard, buildProperties, buildPlatform, err := pme.ResolveFQBN(ctx.FQBN)
75+
require.NoError(t, err)
76+
requiredTools, err := pme.FindToolsRequiredForBuild(targetPlatform, buildPlatform)
77+
require.NoError(t, err)
78+
79+
ctx.PackageManager = pme
80+
ctx.TargetBoard = targetBoard
81+
ctx.TargetBoardBuildProperties = buildProperties
82+
ctx.TargetPlatform = targetPlatform
83+
ctx.TargetPackage = targetPackage
84+
ctx.ActualPlatform = buildPlatform
85+
ctx.RequiredTools = requiredTools
86+
}
87+
88+
return ctx
4689
}
4790

4891
func TestBuilderEmptySketch(t *testing.T) {
49-
DownloadCoresAndToolsAndLibraries(t)
50-
51-
ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
92+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
5293

5394
buildPath := SetupBuildPath(t, ctx)
5495
defer buildPath.RemoveAll()
@@ -76,9 +117,7 @@ func TestBuilderEmptySketch(t *testing.T) {
76117
}
77118

78119
func TestBuilderBridge(t *testing.T) {
79-
DownloadCoresAndToolsAndLibraries(t)
80-
81-
ctx := prepareBuilderTestContext(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
120+
ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
82121

83122
buildPath := SetupBuildPath(t, ctx)
84123
defer buildPath.RemoveAll()
@@ -109,9 +148,7 @@ func TestBuilderBridge(t *testing.T) {
109148
}
110149

111150
func TestBuilderSketchWithConfig(t *testing.T) {
112-
DownloadCoresAndToolsAndLibraries(t)
113-
114-
ctx := prepareBuilderTestContext(t, paths.New("sketch_with_config", "sketch_with_config.ino"), "arduino:avr:leonardo")
151+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_config", "sketch_with_config.ino"), "arduino:avr:leonardo")
115152

116153
buildPath := SetupBuildPath(t, ctx)
117154
defer buildPath.RemoveAll()
@@ -142,9 +179,7 @@ func TestBuilderSketchWithConfig(t *testing.T) {
142179
}
143180

144181
func TestBuilderBridgeTwice(t *testing.T) {
145-
DownloadCoresAndToolsAndLibraries(t)
146-
147-
ctx := prepareBuilderTestContext(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
182+
ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
148183

149184
buildPath := SetupBuildPath(t, ctx)
150185
defer buildPath.RemoveAll()
@@ -180,9 +215,7 @@ func TestBuilderBridgeTwice(t *testing.T) {
180215
}
181216

182217
func TestBuilderBridgeSAM(t *testing.T) {
183-
DownloadCoresAndToolsAndLibraries(t)
184-
185-
ctx := prepareBuilderTestContext(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:sam:arduino_due_x_dbg")
218+
ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:sam:arduino_due_x_dbg")
186219
ctx.WarningsLevel = "all"
187220

188221
buildPath := SetupBuildPath(t, ctx)
@@ -225,11 +258,13 @@ func TestBuilderBridgeSAM(t *testing.T) {
225258
}
226259

227260
func TestBuilderBridgeRedBearLab(t *testing.T) {
228-
DownloadCoresAndToolsAndLibraries(t)
229-
230-
ctx := prepareBuilderTestContext(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "RedBearLab:avr:blend")
231-
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
232-
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
261+
ctx := &types.Context{
262+
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
263+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "downloaded_board_manager_stuff"),
264+
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
265+
OtherLibrariesDirs: paths.NewPathList("libraries"),
266+
}
267+
ctx = prepareBuilderTestContext(t, ctx, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "RedBearLab:avr:blend")
233268

234269
buildPath := SetupBuildPath(t, ctx)
235270
defer buildPath.RemoveAll()
@@ -260,11 +295,13 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
260295
}
261296

262297
func TestBuilderSketchNoFunctions(t *testing.T) {
263-
DownloadCoresAndToolsAndLibraries(t)
264-
265-
ctx := prepareBuilderTestContext(t, paths.New("sketch_no_functions", "sketch_no_functions.ino"), "RedBearLab:avr:blend")
266-
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
267-
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
298+
ctx := &types.Context{
299+
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
300+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "downloaded_board_manager_stuff"),
301+
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
302+
OtherLibrariesDirs: paths.NewPathList("libraries"),
303+
}
304+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_no_functions", "sketch_no_functions.ino"), "RedBearLab:avr:blend")
268305

269306
buildPath := SetupBuildPath(t, ctx)
270307
defer buildPath.RemoveAll()
@@ -276,11 +313,13 @@ func TestBuilderSketchNoFunctions(t *testing.T) {
276313
}
277314

278315
func TestBuilderSketchWithBackup(t *testing.T) {
279-
DownloadCoresAndToolsAndLibraries(t)
280-
281-
ctx := prepareBuilderTestContext(t, paths.New("sketch_with_backup_files", "sketch_with_backup_files.ino"), "arduino:avr:uno")
282-
ctx.HardwareDirs = append(ctx.HardwareDirs, paths.New("downloaded_board_manager_stuff"))
283-
ctx.BuiltInToolsDirs = append(ctx.BuiltInToolsDirs, paths.New("downloaded_board_manager_stuff"))
316+
ctx := &types.Context{
317+
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
318+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "downloaded_board_manager_stuff"),
319+
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
320+
OtherLibrariesDirs: paths.NewPathList("libraries"),
321+
}
322+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_with_backup_files", "sketch_with_backup_files.ino"), "arduino:avr:uno")
284323

285324
buildPath := SetupBuildPath(t, ctx)
286325
defer buildPath.RemoveAll()
@@ -292,9 +331,7 @@ func TestBuilderSketchWithBackup(t *testing.T) {
292331
}
293332

294333
func TestBuilderSketchWithOldLib(t *testing.T) {
295-
DownloadCoresAndToolsAndLibraries(t)
296-
297-
ctx := prepareBuilderTestContext(t, paths.New("sketch_with_old_lib", "sketch_with_old_lib.ino"), "arduino:avr:uno")
334+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_old_lib", "sketch_with_old_lib.ino"), "arduino:avr:uno")
298335

299336
buildPath := SetupBuildPath(t, ctx)
300337
defer buildPath.RemoveAll()
@@ -306,10 +343,8 @@ func TestBuilderSketchWithOldLib(t *testing.T) {
306343
}
307344

308345
func TestBuilderSketchWithSubfolders(t *testing.T) {
309-
DownloadCoresAndToolsAndLibraries(t)
310-
311346
logrus.SetLevel(logrus.DebugLevel)
312-
ctx := prepareBuilderTestContext(t, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:uno")
347+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:uno")
313348

314349
buildPath := SetupBuildPath(t, ctx)
315350
defer buildPath.RemoveAll()
@@ -321,9 +356,7 @@ func TestBuilderSketchWithSubfolders(t *testing.T) {
321356
}
322357

323358
func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testing.T) {
324-
DownloadCoresAndToolsAndLibraries(t)
325-
326-
ctx := prepareBuilderTestContext(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
359+
ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
327360

328361
buildPath := SetupBuildPath(t, ctx)
329362
defer buildPath.RemoveAll()
@@ -344,9 +377,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin
344377
}
345378

346379
func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
347-
DownloadCoresAndToolsAndLibraries(t)
348-
349-
ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
380+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
350381

351382
var err error
352383
ctx.BuildPath, err = paths.New("sketch1", "build").Abs()
@@ -365,9 +396,7 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
365396
}
366397

367398
func TestBuilderCacheCoreAFile(t *testing.T) {
368-
DownloadCoresAndToolsAndLibraries(t)
369-
370-
ctx := prepareBuilderTestContext(t, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
399+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
371400

372401
SetupBuildPath(t, ctx)
373402
defer ctx.BuildPath.RemoveAll()

‎legacy/builder/test/ctags_runner_test.go

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package test
1717

1818
import (
19-
"path/filepath"
2019
"strings"
2120
"testing"
2221

@@ -27,37 +26,22 @@ import (
2726
)
2827

2928
func TestCTagsRunner(t *testing.T) {
30-
DownloadCoresAndToolsAndLibraries(t)
31-
3229
sketchLocation := Abs(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"))
33-
34-
ctx := &types.Context{
35-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
36-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
37-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
38-
OtherLibrariesDirs: paths.NewPathList("libraries"),
39-
Sketch: OpenSketch(t, sketchLocation),
40-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
41-
Verbose: true,
42-
}
30+
ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo")
31+
ctx.Verbose = true
4332

4433
buildPath := SetupBuildPath(t, ctx)
4534
defer buildPath.RemoveAll()
4635

4736
commands := []types.Command{
48-
4937
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
50-
5138
&builder.ContainerMergeCopySketchFiles{},
52-
5339
&builder.ContainerFindIncludes{},
54-
5540
&builder.PrintUsedLibrariesIfVerbose{},
5641
&builder.WarnAboutArchIncompatibleLibraries{},
5742
&builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: "ctags_target.cpp"},
5843
&builder.CTagsRunner{},
5944
}
60-
6145
for _, command := range commands {
6246
err := command.Run(ctx)
6347
NoError(t, err)
@@ -76,37 +60,22 @@ func TestCTagsRunner(t *testing.T) {
7660
}
7761

7862
func TestCTagsRunnerSketchWithClass(t *testing.T) {
79-
DownloadCoresAndToolsAndLibraries(t)
80-
8163
sketchLocation := Abs(t, paths.New("sketch_with_class", "sketch_with_class.ino"))
82-
83-
ctx := &types.Context{
84-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
85-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
86-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
87-
OtherLibrariesDirs: paths.NewPathList("libraries"),
88-
Sketch: OpenSketch(t, sketchLocation),
89-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
90-
Verbose: true,
91-
}
64+
ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo")
65+
ctx.Verbose = true
9266

9367
buildPath := SetupBuildPath(t, ctx)
9468
defer buildPath.RemoveAll()
9569

9670
commands := []types.Command{
97-
9871
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
99-
10072
&builder.ContainerMergeCopySketchFiles{},
101-
10273
&builder.ContainerFindIncludes{},
103-
10474
&builder.PrintUsedLibrariesIfVerbose{},
10575
&builder.WarnAboutArchIncompatibleLibraries{},
10676
&builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: "ctags_target.cpp"},
10777
&builder.CTagsRunner{},
10878
}
109-
11079
for _, command := range commands {
11180
err := command.Run(ctx)
11281
NoError(t, err)
@@ -118,42 +87,26 @@ func TestCTagsRunnerSketchWithClass(t *testing.T) {
11887
"set_values\t" + quotedSketchLocation + "\t/^void Rectangle::set_values (int x, int y) {$/;\"\tkind:function\tline:8\tclass:Rectangle\tsignature:(int x, int y)\treturntype:void\n" +
11988
"setup\t" + quotedSketchLocation + "\t/^void setup() {$/;\"\tkind:function\tline:13\tsignature:()\treturntype:void\n" +
12089
"loop\t" + quotedSketchLocation + "\t/^void loop() {$/;\"\tkind:function\tline:17\tsignature:()\treturntype:void\n"
121-
12290
require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1))
12391
}
12492

12593
func TestCTagsRunnerSketchWithTypename(t *testing.T) {
126-
DownloadCoresAndToolsAndLibraries(t)
127-
12894
sketchLocation := Abs(t, paths.New("sketch_with_typename", "sketch_with_typename.ino"))
129-
130-
ctx := &types.Context{
131-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
132-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
133-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
134-
OtherLibrariesDirs: paths.NewPathList("libraries"),
135-
Sketch: OpenSketch(t, sketchLocation),
136-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
137-
Verbose: true,
138-
}
95+
ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo")
96+
ctx.Verbose = true
13997

14098
buildPath := SetupBuildPath(t, ctx)
14199
defer buildPath.RemoveAll()
142100

143101
commands := []types.Command{
144-
145102
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
146-
147103
&builder.ContainerMergeCopySketchFiles{},
148-
149104
&builder.ContainerFindIncludes{},
150-
151105
&builder.PrintUsedLibrariesIfVerbose{},
152106
&builder.WarnAboutArchIncompatibleLibraries{},
153107
&builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: "ctags_target.cpp"},
154108
&builder.CTagsRunner{},
155109
}
156-
157110
for _, command := range commands {
158111
err := command.Run(ctx)
159112
NoError(t, err)
@@ -164,42 +117,26 @@ func TestCTagsRunnerSketchWithTypename(t *testing.T) {
164117
"setup\t" + quotedSketchLocation + "\t/^void setup() {$/;\"\tkind:function\tline:6\tsignature:()\treturntype:void\n" +
165118
"loop\t" + quotedSketchLocation + "\t/^void loop() {}$/;\"\tkind:function\tline:10\tsignature:()\treturntype:void\n" +
166119
"func\t" + quotedSketchLocation + "\t/^typename Foo<char>::Bar func(){$/;\"\tkind:function\tline:12\tsignature:()\treturntype:Foo::Bar\n"
167-
168120
require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1))
169121
}
170122

171123
func TestCTagsRunnerSketchWithNamespace(t *testing.T) {
172-
DownloadCoresAndToolsAndLibraries(t)
173-
174124
sketchLocation := Abs(t, paths.New("sketch_with_namespace", "sketch_with_namespace.ino"))
175-
176-
ctx := &types.Context{
177-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
178-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
179-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
180-
OtherLibrariesDirs: paths.NewPathList("libraries"),
181-
Sketch: OpenSketch(t, sketchLocation),
182-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
183-
Verbose: true,
184-
}
125+
ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo")
126+
ctx.Verbose = true
185127

186128
buildPath := SetupBuildPath(t, ctx)
187129
defer buildPath.RemoveAll()
188130

189131
commands := []types.Command{
190-
191132
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
192-
193133
&builder.ContainerMergeCopySketchFiles{},
194-
195134
&builder.ContainerFindIncludes{},
196-
197135
&builder.PrintUsedLibrariesIfVerbose{},
198136
&builder.WarnAboutArchIncompatibleLibraries{},
199137
&builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: "ctags_target.cpp"},
200138
&builder.CTagsRunner{},
201139
}
202-
203140
for _, command := range commands {
204141
err := command.Run(ctx)
205142
NoError(t, err)
@@ -209,42 +146,26 @@ func TestCTagsRunnerSketchWithNamespace(t *testing.T) {
209146
expectedOutput := "value\t" + quotedSketchLocation + "\t/^\tint value() {$/;\"\tkind:function\tline:2\tnamespace:Test\tsignature:()\treturntype:int\n" +
210147
"setup\t" + quotedSketchLocation + "\t/^void setup() {}$/;\"\tkind:function\tline:7\tsignature:()\treturntype:void\n" +
211148
"loop\t" + quotedSketchLocation + "\t/^void loop() {}$/;\"\tkind:function\tline:8\tsignature:()\treturntype:void\n"
212-
213149
require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1))
214150
}
215151

216152
func TestCTagsRunnerSketchWithTemplates(t *testing.T) {
217-
DownloadCoresAndToolsAndLibraries(t)
218-
219153
sketchLocation := Abs(t, paths.New("sketch_with_templates_and_shift", "sketch_with_templates_and_shift.ino"))
220-
221-
ctx := &types.Context{
222-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
223-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
224-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
225-
OtherLibrariesDirs: paths.NewPathList("libraries"),
226-
Sketch: OpenSketch(t, sketchLocation),
227-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
228-
Verbose: true,
229-
}
154+
ctx := prepareBuilderTestContext(t, nil, sketchLocation, "arduino:avr:leonardo")
155+
ctx.Verbose = true
230156

231157
buildPath := SetupBuildPath(t, ctx)
232158
defer buildPath.RemoveAll()
233159

234160
commands := []types.Command{
235-
236161
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
237-
238162
&builder.ContainerMergeCopySketchFiles{},
239-
240163
&builder.ContainerFindIncludes{},
241-
242164
&builder.PrintUsedLibrariesIfVerbose{},
243165
&builder.WarnAboutArchIncompatibleLibraries{},
244166
&builder.CTagsTargetFileSaver{Source: &ctx.Source, TargetFileName: "ctags_target.cpp"},
245167
&builder.CTagsRunner{},
246168
}
247-
248169
for _, command := range commands {
249170
err := command.Run(ctx)
250171
NoError(t, err)
@@ -255,6 +176,5 @@ func TestCTagsRunnerSketchWithTemplates(t *testing.T) {
255176
"bVar\t" + quotedSketchLocation + "\t/^c< 8 > bVar;$/;\"\tkind:variable\tline:15\n" +
256177
"aVar\t" + quotedSketchLocation + "\t/^c< 1<<8 > aVar;$/;\"\tkind:variable\tline:16\n" +
257178
"func\t" + quotedSketchLocation + "\t/^template<int X> func( c< 1<<X> & aParam) {$/;\"\tkind:function\tline:18\tsignature:( c< 1<<X> & aParam)\treturntype:template\n"
258-
259179
require.Equal(t, expectedOutput, strings.Replace(ctx.CTagsOutput, "\r\n", "\n", -1))
260180
}

‎legacy/builder/test/hardware_loader_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func TestLoadHardware(t *testing.T) {
3434
ctx := &types.Context{
3535
HardwareDirs: paths.NewPathList("downloaded_hardware", filepath.Join("..", "hardware")),
3636
}
37+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
3738

3839
commands := []types.Command{
3940
&builder.HardwareLoader{},
4041
}
41-
4242
for _, command := range commands {
4343
err := command.Run(ctx)
4444
NoError(t, err)
@@ -67,23 +67,18 @@ func TestLoadHardware(t *testing.T) {
6767
require.Equal(t, "/my/personal/avrdude", avrPlatform.Releases["1.6.10"].Properties.Get("tools.avrdude.cmd.path"))
6868

6969
require.Equal(t, "AVRISP mkII", avrPlatform.Releases["1.6.10"].Programmers["avrispmkii"].Name)
70-
71-
//require.Equal(t, "{runtime.tools.ctags.path}", packages.Properties.Get("tools.ctags.path"])
72-
//require.Equal(t, "\"{cmd.path}\" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives \"{source_file}\"", packages.Properties.Get("tools.ctags.pattern"])
73-
//require.Equal(t, "{runtime.tools.avrdude.path}", packages.Properties.Get("tools.avrdude.path"])
74-
//require.Equal(t, "-w -x c++ -E -CC", packages.Properties.Get("preproc.macros.flags"])
7570
}
7671

7772
func TestLoadHardwareMixingUserHardwareFolder(t *testing.T) {
7873
ctx := &types.Context{
7974
HardwareDirs: paths.NewPathList("downloaded_hardware", filepath.Join("..", "hardware"), "user_hardware"),
8075
}
76+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
8177

8278
commands := []types.Command{
8379
&builder.AddAdditionalEntriesToContext{},
8480
&builder.HardwareLoader{},
8581
}
86-
8782
for _, command := range commands {
8883
err := command.Run(ctx)
8984
NoError(t, err)
@@ -146,11 +141,11 @@ func TestLoadHardwareWithBoardManagerFolderStructure(t *testing.T) {
146141
ctx := &types.Context{
147142
HardwareDirs: paths.NewPathList("downloaded_board_manager_stuff"),
148143
}
144+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
149145

150146
commands := []types.Command{
151147
&builder.HardwareLoader{},
152148
}
153-
154149
for _, command := range commands {
155150
err := command.Run(ctx)
156151
NoError(t, err)
@@ -194,11 +189,11 @@ func TestLoadLotsOfHardware(t *testing.T) {
194189
ctx := &types.Context{
195190
HardwareDirs: paths.NewPathList("downloaded_board_manager_stuff", "downloaded_hardware", filepath.Join("..", "hardware"), "user_hardware"),
196191
}
192+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
197193

198194
commands := []types.Command{
199195
&builder.HardwareLoader{},
200196
}
201-
202197
for _, command := range commands {
203198
err := command.Run(ctx)
204199
NoError(t, err)

‎legacy/builder/test/helper.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/arduino/arduino-cli/arduino/cores"
2727
"github.com/arduino/arduino-cli/arduino/libraries"
28-
"github.com/arduino/arduino-cli/arduino/sketch"
2928
"github.com/arduino/arduino-cli/legacy/builder/constants"
3029
"github.com/arduino/arduino-cli/legacy/builder/types"
3130
"github.com/arduino/arduino-cli/legacy/builder/utils"
@@ -84,12 +83,6 @@ func parseFQBN(t *testing.T, fqbnIn string) *cores.FQBN {
8483
return fqbn
8584
}
8685

87-
func OpenSketch(t *testing.T, sketchPath *paths.Path) *sketch.Sketch {
88-
sketch, err := sketch.New(sketchPath)
89-
require.NoError(t, err)
90-
return sketch
91-
}
92-
9386
type ByLibraryName []*libraries.Library
9487

9588
func (s ByLibraryName) Len() int {

‎legacy/builder/test/includes_to_include_folders_test.go

Lines changed: 13 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,17 @@ import (
2727
)
2828

2929
func TestIncludesToIncludeFolders(t *testing.T) {
30-
DownloadCoresAndToolsAndLibraries(t)
31-
32-
ctx := &types.Context{
33-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
34-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
35-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
36-
OtherLibrariesDirs: paths.NewPathList("libraries"),
37-
Sketch: OpenSketch(t, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino")),
38-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
39-
Verbose: true,
40-
}
30+
ctx := prepareBuilderTestContext(t, nil, paths.New("downloaded_libraries", "Bridge", "examples", "Bridge", "Bridge.ino"), "arduino:avr:leonardo")
31+
ctx.Verbose = true
4132

4233
buildPath := SetupBuildPath(t, ctx)
4334
defer buildPath.RemoveAll()
4435

4536
commands := []types.Command{
46-
4737
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
48-
4938
&builder.ContainerMergeCopySketchFiles{},
50-
5139
&builder.ContainerFindIncludes{},
5240
}
53-
5441
for _, command := range commands {
5542
err := command.Run(ctx)
5643
NoError(t, err)
@@ -62,30 +49,17 @@ func TestIncludesToIncludeFolders(t *testing.T) {
6249
}
6350

6451
func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
65-
DownloadCoresAndToolsAndLibraries(t)
66-
67-
ctx := &types.Context{
68-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
69-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
70-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
71-
OtherLibrariesDirs: paths.NewPathList("libraries"),
72-
Sketch: OpenSketch(t, paths.New("SketchWithIfDef", "SketchWithIfDef.ino")),
73-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
74-
Verbose: true,
75-
}
52+
ctx := prepareBuilderTestContext(t, nil, paths.New("SketchWithIfDef", "SketchWithIfDef.ino"), "arduino:avr:leonardo")
53+
ctx.Verbose = true
7654

7755
buildPath := SetupBuildPath(t, ctx)
7856
defer buildPath.RemoveAll()
7957

8058
commands := []types.Command{
81-
8259
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
83-
8460
&builder.ContainerMergeCopySketchFiles{},
85-
8661
&builder.ContainerFindIncludes{},
8762
}
88-
8963
for _, command := range commands {
9064
err := command.Run(ctx)
9165
NoError(t, err)
@@ -96,30 +70,17 @@ func TestIncludesToIncludeFoldersSketchWithIfDef(t *testing.T) {
9670
}
9771

9872
func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
99-
DownloadCoresAndToolsAndLibraries(t)
100-
101-
ctx := &types.Context{
102-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
103-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
104-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
105-
OtherLibrariesDirs: paths.NewPathList("libraries"),
106-
Sketch: OpenSketch(t, paths.New("sketch9", "sketch9.ino")),
107-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
108-
Verbose: true,
109-
}
73+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch9", "sketch9.ino"), "arduino:avr:leonardo")
74+
ctx.Verbose = true
11075

11176
buildPath := SetupBuildPath(t, ctx)
11277
defer buildPath.RemoveAll()
11378

11479
commands := []types.Command{
115-
11680
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
117-
11881
&builder.ContainerMergeCopySketchFiles{},
119-
12082
&builder.ContainerFindIncludes{},
12183
}
122-
12384
for _, command := range commands {
12485
err := command.Run(ctx)
12586
NoError(t, err)
@@ -133,17 +94,8 @@ func TestIncludesToIncludeFoldersIRremoteLibrary(t *testing.T) {
13394
}
13495

13596
func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
136-
DownloadCoresAndToolsAndLibraries(t)
137-
138-
ctx := &types.Context{
139-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
140-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
141-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
142-
OtherLibrariesDirs: paths.NewPathList("libraries"),
143-
Sketch: OpenSketch(t, paths.New("sketch10", "sketch10.ino")),
144-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
145-
Verbose: true,
146-
}
97+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch10", "sketch10.ino"), "arduino:avr:leonardo")
98+
ctx.Verbose = true
14799

148100
buildPath := SetupBuildPath(t, ctx)
149101
defer buildPath.RemoveAll()
@@ -153,7 +105,6 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
153105
&builder.ContainerMergeCopySketchFiles{},
154106
&builder.ContainerFindIncludes{},
155107
}
156-
157108
for _, command := range commands {
158109
err := command.Run(ctx)
159110
NoError(t, err)
@@ -167,29 +118,22 @@ func TestIncludesToIncludeFoldersANewLibrary(t *testing.T) {
167118
}
168119

169120
func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {
170-
DownloadCoresAndToolsAndLibraries(t)
171-
172121
ctx := &types.Context{
173122
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
174123
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
175124
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
176-
Sketch: OpenSketch(t, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino")),
177-
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
178125
Verbose: true,
179126
}
127+
ctx = prepareBuilderTestContext(t, ctx, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), "my_avr_platform:avr:custom_yun")
180128

181129
buildPath := SetupBuildPath(t, ctx)
182130
defer buildPath.RemoveAll()
183131

184132
commands := []types.Command{
185-
186133
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
187-
188134
&builder.ContainerMergeCopySketchFiles{},
189-
190135
&builder.ContainerFindIncludes{},
191136
}
192-
193137
for _, command := range commands {
194138
err := command.Run(ctx)
195139
NoError(t, err)
@@ -203,30 +147,23 @@ func TestIncludesToIncludeFoldersDuplicateLibs(t *testing.T) {
203147
}
204148

205149
func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatform(t *testing.T) {
206-
DownloadCoresAndToolsAndLibraries(t)
207-
208150
ctx := &types.Context{
209151
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
210152
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
211153
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
212154
OtherLibrariesDirs: paths.NewPathList("libraries"),
213-
Sketch: OpenSketch(t, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino")),
214-
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
215155
Verbose: true,
216156
}
157+
ctx = prepareBuilderTestContext(t, ctx, paths.New("user_hardware", "my_avr_platform", "avr", "libraries", "SPI", "examples", "BarometricPressureSensor", "BarometricPressureSensor.ino"), "my_avr_platform:avr:custom_yun")
217158

218159
buildPath := SetupBuildPath(t, ctx)
219160
defer buildPath.RemoveAll()
220161

221162
commands := []types.Command{
222-
223163
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
224-
225164
&builder.ContainerMergeCopySketchFiles{},
226-
227165
&builder.ContainerFindIncludes{},
228166
}
229-
230167
for _, command := range commands {
231168
err := command.Run(ctx)
232169
NoError(t, err)
@@ -240,30 +177,23 @@ func TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatfo
240177
}
241178

242179
func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
243-
DownloadCoresAndToolsAndLibraries(t)
244-
245180
ctx := &types.Context{
246181
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
247182
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
248183
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
249184
OtherLibrariesDirs: paths.NewPathList("libraries"),
250-
Sketch: OpenSketch(t, paths.New("sketch_usbhost", "sketch_usbhost.ino")),
251-
FQBN: parseFQBN(t, "arduino:samd:arduino_zero_native"),
252185
Verbose: true,
253186
}
187+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch_usbhost", "sketch_usbhost.ino"), "arduino:samd:arduino_zero_native")
254188

255189
buildPath := SetupBuildPath(t, ctx)
256190
defer buildPath.RemoveAll()
257191

258192
commands := []types.Command{
259-
260193
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
261-
262194
&builder.ContainerMergeCopySketchFiles{},
263-
264195
&builder.ContainerFindIncludes{},
265196
}
266-
267197
for _, command := range commands {
268198
err := command.Run(ctx)
269199
NoError(t, err)
@@ -277,30 +207,17 @@ func TestIncludesToIncludeFoldersDuplicateLibs2(t *testing.T) {
277207
}
278208

279209
func TestIncludesToIncludeFoldersSubfolders(t *testing.T) {
280-
DownloadCoresAndToolsAndLibraries(t)
281-
282-
ctx := &types.Context{
283-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
284-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
285-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
286-
OtherLibrariesDirs: paths.NewPathList("libraries"),
287-
Sketch: OpenSketch(t, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino")),
288-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
289-
Verbose: true,
290-
}
210+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch_with_subfolders", "sketch_with_subfolders.ino"), "arduino:avr:leonardo")
211+
ctx.Verbose = true
291212

292213
buildPath := SetupBuildPath(t, ctx)
293214
defer buildPath.RemoveAll()
294215

295216
commands := []types.Command{
296-
297217
&builder.ContainerSetupHardwareToolsLibsSketchAndProps{},
298-
299218
&builder.ContainerMergeCopySketchFiles{},
300-
301219
&builder.ContainerFindIncludes{},
302220
}
303-
304221
for _, command := range commands {
305222
err := command.Run(ctx)
306223
NoError(t, err)

‎legacy/builder/test/libraries_loader_test.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,18 @@ func extractLibraries(ctx *types.Context) []*libraries.Library {
3939
}
4040

4141
func TestLoadLibrariesAVR(t *testing.T) {
42-
DownloadCoresAndToolsAndLibraries(t)
43-
4442
ctx := &types.Context{
4543
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
4644
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
4745
OtherLibrariesDirs: paths.NewPathList("libraries"),
48-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
4946
}
47+
ctx = prepareBuilderTestContext(t, ctx, nil, "arduino:avr:leonardo")
5048

5149
commands := []types.Command{
5250
&builder.AddAdditionalEntriesToContext{},
5351
&builder.HardwareLoader{},
54-
&builder.TargetBoardResolver{},
5552
&builder.LibrariesLoader{},
5653
}
57-
5854
for _, command := range commands {
5955
err := command.Run(ctx)
6056
NoError(t, err)
@@ -149,22 +145,18 @@ func TestLoadLibrariesAVR(t *testing.T) {
149145
}
150146

151147
func TestLoadLibrariesSAM(t *testing.T) {
152-
DownloadCoresAndToolsAndLibraries(t)
153-
154148
ctx := &types.Context{
155149
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
156150
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
157151
OtherLibrariesDirs: paths.NewPathList("libraries"),
158-
FQBN: parseFQBN(t, "arduino:sam:arduino_due_x_dbg"),
159152
}
153+
ctx = prepareBuilderTestContext(t, ctx, nil, "arduino:sam:arduino_due_x_dbg")
160154

161155
commands := []types.Command{
162156
&builder.AddAdditionalEntriesToContext{},
163157
&builder.HardwareLoader{},
164-
&builder.TargetBoardResolver{},
165158
&builder.LibrariesLoader{},
166159
}
167-
168160
for _, command := range commands {
169161
err := command.Run(ctx)
170162
NoError(t, err)
@@ -232,22 +224,17 @@ func TestLoadLibrariesSAM(t *testing.T) {
232224
}
233225

234226
func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) {
235-
DownloadCoresAndToolsAndLibraries(t)
236-
237227
ctx := &types.Context{
238228
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
239229
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
240230
OtherLibrariesDirs: paths.NewPathList("libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")),
241-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
242231
}
232+
ctx = prepareBuilderTestContext(t, ctx, nil, "arduino:avr:leonardo")
243233

244234
commands := []types.Command{
245235
&builder.AddAdditionalEntriesToContext{},
246-
&builder.HardwareLoader{},
247-
&builder.TargetBoardResolver{},
248236
&builder.LibrariesLoader{},
249237
}
250-
251238
for _, command := range commands {
252239
err := command.Run(ctx)
253240
NoError(t, err)
@@ -261,22 +248,18 @@ func TestLoadLibrariesAVRNoDuplicateLibrariesFolders(t *testing.T) {
261248
}
262249

263250
func TestLoadLibrariesMyAVRPlatform(t *testing.T) {
264-
DownloadCoresAndToolsAndLibraries(t)
265-
266251
ctx := &types.Context{
267252
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "user_hardware", "downloaded_hardware"),
268253
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
269254
OtherLibrariesDirs: paths.NewPathList("libraries", filepath.Join("downloaded_hardware", "arduino", "avr", "libraries")),
270-
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
271255
}
256+
ctx = prepareBuilderTestContext(t, ctx, nil, "my_avr_platform:avr:custom_yun")
272257

273258
commands := []types.Command{
274259
&builder.AddAdditionalEntriesToContext{},
275260
&builder.HardwareLoader{},
276-
&builder.TargetBoardResolver{},
277261
&builder.LibrariesLoader{},
278262
}
279-
280263
for _, command := range commands {
281264
err := command.Run(ctx)
282265
NoError(t, err)

‎legacy/builder/test/merge_sketch_with_bootloader_test.go

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,7 @@ import (
2929
)
3030

3131
func TestMergeSketchWithBootloader(t *testing.T) {
32-
DownloadCoresAndToolsAndLibraries(t)
33-
34-
ctx := &types.Context{
35-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
36-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
37-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
38-
OtherLibrariesDirs: paths.NewPathList("libraries"),
39-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
40-
FQBN: parseFQBN(t, "arduino:avr:uno"),
41-
}
32+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
4233

4334
buildPath := SetupBuildPath(t, ctx)
4435
defer buildPath.RemoveAll()
@@ -98,16 +89,7 @@ func TestMergeSketchWithBootloader(t *testing.T) {
9889
}
9990

10091
func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {
101-
DownloadCoresAndToolsAndLibraries(t)
102-
103-
ctx := &types.Context{
104-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
105-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
106-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
107-
OtherLibrariesDirs: paths.NewPathList("libraries"),
108-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
109-
FQBN: parseFQBN(t, "arduino:avr:uno"),
110-
}
92+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
11193

11294
buildPath := SetupBuildPath(t, ctx)
11395
defer buildPath.RemoveAll()
@@ -168,16 +150,7 @@ func TestMergeSketchWithBootloaderSketchInBuildPath(t *testing.T) {
168150
}
169151

170152
func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {
171-
DownloadCoresAndToolsAndLibraries(t)
172-
173-
ctx := &types.Context{
174-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
175-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
176-
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
177-
OtherLibrariesDirs: paths.NewPathList("libraries"),
178-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
179-
FQBN: parseFQBN(t, "arduino:avr:uno"),
180-
}
153+
ctx := prepareBuilderTestContext(t, nil, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
181154

182155
buildPath := SetupBuildPath(t, ctx)
183156
defer buildPath.RemoveAll()
@@ -205,16 +178,13 @@ func TestMergeSketchWithBootloaderWhenNoBootloaderAvailable(t *testing.T) {
205178
}
206179

207180
func TestMergeSketchWithBootloaderPathIsParameterized(t *testing.T) {
208-
DownloadCoresAndToolsAndLibraries(t)
209-
210181
ctx := &types.Context{
211182
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
212183
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
213184
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
214185
OtherLibrariesDirs: paths.NewPathList("libraries"),
215-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
216-
FQBN: parseFQBN(t, "my_avr_platform:avr:mymega:cpu=atmega2560"),
217186
}
187+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "my_avr_platform:avr:mymega:cpu=atmega2560")
218188

219189
buildPath := SetupBuildPath(t, ctx)
220190
defer buildPath.RemoveAll()

‎legacy/builder/test/prototypes_adder_test.go

Lines changed: 40 additions & 237 deletions
Large diffs are not rendered by default.

‎legacy/builder/test/setup_build_properties_test.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,19 @@ import (
2626
)
2727

2828
func TestSetupBuildProperties(t *testing.T) {
29-
DownloadCoresAndToolsAndLibraries(t)
30-
3129
ctx := &types.Context{
3230
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
3331
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
34-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
35-
FQBN: parseFQBN(t, "arduino:avr:uno"),
3632
}
37-
33+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
3834
buildPath := SetupBuildPath(t, ctx)
3935
defer buildPath.RemoveAll()
4036

4137
commands := []types.Command{
4238
&builder.AddAdditionalEntriesToContext{},
4339
&builder.HardwareLoader{},
44-
&builder.TargetBoardResolver{},
4540
&builder.SetupBuildProperties{},
4641
}
47-
4842
for _, command := range commands {
4943
err := command.Run(ctx)
5044
NoError(t, err)
@@ -89,24 +83,19 @@ func TestSetupBuildProperties(t *testing.T) {
8983
}
9084

9185
func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) {
92-
DownloadCoresAndToolsAndLibraries(t)
93-
9486
ctx := &types.Context{
95-
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
96-
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
97-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
98-
FQBN: parseFQBN(t, "arduino:avr:uno"),
99-
87+
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware"),
88+
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
10089
CustomBuildProperties: []string{"name=fake name", "tools.avrdude.config.path=non existent path with space and a ="},
10190
}
91+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "arduino:avr:uno")
10292

10393
buildPath := SetupBuildPath(t, ctx)
10494
defer buildPath.RemoveAll()
10595

10696
commands := []types.Command{
10797
&builder.AddAdditionalEntriesToContext{},
10898
&builder.HardwareLoader{},
109-
&builder.TargetBoardResolver{},
11099
&builder.SetupBuildProperties{},
111100
&builder.SetCustomBuildProperties{},
112101
}
@@ -127,25 +116,19 @@ func TestSetupBuildPropertiesWithSomeCustomOverrides(t *testing.T) {
127116
}
128117

129118
func TestSetupBuildPropertiesUserHardware(t *testing.T) {
130-
DownloadCoresAndToolsAndLibraries(t)
131-
132119
ctx := &types.Context{
133120
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
134121
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
135-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
136-
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
137122
}
138-
123+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "my_avr_platform:avr:custom_yun")
139124
buildPath := SetupBuildPath(t, ctx)
140125
defer buildPath.RemoveAll()
141126

142127
commands := []types.Command{
143128
&builder.AddAdditionalEntriesToContext{},
144129
&builder.HardwareLoader{},
145-
&builder.TargetBoardResolver{},
146130
&builder.SetupBuildProperties{},
147131
}
148-
149132
for _, command := range commands {
150133
err := command.Run(ctx)
151134
NoError(t, err)
@@ -162,15 +145,11 @@ func TestSetupBuildPropertiesUserHardware(t *testing.T) {
162145
}
163146

164147
func TestSetupBuildPropertiesWithMissingPropsFromParentPlatformTxtFiles(t *testing.T) {
165-
DownloadCoresAndToolsAndLibraries(t)
166-
167148
ctx := &types.Context{
168149
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "user_hardware"),
169150
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
170-
Sketch: OpenSketch(t, paths.New("sketch1", "sketch1.ino")),
171-
FQBN: parseFQBN(t, "my_avr_platform:avr:custom_yun"),
172151
}
173-
152+
ctx = prepareBuilderTestContext(t, ctx, paths.New("sketch1", "sketch1.ino"), "my_avr_platform:avr:custom_yun")
174153
buildPath := SetupBuildPath(t, ctx)
175154
defer buildPath.RemoveAll()
176155

‎legacy/builder/test/tools_loader_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ func requireEquivalentPaths(t *testing.T, actual string, expected ...string) {
6262
}
6363

6464
func TestLoadTools(t *testing.T) {
65-
DownloadCoresAndToolsAndLibraries(t)
66-
6765
ctx := &types.Context{
6866
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
6967
}
68+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
7069

7170
NoError(t, (&builder.HardwareLoader{}).Run(ctx))
7271

@@ -105,10 +104,10 @@ func TestLoadTools(t *testing.T) {
105104
}
106105

107106
func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) {
108-
DownloadCoresAndToolsAndLibraries(t)
109107
ctx := &types.Context{
110108
HardwareDirs: paths.NewPathList("downloaded_board_manager_stuff"),
111109
}
110+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
112111

113112
NoError(t, (&builder.HardwareLoader{}).Run(ctx))
114113

@@ -129,12 +128,11 @@ func TestLoadToolsWithBoardManagerFolderStructure(t *testing.T) {
129128
}
130129

131130
func TestLoadLotsOfTools(t *testing.T) {
132-
DownloadCoresAndToolsAndLibraries(t)
133-
134131
ctx := &types.Context{
135132
HardwareDirs: paths.NewPathList("downloaded_board_manager_stuff"),
136133
BuiltInToolsDirs: paths.NewPathList("downloaded_tools", "tools_builtin"),
137134
}
135+
ctx = prepareBuilderTestContext(t, ctx, nil, "")
138136

139137
NoError(t, (&builder.HardwareLoader{}).Run(ctx))
140138

‎legacy/builder/test/try_build_of_problematic_sketch_test.go

Lines changed: 62 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,223 +26,215 @@ import (
2626
)
2727

2828
func TestTryBuild001(t *testing.T) {
29-
tryBuild(t, "sketch_with_inline_function", "sketch_with_inline_function.ino")
29+
tryBuild(t, paths.New("sketch_with_inline_function", "sketch_with_inline_function.ino"))
3030
}
3131

3232
func TestTryBuild002(t *testing.T) {
33-
tryBuild(t, "sketch_with_function_signature_inside_ifdef", "sketch_with_function_signature_inside_ifdef.ino")
33+
tryBuild(t, paths.New("sketch_with_function_signature_inside_ifdef", "sketch_with_function_signature_inside_ifdef.ino"))
3434
}
3535

3636
func TestTryBuild003(t *testing.T) {
37-
tryPreprocess(t, "sketch_no_functions", "sketch_no_functions.ino")
37+
tryPreprocess(t, paths.New("sketch_no_functions", "sketch_no_functions.ino"))
3838
}
3939

4040
func TestTryBuild004(t *testing.T) {
41-
tryBuild(t, "sketch_with_const", "sketch_with_const.ino")
41+
tryBuild(t, paths.New("sketch_with_const", "sketch_with_const.ino"))
4242
}
4343

4444
func TestTryBuild005(t *testing.T) {
45-
tryBuild(t, "sketch_with_old_lib", "sketch_with_old_lib.ino")
45+
tryBuild(t, paths.New("sketch_with_old_lib", "sketch_with_old_lib.ino"))
4646
}
4747

4848
func TestTryBuild006(t *testing.T) {
49-
tryBuild(t, "sketch_with_macosx_garbage", "sketch_with_macosx_garbage.ino")
49+
tryBuild(t, paths.New("sketch_with_macosx_garbage", "sketch_with_macosx_garbage.ino"))
5050
}
5151

5252
func TestTryBuild007(t *testing.T) {
53-
tryBuild(t, "sketch_with_config", "sketch_with_config.ino")
53+
tryBuild(t, paths.New("sketch_with_config", "sketch_with_config.ino"))
5454
}
5555

5656
// XXX: Failing sketch, typename not supported
5757
//func TestTryBuild008(t *testing.T) {
58-
// tryBuild(t, "sketch_with_typename", "sketch.ino")
58+
// tryBuild(t, paths.New("sketch_with_typename", "sketch.ino"))
5959
//}
6060

6161
func TestTryBuild009(t *testing.T) {
62-
tryBuild(t, "sketch_with_usbcon", "sketch_with_usbcon.ino")
62+
tryBuild(t, paths.New("sketch_with_usbcon", "sketch_with_usbcon.ino"))
6363
}
6464

6565
func TestTryBuild010(t *testing.T) {
66-
tryBuild(t, "sketch_with_namespace", "sketch_with_namespace.ino")
66+
tryBuild(t, paths.New("sketch_with_namespace", "sketch_with_namespace.ino"))
6767
}
6868

6969
func TestTryBuild011(t *testing.T) {
70-
tryBuild(t, "sketch_with_inline_function", "sketch_with_inline_function.ino")
70+
tryBuild(t, paths.New("sketch_with_inline_function", "sketch_with_inline_function.ino"))
7171
}
7272

7373
func TestTryBuild012(t *testing.T) {
74-
tryBuild(t, "sketch_with_default_args", "sketch_with_default_args.ino")
74+
tryBuild(t, paths.New("sketch_with_default_args", "sketch_with_default_args.ino"))
7575
}
7676

7777
func TestTryBuild013(t *testing.T) {
78-
tryBuild(t, "sketch_with_class", "sketch_with_class.ino")
78+
tryBuild(t, paths.New("sketch_with_class", "sketch_with_class.ino"))
7979
}
8080

8181
func TestTryBuild014(t *testing.T) {
82-
tryBuild(t, "sketch_with_backup_files", "sketch_with_backup_files.ino")
82+
tryBuild(t, paths.New("sketch_with_backup_files", "sketch_with_backup_files.ino"))
8383
}
8484

8585
func TestTryBuild015(t *testing.T) {
86-
tryBuild(t, "sketch_with_subfolders")
86+
tryBuild(t, paths.New("sketch_with_subfolders"))
8787
}
8888

8989
// This is a sketch that fails to build on purpose
9090
//func TestTryBuild016(t *testing.T) {
91-
// tryBuild(t, "sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino")
91+
// tryBuild(t, paths.New("sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino"))
9292
//}
9393

9494
func TestTryBuild017(t *testing.T) {
95-
tryPreprocess(t, "sketch_no_functions_two_files", "sketch_no_functions_two_files.ino")
95+
tryPreprocess(t, paths.New("sketch_no_functions_two_files", "sketch_no_functions_two_files.ino"))
9696
}
9797

9898
func TestTryBuild018(t *testing.T) {
99-
tryBuild(t, "sketch_that_checks_if_SPI_has_transactions", "sketch_that_checks_if_SPI_has_transactions.ino")
99+
tryBuild(t, paths.New("sketch_that_checks_if_SPI_has_transactions", "sketch_that_checks_if_SPI_has_transactions.ino"))
100100
}
101101

102102
func TestTryBuild019(t *testing.T) {
103-
tryBuild(t, "sketch_with_ifdef", "sketch_with_ifdef.ino")
103+
tryBuild(t, paths.New("sketch_with_ifdef", "sketch_with_ifdef.ino"))
104104
}
105105

106106
func TestTryBuild020(t *testing.T) {
107-
ctx := makeDefaultContext(t)
107+
ctx := makeDefaultContext()
108108
ctx.OtherLibrariesDirs = paths.NewPathList("dependent_libraries", "libraries")
109-
tryPreprocessWithContext(t, ctx, "sketch_with_dependend_libraries", "sketch_with_dependend_libraries.ino")
109+
tryPreprocessWithContext(t, ctx, "arduino:avr:leonardo", paths.New("sketch_with_dependend_libraries", "sketch_with_dependend_libraries.ino"))
110110
}
111111

112112
func TestTryBuild021(t *testing.T) {
113-
tryBuild(t, "sketch_with_function_pointer", "sketch_with_function_pointer.ino")
113+
tryBuild(t, paths.New("sketch_with_function_pointer", "sketch_with_function_pointer.ino"))
114114
}
115115

116116
func TestTryBuild022(t *testing.T) {
117-
ctx := makeDefaultContext(t)
118-
ctx.FQBN = parseFQBN(t, "arduino:samd:arduino_zero_native")
119-
tryBuildWithContext(t, ctx, "sketch_usbhost", "sketch_usbhost.ino")
117+
ctx := makeDefaultContext()
118+
tryBuildWithContext(t, ctx, "arduino:samd:arduino_zero_native", paths.New("sketch_usbhost", "sketch_usbhost.ino"))
120119
}
121120

122121
func TestTryBuild023(t *testing.T) {
123-
tryBuild(t, "sketch1", "sketch1.ino")
122+
tryBuild(t, paths.New("sketch1", "sketch1.ino"))
124123
}
125124

126125
func TestTryBuild024(t *testing.T) {
127-
tryBuild(t, "SketchWithIfDef", "SketchWithIfDef.ino")
126+
tryBuild(t, paths.New("SketchWithIfDef", "SketchWithIfDef.ino"))
128127
}
129128

130129
// The library for this sketch is missing
131130
//func TestTryBuild025(t *testing.T) {
132-
// tryBuild(t, "sketch3", "Baladuino.ino")
131+
// tryBuild(t, paths.New("sketch3", "Baladuino.ino"))
133132
//}
134133

135134
func TestTryBuild026(t *testing.T) {
136-
tryBuild(t, "CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino")
135+
tryBuild(t, paths.New("CharWithEscapedDoubleQuote", "CharWithEscapedDoubleQuote.ino"))
137136
}
138137

139138
func TestTryBuild027(t *testing.T) {
140-
tryBuild(t, "IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino")
139+
tryBuild(t, paths.New("IncludeBetweenMultilineComment", "IncludeBetweenMultilineComment.ino"))
141140
}
142141

143142
func TestTryBuild028(t *testing.T) {
144-
tryBuild(t, "LineContinuations", "LineContinuations.ino")
143+
tryBuild(t, paths.New("LineContinuations", "LineContinuations.ino"))
145144
}
146145

147146
func TestTryBuild029(t *testing.T) {
148-
tryBuild(t, "StringWithComment", "StringWithComment.ino")
147+
tryBuild(t, paths.New("StringWithComment", "StringWithComment.ino"))
149148
}
150149

151150
func TestTryBuild030(t *testing.T) {
152-
tryBuild(t, "SketchWithStruct", "SketchWithStruct.ino")
151+
tryBuild(t, paths.New("SketchWithStruct", "SketchWithStruct.ino"))
153152
}
154153

155154
func TestTryBuild031(t *testing.T) {
156-
tryBuild(t, "sketch9", "sketch9.ino")
155+
tryBuild(t, paths.New("sketch9", "sketch9.ino"))
157156
}
158157

159158
func TestTryBuild032(t *testing.T) {
160-
tryBuild(t, "sketch10", "sketch10.ino")
159+
tryBuild(t, paths.New("sketch10", "sketch10.ino"))
161160
}
162161

163162
func TestTryBuild033(t *testing.T) {
164-
tryBuild(t, "sketch_that_includes_arduino_h", "sketch_that_includes_arduino_h.ino")
163+
tryBuild(t, paths.New("sketch_that_includes_arduino_h", "sketch_that_includes_arduino_h.ino"))
165164
}
166165

167166
func TestTryBuild034(t *testing.T) {
168-
tryBuild(t, "sketch_with_static_asserts", "sketch_with_static_asserts.ino")
167+
tryBuild(t, paths.New("sketch_with_static_asserts", "sketch_with_static_asserts.ino"))
169168
}
170169

171170
func TestTryBuild035(t *testing.T) {
172-
tryBuild(t, "sketch_with_enum_class", "sketch_with_enum_class.ino")
171+
tryBuild(t, paths.New("sketch_with_enum_class", "sketch_with_enum_class.ino"))
173172
}
174173

175174
func TestTryBuild036(t *testing.T) {
176-
ctx := makeDefaultContext(t)
177-
ctx.FQBN = parseFQBN(t, "arduino:samd:arduino_zero_native")
178-
tryBuildWithContext(t, ctx, "sketch_fastleds", "sketch_fastleds.ino")
175+
ctx := makeDefaultContext()
176+
tryBuildWithContext(t, ctx, "arduino:samd:arduino_zero_native", paths.New("sketch_fastleds", "sketch_fastleds.ino"))
179177
}
180178

181179
func TestTryBuild037(t *testing.T) {
182-
tryBuild(t, "sketch_with_externC", "sketch_with_externC.ino")
180+
tryBuild(t, paths.New("sketch_with_externC", "sketch_with_externC.ino"))
183181
}
184182

185183
func TestTryBuild038(t *testing.T) {
186-
tryBuild(t, "sketch_with_multiline_prototypes", "sketch_with_multiline_prototypes.ino")
184+
tryBuild(t, paths.New("sketch_with_multiline_prototypes", "sketch_with_multiline_prototypes.ino"))
187185
}
188186

189187
func TestTryBuild039(t *testing.T) {
190-
ctx := makeDefaultContext(t)
191-
ctx.FQBN = parseFQBN(t, "arduino:samd:arduino_zero_native")
192-
tryBuildWithContext(t, ctx, "sketch12", "sketch12.ino")
188+
ctx := makeDefaultContext()
189+
tryBuildWithContext(t, ctx, "arduino:samd:arduino_zero_native", paths.New("sketch12", "sketch12.ino"))
193190
}
194191

195192
func TestTryBuild040(t *testing.T) {
196-
tryBuild(t, "sketch_with_externC_multiline", "sketch_with_externC_multiline.ino")
193+
tryBuild(t, paths.New("sketch_with_externC_multiline", "sketch_with_externC_multiline.ino"))
197194
}
198195

199196
func TestTryBuild041(t *testing.T) {
200-
tryBuild(t, "sketch_with_multiline_template", "sketch_with_multiline_template.ino")
197+
tryBuild(t, paths.New("sketch_with_multiline_template", "sketch_with_multiline_template.ino"))
201198
}
202199

203200
func TestTryBuild042(t *testing.T) {
204-
tryBuild(t, "sketch_with_fake_function_pointer", "sketch_with_fake_function_pointer.ino")
201+
tryBuild(t, paths.New("sketch_with_fake_function_pointer", "sketch_with_fake_function_pointer.ino"))
205202
}
206203

207-
func makeDefaultContext(t *testing.T) *types.Context {
208-
DownloadCoresAndToolsAndLibraries(t)
209-
210-
ctx := &types.Context{
204+
func makeDefaultContext() *types.Context {
205+
return &types.Context{
211206
HardwareDirs: paths.NewPathList(filepath.Join("..", "hardware"), "downloaded_hardware", "downloaded_board_manager_stuff"),
212207
BuiltInToolsDirs: paths.NewPathList("downloaded_tools"),
213208
BuiltInLibrariesDirs: paths.New("downloaded_libraries"),
214209
OtherLibrariesDirs: paths.NewPathList("libraries"),
215-
FQBN: parseFQBN(t, "arduino:avr:leonardo"),
216210
Verbose: true,
217211
DebugPreprocessor: true,
218212
}
219-
buildPath := SetupBuildPath(t, ctx)
220-
defer buildPath.RemoveAll()
221-
222-
return ctx
223213
}
224214

225-
func tryBuild(t *testing.T, sketchPath ...string) {
226-
ctx := makeDefaultContext(t)
227-
tryBuildWithContext(t, ctx, sketchPath...)
215+
func tryBuild(t *testing.T, sketchLocation *paths.Path) {
216+
tryBuildWithContext(t, makeDefaultContext(), "arduino:avr:leonardo", sketchLocation)
228217
}
229218

230-
func tryBuildWithContext(t *testing.T, ctx *types.Context, sketchPath ...string) {
231-
sketchLocation := paths.New(sketchPath...)
232-
ctx.Sketch = OpenSketch(t, sketchLocation)
219+
func tryBuildWithContext(t *testing.T, ctx *types.Context, fqbn string, sketchLocation *paths.Path) {
220+
ctx = prepareBuilderTestContext(t, ctx, sketchLocation, fqbn)
221+
222+
buildPath := SetupBuildPath(t, ctx)
223+
defer buildPath.RemoveAll()
233224

234225
err := builder.RunBuilder(ctx)
235226
NoError(t, err, "Build error for "+sketchLocation.String())
236227
}
237228

238-
func tryPreprocess(t *testing.T, sketchPath ...string) {
239-
ctx := makeDefaultContext(t)
240-
tryPreprocessWithContext(t, ctx, sketchPath...)
229+
func tryPreprocess(t *testing.T, sketchLocation *paths.Path) {
230+
tryPreprocessWithContext(t, makeDefaultContext(), "arduino:avr:leonardo", sketchLocation)
241231
}
242232

243-
func tryPreprocessWithContext(t *testing.T, ctx *types.Context, sketchPath ...string) {
244-
sketchLocation := paths.New(sketchPath...)
245-
ctx.Sketch = OpenSketch(t, sketchLocation)
233+
func tryPreprocessWithContext(t *testing.T, ctx *types.Context, fqbn string, sketchLocation *paths.Path) {
234+
ctx = prepareBuilderTestContext(t, ctx, sketchLocation, fqbn)
235+
236+
buildPath := SetupBuildPath(t, ctx)
237+
defer buildPath.RemoveAll()
246238

247239
err := builder.RunPreprocess(ctx)
248240
NoError(t, err, "Build error for "+sketchLocation.String())

0 commit comments

Comments
 (0)
Please sign in to comment.