Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1c110e9

Browse filesBrowse files
authored
[skip-changelog] Porting legacy tests to new integration-test infra (part 3...) (#2300)
* Ported TestCoreCaching to current integration test infra * Removed useless TestBuilderEmptySketch The same features are already tested in a number of other integration tests. * Ported TestBuilderWithBuildPathInSketchDir to current integration test infra * Ported TestLoadHardware to current integration test infra * Moved user_hardware testdata resources * Ported TestLoadHardwareMixingUserHardwareFolder to current integration test infra * Removed redundant legacy tests * Removed useless 'sleep' helper function * Removed unused LoadAndInterpolate function * Removed useless NoError helper function * Grouped tests inside the same correct sub-group * Ported TestFailIfBuildPathEqualsSketchPath and TestFailIfBuildPathEqualsSketchPathSketchPathDiffers to current integration test infra
1 parent 67f461e commit 1c110e9
Copy full SHA for 1c110e9
Expand file treeCollapse file tree

32 files changed

+454
-492
lines changed
+251Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package board_test
17+
18+
import (
19+
"runtime"
20+
"testing"
21+
22+
"github.com/arduino/arduino-cli/internal/integrationtest"
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/stretchr/testify/require"
25+
"go.bug.st/testifyjson/requirejson"
26+
)
27+
28+
func TestHardwareLoading(t *testing.T) {
29+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
30+
defer env.CleanUp()
31+
32+
// install two cores, boards must be ordered by package name and platform name
33+
_, _, err := cli.Run("core", "install", "arduino:avr@1.8.6")
34+
require.NoError(t, err)
35+
// _, _, err = cli.Run("core", "install", "arduino:sam")
36+
// require.NoError(t, err)
37+
38+
localTxt, err := paths.New("testdata", "custom_local_txts").Abs()
39+
require.NoError(t, err)
40+
downloadedHardwareAvr := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6")
41+
localTxt.Join("boards.local.txt").CopyTo(downloadedHardwareAvr.Join("boards.local.txt"))
42+
localTxt.Join("platform.local.txt").CopyTo(downloadedHardwareAvr.Join("platform.local.txt"))
43+
44+
t.Run("Simple", func(t *testing.T) {
45+
{
46+
out, _, err := cli.Run("core", "list", "--format", "json")
47+
require.NoError(t, err)
48+
jsonOut := requirejson.Parse(t, out)
49+
jsonOut.LengthMustEqualTo(1)
50+
jsonOut.MustContain(`[
51+
{
52+
"id": "arduino:avr",
53+
"installed": "1.8.6",
54+
"name": "Arduino AVR Boards",
55+
"boards": [
56+
{
57+
"name": "Arduino Uno",
58+
"fqbn": "arduino:avr:uno"
59+
},
60+
{
61+
"name": "Arduino Yún",
62+
"fqbn": "arduino:avr:yun"
63+
}
64+
]
65+
}
66+
]`)
67+
}
68+
69+
{
70+
// Also test local platform.txt properties override
71+
out, _, err := cli.Run("board", "details", "-b", "arduino:avr:uno", "--format", "json")
72+
require.NoError(t, err)
73+
jsonOut := requirejson.Parse(t, out)
74+
jsonOut.MustContain(`{
75+
"version": "1.8.6",
76+
"properties_id": "uno",
77+
"build_properties": [
78+
"_id=uno",
79+
"tools.avrdude.bootloader.params.verbose=-v",
80+
"tools.avrdude.cmd.path=/my/personal/avrdude"
81+
],
82+
"programmers": [
83+
{
84+
"platform": "Arduino AVR Boards",
85+
"id": "usbasp",
86+
"name": "USBasp"
87+
},
88+
{
89+
"platform": "Arduino AVR Boards",
90+
"id": "avrispmkii",
91+
"name": "AVRISP mkII"
92+
}
93+
]
94+
}`)
95+
}
96+
97+
{
98+
out, _, err := cli.Run("board", "details", "-b", "arduino:avr:yun", "--format", "json")
99+
require.NoError(t, err)
100+
jsonOut := requirejson.Parse(t, out)
101+
jsonOut.MustContain(`{
102+
"version": "1.8.6",
103+
"properties_id": "yun",
104+
"build_properties": [
105+
"_id=yun",
106+
"upload.wait_for_upload_port=true"
107+
]
108+
}`)
109+
}
110+
111+
{
112+
// Check un-expansion of board_properties
113+
out, _, err := cli.Run("board", "details", "-b", "arduino:avr:robotMotor", "--show-properties=unexpanded", "--format", "json")
114+
require.NoError(t, err)
115+
jsonOut := requirejson.Parse(t, out)
116+
jsonOut.MustContain(`{
117+
"version": "1.8.6",
118+
"properties_id": "robotMotor",
119+
"build_properties": [
120+
"_id=robotMotor",
121+
"build.extra_flags={build.usb_flags}",
122+
"upload.wait_for_upload_port=true"
123+
]
124+
}`)
125+
}
126+
127+
{
128+
// Also test local boards.txt properties override
129+
out, _, err := cli.Run("board", "details", "-b", "arduino:avr:diecimila", "--show-properties=unexpanded", "--format", "json")
130+
require.NoError(t, err)
131+
jsonOut := requirejson.Parse(t, out)
132+
jsonOut.MustContain(`{
133+
"version": "1.8.6",
134+
"properties_id": "diecimila",
135+
"build_properties": [
136+
"_id=diecimila",
137+
"menu.cpu.atmega123=ATmega123"
138+
]
139+
}`)
140+
}
141+
})
142+
143+
t.Run("MixingUserHardware", func(t *testing.T) {
144+
// Install custom hardware required for tests
145+
customHwDir, err := paths.New("..", "testdata", "user_hardware").Abs()
146+
require.NoError(t, err)
147+
require.NoError(t, customHwDir.CopyDirTo(cli.SketchbookDir().Join("hardware")))
148+
149+
{
150+
out, _, err := cli.Run("core", "list", "--format", "json")
151+
require.NoError(t, err)
152+
jsonOut := requirejson.Parse(t, out)
153+
if runtime.GOOS == "windows" {
154+
//a package is a symlink, and windows does not support them
155+
jsonOut.LengthMustEqualTo(2)
156+
} else {
157+
jsonOut.LengthMustEqualTo(3)
158+
}
159+
jsonOut.MustContain(`[
160+
{
161+
"id": "arduino:avr",
162+
"installed": "1.8.6",
163+
"name": "Arduino AVR Boards",
164+
"boards": [
165+
{
166+
"name": "Arduino Uno",
167+
"fqbn": "arduino:avr:uno"
168+
},
169+
{
170+
"name": "Arduino Yún",
171+
"fqbn": "arduino:avr:yun"
172+
}
173+
]
174+
}
175+
]`)
176+
jsonOut.MustContain(`[
177+
{
178+
"id": "my_avr_platform:avr",
179+
"installed": "9.9.9",
180+
"name": "My AVR Boards",
181+
"boards": [
182+
{
183+
"name": "Arduino Yún",
184+
"fqbn": "my_avr_platform:avr:custom_yun"
185+
}
186+
],
187+
"manually_installed": true,
188+
"missing_metadata": true
189+
}
190+
]`)
191+
192+
// require.False(t, myAVRPlatformAvrArch.Properties.ContainsKey("preproc.includes.flags"))
193+
194+
if runtime.GOOS != "windows" {
195+
jsonOut.MustContain(`[
196+
{
197+
"id": "my_symlinked_avr_platform:avr",
198+
"manually_installed": true,
199+
"missing_metadata": true
200+
}
201+
]`)
202+
}
203+
}
204+
205+
{
206+
// Also test local platform.txt properties override
207+
out, _, err := cli.Run("board", "details", "-b", "arduino:avr:uno", "--format", "json")
208+
require.NoError(t, err)
209+
jsonOut := requirejson.Parse(t, out)
210+
jsonOut.MustContain(`{
211+
"version": "1.8.6",
212+
"properties_id": "uno",
213+
"build_properties": [
214+
"_id=uno",
215+
"tools.avrdude.bootloader.params.verbose=-v",
216+
"tools.avrdude.cmd.path=/my/personal/avrdude"
217+
],
218+
"programmers": [
219+
{
220+
"platform": "Arduino AVR Boards",
221+
"id": "usbasp",
222+
"name": "USBasp"
223+
},
224+
{
225+
"platform": "Arduino AVR Boards",
226+
"id": "avrispmkii",
227+
"name": "AVRISP mkII"
228+
}
229+
]
230+
}`)
231+
}
232+
233+
{
234+
out, _, err := cli.Run("board", "details", "-b", "arduino:avr:yun", "--show-properties=unexpanded", "--format", "json")
235+
require.NoError(t, err)
236+
jsonOut := requirejson.Parse(t, out)
237+
jsonOut.MustContain(`{
238+
"version": "1.8.6",
239+
"properties_id": "yun",
240+
"build_properties": [
241+
"_id=yun",
242+
"upload.wait_for_upload_port=true",
243+
"preproc.includes.flags=-w -x c++ -M -MG -MP",
244+
"preproc.macros.flags=-w -x c++ -E -CC",
245+
"recipe.preproc.includes=\"{compiler.path}{compiler.cpp.cmd}\" {compiler.cpp.flags} {preproc.includes.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} \"{source_file}\""
246+
]
247+
}`)
248+
jsonOut.Query(`isempty( .build_properties[] | select(startswith("preproc.macros.compatibility_flags")) )`).MustEqual("true")
249+
}
250+
})
251+
}

‎internal/integrationtest/compile_1/compile_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/compile_1/compile_test.go
+59-36Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func TestCompile(t *testing.T) {
5959
{"WithMultipleBuildPropertyFlags", compileWithMultipleBuildPropertyFlags},
6060
{"WithOutputDirFlag", compileWithOutputDirFlag},
6161
{"WithExportBinariesFlag", compileWithExportBinariesFlag},
62-
{"WithCustomBuildPath", compileWithCustomBuildPath},
6362
{"WithExportBinariesEnvVar", compileWithExportBinariesEnvVar},
6463
{"WithExportBinariesConfig", compileWithExportBinariesConfig},
6564
{"WithInvalidUrl", compileWithInvalidUrl},
@@ -73,6 +72,7 @@ func TestCompile(t *testing.T) {
7372
{"WithRelativeBuildPath", compileWithRelativeBuildPath},
7473
{"WithFakeSecureBootCore", compileWithFakeSecureBootCore},
7574
{"PreprocessFlagDoNotMessUpWithOutput", preprocessFlagDoNotMessUpWithOutput},
75+
{"WithCustomBuildPath", buildWithCustomBuildPath},
7676
}.Run(t, env, cli)
7777
}
7878

@@ -448,41 +448,6 @@ func compileWithExportBinariesFlag(t *testing.T, env *integrationtest.Environmen
448448
require.FileExists(t, sketchPath.Join("build", fqbn, sketchName+".ino.with_bootloader.hex").String())
449449
}
450450

451-
func compileWithCustomBuildPath(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
452-
sketchName := "CompileWithBuildPath"
453-
sketchPath := cli.SketchbookDir().Join(sketchName)
454-
defer sketchPath.RemoveAll()
455-
fqbn := "arduino:avr:uno"
456-
457-
// Create a test sketch
458-
_, _, err := cli.Run("sketch", "new", sketchPath.String())
459-
require.NoError(t, err)
460-
461-
// Test the --build-path flag with absolute path
462-
buildPath := cli.DataDir().Join("test_dir", "build_dir")
463-
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--build-path", buildPath.String())
464-
require.NoError(t, err)
465-
466-
// Verifies expected binaries have been built to build_path
467-
require.DirExists(t, buildPath.String())
468-
require.FileExists(t, buildPath.Join(sketchName+".ino.eep").String())
469-
require.FileExists(t, buildPath.Join(sketchName+".ino.elf").String())
470-
require.FileExists(t, buildPath.Join(sketchName+".ino.hex").String())
471-
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.bin").String())
472-
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.hex").String())
473-
474-
// Verifies there are no binaries in temp directory
475-
md5 := md5.Sum(([]byte(sketchPath.String())))
476-
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
477-
require.NotEmpty(t, sketchPathMd5)
478-
buildDir := paths.TempDir().Join("arduino", "sketches", sketchPathMd5)
479-
require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String())
480-
require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String())
481-
require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String())
482-
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
483-
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
484-
}
485-
486451
func compileWithExportBinariesEnvVar(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
487452
sketchName := "CompileWithExportBinariesEnvVar"
488453
sketchPath := cli.SketchbookDir().Join(sketchName)
@@ -1204,3 +1169,61 @@ void loop() {
12041169
require.NoError(t, err)
12051170
require.Equal(t, expected, string(output))
12061171
}
1172+
1173+
func buildWithCustomBuildPath(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
1174+
sketchName := "bare_minimum"
1175+
sketchPath := cli.CopySketch(sketchName)
1176+
defer sketchPath.RemoveAll()
1177+
1178+
t.Run("OutsideSketch", func(t *testing.T) {
1179+
sketchName := "CompileWithBuildPath"
1180+
sketchPath := cli.SketchbookDir().Join(sketchName)
1181+
defer sketchPath.RemoveAll()
1182+
fqbn := "arduino:avr:uno"
1183+
1184+
// Create a test sketch
1185+
_, _, err := cli.Run("sketch", "new", sketchPath.String())
1186+
require.NoError(t, err)
1187+
1188+
// Test the --build-path flag with absolute path
1189+
buildPath := cli.DataDir().Join("test_dir", "build_dir")
1190+
_, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--build-path", buildPath.String())
1191+
require.NoError(t, err)
1192+
1193+
// Verifies expected binaries have been built to build_path
1194+
require.DirExists(t, buildPath.String())
1195+
require.FileExists(t, buildPath.Join(sketchName+".ino.eep").String())
1196+
require.FileExists(t, buildPath.Join(sketchName+".ino.elf").String())
1197+
require.FileExists(t, buildPath.Join(sketchName+".ino.hex").String())
1198+
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.bin").String())
1199+
require.FileExists(t, buildPath.Join(sketchName+".ino.with_bootloader.hex").String())
1200+
1201+
// Verifies there are no binaries in temp directory
1202+
md5 := md5.Sum(([]byte(sketchPath.String())))
1203+
sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:]))
1204+
require.NotEmpty(t, sketchPathMd5)
1205+
buildDir := paths.TempDir().Join("arduino", "sketches", sketchPathMd5)
1206+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.eep").String())
1207+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.elf").String())
1208+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.hex").String())
1209+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String())
1210+
require.NoFileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String())
1211+
})
1212+
1213+
t.Run("InsideSketch", func(t *testing.T) {
1214+
buildPath := sketchPath.Join("build")
1215+
1216+
// Run build
1217+
_, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
1218+
require.NoError(t, err)
1219+
// Run build twice, to verify the build still works when the build directory is present at the start
1220+
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
1221+
require.NoError(t, err)
1222+
})
1223+
1224+
t.Run("SameAsSektch", func(t *testing.T) {
1225+
// Run build
1226+
_, _, err := cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", sketchPath.String(), sketchPath.String())
1227+
require.Error(t, err)
1228+
})
1229+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.