Skip to content

Commit 937f3e0

Browse files
committed
testsuite: added test for arduino#1614
1 parent ae669d0 commit 937f3e0

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

Diff for: internal/integrationtest/arduino-cli.go

+23
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,26 @@ func (inst *ArduinoCLIInstance) BoardListWatch() (commands.ArduinoCoreService_Bo
259259
}
260260
return watcher, watcher.Send(boardListWatchReq)
261261
}
262+
263+
// PlatformInstall calls the "PlatformInstall" gRPC method.
264+
func (inst *ArduinoCLIInstance) PlatformInstall(ctx context.Context, packager, arch, version string) (commands.ArduinoCoreService_PlatformInstallClient, error) {
265+
installCl, err := inst.cli.daemonClient.PlatformInstall(ctx, &commands.PlatformInstallRequest{
266+
Instance: inst.instance,
267+
PlatformPackage: packager,
268+
Architecture: arch,
269+
Version: version,
270+
})
271+
logCallf(">>> PlatformInstall(%v:%v %v)\n", packager, arch, version)
272+
return installCl, err
273+
}
274+
275+
func (inst *ArduinoCLIInstance) Compile(ctx context.Context, fqbn, sketchPath string) (commands.ArduinoCoreService_CompileClient, error) {
276+
compileCl, err := inst.cli.daemonClient.Compile(ctx, &commands.CompileRequest{
277+
Instance: inst.instance,
278+
Fqbn: fqbn,
279+
SketchPath: sketchPath,
280+
Verbose: true,
281+
})
282+
logCallf(">>> Compile(%v %v)\n", fqbn, sketchPath)
283+
return compileCl, err
284+
}
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 [email protected].
15+
16+
package daemon_test
17+
18+
import (
19+
"context"
20+
"fmt"
21+
"io"
22+
"testing"
23+
24+
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
25+
"github.com/arduino/go-paths-helper"
26+
"github.com/stretchr/testify/require"
27+
)
28+
29+
func TestDaemonCompileOptions(t *testing.T) {
30+
env, cli := createEnvForDaemon(t)
31+
defer env.CleanUp()
32+
33+
inst := cli.Create()
34+
require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) {
35+
fmt.Printf("INIT> %v\n", ir.GetMessage())
36+
}))
37+
38+
plInst, err := inst.PlatformInstall(context.Background(), "arduino", "avr", "1.8.5")
39+
require.NoError(t, err)
40+
for {
41+
msg, err := plInst.Recv()
42+
if err == io.EOF {
43+
break
44+
}
45+
require.NoError(t, err)
46+
fmt.Printf("INSTALL> %v\n", msg)
47+
}
48+
49+
// Install boards.local.txt to trigger bug
50+
platformLocalTxt := paths.New("testdata", "boards.local.txt-issue1614")
51+
err = platformLocalTxt.CopyTo(cli.DataDir().
52+
Join("packages", "arduino", "hardware", "avr", "1.8.5", "boards.local.txt"))
53+
require.NoError(t, err)
54+
55+
// Re-init instance to update changes
56+
require.NoError(t, inst.Init("", "", func(ir *commands.InitResponse) {
57+
fmt.Printf("INIT> %v\n", ir.GetMessage())
58+
}))
59+
60+
// Build sketch (with errors)
61+
sk := paths.New("testdata", "bare_minimum")
62+
compile, err := inst.Compile(context.Background(), "arduino:avr:uno:some_menu=bad", sk.String())
63+
require.NoError(t, err)
64+
for {
65+
msg, err := compile.Recv()
66+
if err == io.EOF {
67+
require.FailNow(t, "Expected compilation failure", "compilation succeeded")
68+
break
69+
}
70+
if err != nil {
71+
fmt.Println("COMPILE ERROR>", err)
72+
break
73+
}
74+
// if msg.OutStream != nil {
75+
// fmt.Printf("COMPILE> %v\n", string(msg.GetOutStream()))
76+
// }
77+
if msg.ErrStream != nil {
78+
fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream()))
79+
}
80+
}
81+
82+
// Build sketch (without errors)
83+
compile, err = inst.Compile(context.Background(), "arduino:avr:uno:some_menu=good", sk.String())
84+
require.NoError(t, err)
85+
for {
86+
msg, err := compile.Recv()
87+
if err == io.EOF {
88+
break
89+
}
90+
require.NoError(t, err)
91+
// if msg.OutStream != nil {
92+
// fmt.Printf("COMPILE> %v\n", string(msg.GetOutStream()))
93+
// }
94+
if msg.ErrStream != nil {
95+
fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream()))
96+
}
97+
}
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup() {}
2+
void loop() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# https://github.com/arduino/arduino-cli/issues/1614
2+
3+
menu.some_menu=Some Custom Menu
4+
5+
uno.menu.some_menu.bad=Bad Option
6+
uno.menu.some_menu.bad.build.extra_flags=-bad-build-extraflags
7+
uno.menu.some_menu.bad.compiler.cpp.extra_flags=-bad-compiler-cpp-extraflags
8+
9+
uno.menu.some_menu.good=Good Option
10+
uno.menu.some_menu.good.compiler.cpp.extra_flags=-DGOOD_COMPILER_CPP_EXTRA_FLAGS

0 commit comments

Comments
 (0)