Skip to content

Commit 6e329eb

Browse files
Use subtest to manually install core once
1 parent 2ce001d commit 6e329eb

File tree

2 files changed

+61
-84
lines changed

2 files changed

+61
-84
lines changed

internal/integrationtest/compile/compile_part_3_test.go

+61-42
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ import (
2525
"gopkg.in/src-d/go-git.v4/plumbing"
2626
)
2727

28+
func TestCompilePart3(t *testing.T) {
29+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
30+
defer env.CleanUp()
31+
32+
_, _, err := cli.Run("update")
33+
require.NoError(t, err)
34+
35+
// Manually installs a core in sketchbooks hardware folder
36+
gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
37+
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
38+
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
39+
URL: gitUrl,
40+
ReferenceName: plumbing.NewTagReferenceName("1.8.3"),
41+
})
42+
require.NoError(t, err)
43+
44+
// Installs also the same core via CLI so all the necessary tools are installed
45+
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
46+
require.NoError(t, err)
47+
48+
integrationtest.CLISubtests{
49+
{"ManuallyInstalledPlatform", compileManuallyInstalledPlatform},
50+
{"ManuallyInstalledPlatformUsingPlatformLocalTxt", compileManuallyInstalledPlatformUsingPlatformLocalTxt},
51+
{"ManuallyInstalledPlatformUsingBoardsLocalTxt", compileManuallyInstalledPlatformUsingBoardsLocalTxt},
52+
}.Run(t, env, cli)
53+
}
54+
2855
func TestCompileWithFullyPrecompiledLibrary(t *testing.T) {
2956
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
3057
defer env.CleanUp()
@@ -61,73 +88,65 @@ func TestCompileWithFullyPrecompiledLibrary(t *testing.T) {
6188
require.Contains(t, string(stdout), "Skipping dependencies detection for precompiled library Arduino_TensorFlowLite")
6289
}
6390

64-
func TestCompileManuallyInstalledPlatform(t *testing.T) {
65-
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
66-
defer env.CleanUp()
67-
68-
_, _, err := cli.Run("update")
69-
require.NoError(t, err)
70-
91+
func compileManuallyInstalledPlatform(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
7192
sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt"
7293
sketchPath := cli.SketchbookDir().Join(sketchName)
94+
defer sketchPath.RemoveAll()
7395
fqbn := "arduino-beta-development:avr:uno"
74-
_, _, err = cli.Run("sketch", "new", sketchPath.String())
75-
require.NoError(t, err)
76-
77-
// Manually installs a core in sketchbooks hardware folder
78-
gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
79-
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
80-
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
81-
URL: gitUrl,
82-
ReferenceName: plumbing.NewTagReferenceName("1.8.3"),
83-
})
84-
require.NoError(t, err)
85-
86-
// Installs also the same core via CLI so all the necessary tools are installed
87-
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
96+
_, _, err := cli.Run("sketch", "new", sketchPath.String())
8897
require.NoError(t, err)
8998

9099
// Verifies compilation works without issues
91100
_, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
92101
require.NoError(t, err)
93102
}
94103

95-
func TestCompileManuallyInstalledPlatformUsingPlatformLocalTxt(t *testing.T) {
96-
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
97-
defer env.CleanUp()
98-
99-
_, _, err := cli.Run("update")
100-
require.NoError(t, err)
101-
104+
func compileManuallyInstalledPlatformUsingPlatformLocalTxt(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
102105
sketchName := "CompileSketchManuallyInstalledPlatformUsingPlatformLocalTxt"
103106
sketchPath := cli.SketchbookDir().Join(sketchName)
107+
defer sketchPath.RemoveAll()
104108
fqbn := "arduino-beta-development:avr:uno"
105-
_, _, err = cli.Run("sketch", "new", sketchPath.String())
106-
require.NoError(t, err)
107-
108-
// Manually installs a core in sketchbooks hardware folder
109-
gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
110-
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
111-
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
112-
URL: gitUrl,
113-
ReferenceName: plumbing.NewTagReferenceName("1.8.3"),
114-
})
115-
require.NoError(t, err)
116-
117-
// Installs also the same core via CLI so all the necessary tools are installed
118-
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
109+
_, _, err := cli.Run("sketch", "new", sketchPath.String())
119110
require.NoError(t, err)
120111

