|
16 | 16 | package compile_part_1_test
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "crypto/md5" |
| 20 | + "encoding/hex" |
| 21 | + "encoding/json" |
| 22 | + "strings" |
19 | 23 | "testing"
|
20 | 24 |
|
21 | 25 | "github.com/arduino/arduino-cli/internal/integrationtest"
|
@@ -84,3 +88,58 @@ func TestCompileErrorMessage(t *testing.T) {
|
84 | 88 | require.Error(t, err)
|
85 | 89 | require.Contains(t, string(stderr), "main file missing from sketch:")
|
86 | 90 | }
|
| 91 | + |
| 92 | +func TestCompileWithSimpleSketch(t *testing.T) { |
| 93 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 94 | + defer env.CleanUp() |
| 95 | + |
| 96 | + // Init the environment explicitly |
| 97 | + _, _, err := cli.Run("core", "update-index") |
| 98 | + require.NoError(t, err) |
| 99 | + |
| 100 | + // Download latest AVR |
| 101 | + _, _, err = cli.Run("core", "install", "arduino:avr") |
| 102 | + require.NoError(t, err) |
| 103 | + |
| 104 | + sketchName := "CompileIntegrationTest" |
| 105 | + sketchPath := cli.SketchbookDir().Join(sketchName) |
| 106 | + fqbn := "arduino:avr:uno" |
| 107 | + |
| 108 | + // Create a test sketch |
| 109 | + stdout, _, err := cli.Run("sketch", "new", sketchPath.String()) |
| 110 | + require.NoError(t, err) |
| 111 | + require.Contains(t, string(stdout), "Sketch created in: "+sketchPath.String()) |
| 112 | + |
| 113 | + // Build sketch for arduino:avr:uno |
| 114 | + _, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String()) |
| 115 | + require.NoError(t, err) |
| 116 | + |
| 117 | + // Build sketch for arduino:avr:uno with json output |
| 118 | + stdout, _, err = cli.Run("compile", "-b", fqbn, sketchPath.String(), "--format", "json") |
| 119 | + require.NoError(t, err) |
| 120 | + // check is a valid json and contains requested data |
| 121 | + var compileOutput map[string]interface{} |
| 122 | + err = json.Unmarshal(stdout, &compileOutput) |
| 123 | + require.NoError(t, err) |
| 124 | + require.NotEmpty(t, compileOutput["compiler_out"]) |
| 125 | + require.Empty(t, compileOutput["compiler_err"]) |
| 126 | + |
| 127 | + // Verifies expected binaries have been built |
| 128 | + md5 := md5.Sum(([]byte(sketchPath.String()))) |
| 129 | + sketchPathMd5 := strings.ToUpper(hex.EncodeToString(md5[:])) |
| 130 | + require.NotEmpty(t, sketchPathMd5) |
| 131 | + buildDir := paths.TempDir().Join("arduino-sketch-" + sketchPathMd5) |
| 132 | + require.FileExists(t, buildDir.Join(sketchName+".ino.eep").String()) |
| 133 | + require.FileExists(t, buildDir.Join(sketchName+".ino.elf").String()) |
| 134 | + require.FileExists(t, buildDir.Join(sketchName+".ino.hex").String()) |
| 135 | + require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.bin").String()) |
| 136 | + require.FileExists(t, buildDir.Join(sketchName+".ino.with_bootloader.hex").String()) |
| 137 | + |
| 138 | + // Verifies binaries are not exported by default to Sketch folder |
| 139 | + sketchBuildDir := sketchPath.Join("build" + strings.ReplaceAll(fqbn, ":", ".")) |
| 140 | + require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.eep").String()) |
| 141 | + require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.elf").String()) |
| 142 | + require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.hex").String()) |
| 143 | + require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.with_bootloader.bin").String()) |
| 144 | + require.NoFileExists(t, sketchBuildDir.Join(sketchName+".ino.with_bootloader.hex").String()) |
| 145 | +} |
0 commit comments