|
| 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 compile_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/arduino/arduino-cli/internal/integrationtest" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + "gopkg.in/src-d/go-git.v4" |
| 24 | + "gopkg.in/src-d/go-git.v4/plumbing" |
| 25 | +) |
| 26 | + |
| 27 | +func TestCompileWithLibrary(t *testing.T) { |
| 28 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 29 | + defer env.CleanUp() |
| 30 | + |
| 31 | + _, _, err := cli.Run("update") |
| 32 | + require.NoError(t, err) |
| 33 | + |
| 34 | + _, _, err = cli.Run("core", "install", "arduino:avr@1.8.3") |
| 35 | + require.NoError(t, err) |
| 36 | + |
| 37 | + sketchName := "CompileSketchWithWiFi101Dependency" |
| 38 | + sketchPath := cli.SketchbookDir().Join(sketchName) |
| 39 | + fqbn := "arduino:avr:uno" |
| 40 | + // Create new sketch and add library include |
| 41 | + _, _, err = cli.Run("sketch", "new", sketchPath.String()) |
| 42 | + require.NoError(t, err) |
| 43 | + sketchFile := sketchPath.Join(sketchName + ".ino") |
| 44 | + lines, err := sketchFile.ReadFileAsLines() |
| 45 | + require.NoError(t, err) |
| 46 | + lines = append([]string{"#include <WiFi101.h>\n"}, lines...) |
| 47 | + var data []byte |
| 48 | + for _, l := range lines { |
| 49 | + data = append(data, []byte(l)...) |
| 50 | + } |
| 51 | + err = sketchFile.WriteFile(data) |
| 52 | + require.NoError(t, err) |
| 53 | + |
| 54 | + // Manually installs a library |
| 55 | + gitUrl := "https://github.com/arduino-libraries/WiFi101.git" |
| 56 | + libPath := cli.SketchbookDir().Join("my-libraries", "WiFi101") |
| 57 | + _, err = git.PlainClone(libPath.String(), false, &git.CloneOptions{ |
| 58 | + URL: gitUrl, |
| 59 | + ReferenceName: plumbing.NewTagReferenceName("0.16.1"), |
| 60 | + }) |
| 61 | + require.NoError(t, err) |
| 62 | + |
| 63 | + stdout, _, err := cli.Run("compile", "-b", fqbn, sketchPath.String(), "--library", libPath.String(), "-v") |
| 64 | + require.NoError(t, err) |
| 65 | + require.Contains(t, string(stdout), "WiFi101") |
| 66 | +} |
0 commit comments