121112
// Verifies compilation works without issues
122113
_, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
123114
require.NoError(t, err)
124115

125116
// Overrides default platform compiler with an unexisting one
117+
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
126118
platformLocalTxt := repoDir.Join("platform.local.txt")
119+
defer platformLocalTxt.Remove()
127120
platformLocalTxt.WriteFile([]byte("compiler.c.cmd=my-compiler-that-does-not-exist"))
128121

129122
// Verifies compilation now fails because compiler is not found
130123
_, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
131124
require.Error(t, err)
132125
require.Contains(t, string(stderr), "my-compiler-that-does-not-exist")
133126
}
127+
128+
func compileManuallyInstalledPlatformUsingBoardsLocalTxt(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
129+
sketchName := "CompileSketchManuallyInstalledPlatformUsingBoardsLocalTxt"
130+
sketchPath := cli.SketchbookDir().Join(sketchName)
131+
defer sketchPath.RemoveAll()
132+
fqbn := "arduino-beta-development:avr:nessuno"
133+
_, _, err := cli.Run("sketch", "new", sketchPath.String())
134+
require.NoError(t, err)
135+
136+
// Verifies compilation fails because board doesn't exist
137+
_, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
138+
require.Error(t, err)
139+
require.Contains(t, string(stderr), "Error during build: Error resolving FQBN: board arduino-beta-development:avr:nessuno not found")
140+
141+
// Use custom boards.local.txt with made arduino:avr:nessuno board
142+
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
143+
boardsLocalTxt := repoDir.Join("boards.local.txt")
144+
defer boardsLocalTxt.Remove()
145+
wd, err := paths.Getwd()
146+
require.NoError(t, err)
147+
err = wd.Parent().Join("testdata", "boards.local.txt").CopyTo(boardsLocalTxt)
148+
require.NoError(t, err)
149+
150+
_, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
151+
require.NoError(t, err)
152+
}

internal/integrationtest/compile/compile_part_4_test.go

-42
Original file line numberDiff line numberDiff line change
@@ -163,48 +163,6 @@ func recompileWithDifferentLibrary(t *testing.T, env *integrationtest.Environmen
163163
require.NotContains(t, string(stdout), "Using previously compiled file: "+objPath.String())
164164
}
165165

166-
func TestCompileManuallyInstalledPlatformUsingBoardsLocalTxt(t *testing.T) {
167-
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
168-
defer env.CleanUp()
169-
170-
_, _, err := cli.Run("update")
171-
require.NoError(t, err)
172-
173-
sketchName := "CompileSketchManuallyInstalledPlatformUsingBoardsLocalTxt"
174-
sketchPath := cli.SketchbookDir().Join(sketchName)
175-
fqbn := "arduino-beta-development:avr:nessuno"
176-
_, _, err = cli.Run("sketch", "new", sketchPath.String())
177-
require.NoError(t, err)
178-
179-
// Manually installs a core in sketchbooks hardware folder
180-
gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
181-
repoDir := cli.SketchbookDir().Join("hardware", "arduino-beta-development", "avr")
182-
_, err = git.PlainClone(repoDir.String(), false, &git.CloneOptions{
183-
URL: gitUrl,
184-
ReferenceName: plumbing.NewTagReferenceName("1.8.3"),
185-
})
186-
require.NoError(t, err)
187-
188-
// Installs also the same core via CLI so all the necessary tools are installed
189-
_, _, err = cli.Run("core", "install", "arduino:[email protected]")
190-
require.NoError(t, err)
191-
192-
// Verifies compilation fails because board doesn't exist
193-
_, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
194-
require.Error(t, err)
195-
require.Contains(t, string(stderr), "Error during build: Error resolving FQBN: board arduino-beta-development:avr:nessuno not found")
196-
197-
// Use custom boards.local.txt with made arduino:avr:nessuno board
198-
boardsLocalTxt := repoDir.Join("boards.local.txt")
199-
wd, err := paths.Getwd()
200-
require.NoError(t, err)
201-
err = wd.Parent().Join("testdata", "boards.local.txt").CopyTo(boardsLocalTxt)
202-
require.NoError(t, err)
203-
204-
_, _, err = cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
205-
require.NoError(t, err)
206-
}
207-
208166
func TestCompileWithConflictingLibrariesInclude(t *testing.T) {
209167
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
210168
defer env.CleanUp()

0 commit comments

Comments
 (0)