|
| 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 | +} |
0 commit comments