|
| 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_part_1_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "crypto/md5" |
| 20 | + "encoding/hex" |
| 21 | + "strings" |
| 22 | + "testing" |
| 23 | + |
| 24 | + "github.com/arduino/arduino-cli/internal/integrationtest" |
| 25 | + "github.com/arduino/go-paths-helper" |
| 26 | + "github.com/stretchr/testify/require" |
| 27 | +) |
| 28 | + |
| 29 | +func TestCompileWithOutputDirFlag(t *testing.T) { |
| 30 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 31 | + defer env.CleanUp() |
| 32 | + |
| 33 | + // Init the environment explicitly |
| 34 | + _, _, err := cli.Run("core", "update-index") |
| 35 | + require.NoError(t, err) |
| 36 | + |
| 37 | + // Download latest AVR |
| 38 | + _, _, err = cli.Run("core", "install", "arduino:avr") |
| 39 | + require.NoError(t, err) |
| 40 | + |
| 41 | + sketchName := "CompileWithOutputDir" |
| 42 | + sketchPath := cli.SketchbookDir().Join(sketchName) |
| 43 | + fqbn := "arduino:avr:uno" |
| 44 | + |
| 45 | + // Create a test sketch |
| 46 | + stdout, _, err := cli.Run("sketch", "new", sketchPath.String()) |
| 47 | + require.NoError(t, err) |
| 48 | + require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String()) |
| 49 | + |
| 50 | + // Test the --output-dir flag with absolute path |
| 51 | + outputDir := cli.SketchbookDir().Join("test_dir", "output_dir") |
| 52 | + _, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--output-dir", outputDir.String()) |
| 53 | + require.NoError(t, err) |
| 54 | + |
| 55 | + // Verifies expected binaries have been built |
| 56 | + md5 := md5.Sum(([]byte(sketchPath.String()))) |
| 57 | + sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) |
| 58 | + require.NotEmpty(t, sketchPathMd5) |
| 59 | + buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) |
| 60 | + require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String()) |
| 61 | + require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String()) |
| 62 | + require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String()) |
| 63 | + require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String()) |
| 64 | + require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String()) |
| 65 | + |
| 66 | + // Verifies binaries are exported when --output-dir flag is specified |
| 67 | + require.DirExists(t, outputDir.String()) |
| 68 | + require.FileExists(t, outputDir.Join(sketchName+".ino.eep").String()) |
| 69 | + require.FileExists(t, outputDir.Join(sketchName+".ino.elf").String()) |
| 70 | + require.FileExists(t, outputDir.Join(sketchName+".ino.hex").String()) |
| 71 | + require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.bin").String()) |
| 72 | + require.FileExists(t, outputDir.Join(sketchName+".ino.with_bootloader.hex").String()) |
| 73 | +} |
0 commit comments