|
16 | 16 | package upload
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "bytes" |
19 | 20 | "fmt"
|
| 21 | + "strings" |
20 | 22 | "testing"
|
21 | 23 |
|
22 | 24 | "github.com/arduino/arduino-cli/arduino/cores"
|
| 25 | + "github.com/arduino/arduino-cli/arduino/cores/packagemanager" |
23 | 26 | "github.com/arduino/arduino-cli/arduino/sketches"
|
24 | 27 | paths "github.com/arduino/go-paths-helper"
|
25 | 28 | "github.com/stretchr/testify/require"
|
@@ -119,3 +122,74 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
|
119 | 122 | })
|
120 | 123 | }
|
121 | 124 | }
|
| 125 | + |
| 126 | +func TestUploadPropertiesComposition(t *testing.T) { |
| 127 | + pm := packagemanager.NewPackageManager(nil, nil, nil, nil) |
| 128 | + err := pm.LoadHardwareFromDirectory(paths.New("testdata", "hardware")) |
| 129 | + require.NoError(t, err) |
| 130 | + buildPath1 := paths.New("testdata", "build_path_1") |
| 131 | + |
| 132 | + type test struct { |
| 133 | + importDir *paths.Path |
| 134 | + fqbn string |
| 135 | + port string |
| 136 | + programmer string |
| 137 | + burnBootloader bool |
| 138 | + expected string |
| 139 | + } |
| 140 | + |
| 141 | + tests := []test{ |
| 142 | + // classic upload, requires port |
| 143 | + {buildPath1, "alice:avr:board1", "port", "", false, "conf-board1 conf-general conf-upload $$VERBOSE-VERIFY$$ protocol port -bspeed testdata/build_path_1/sketch.ino.hex"}, |
| 144 | + } |
| 145 | + for i, test := range tests { |
| 146 | + t.Run(fmt.Sprintf("SubTest%02d", i), func(t *testing.T) { |
| 147 | + outStream := &bytes.Buffer{} |
| 148 | + errStream := &bytes.Buffer{} |
| 149 | + err := runProgramAction( |
| 150 | + pm, |
| 151 | + nil, // sketch |
| 152 | + "", // importFile |
| 153 | + test.importDir.String(), // importDir |
| 154 | + test.fqbn, // FQBN |
| 155 | + test.port, // port |
| 156 | + test.programmer, // programmer |
| 157 | + false, // verbose |
| 158 | + false, // verify |
| 159 | + test.burnBootloader, // burnBootloader |
| 160 | + outStream, |
| 161 | + errStream, |
| 162 | + ) |
| 163 | + require.NoError(t, err) |
| 164 | + out := strings.TrimSpace(outStream.String()) |
| 165 | + require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "quiet noverify"), out) |
| 166 | + }) |
| 167 | + t.Run(fmt.Sprintf("SubTest%02d-WithVerifyAndVerbose", i), func(t *testing.T) { |
| 168 | + outStream := &bytes.Buffer{} |
| 169 | + errStream := &bytes.Buffer{} |
| 170 | + err := runProgramAction( |
| 171 | + pm, |
| 172 | + nil, // sketch |
| 173 | + "", // importFile |
| 174 | + test.importDir.String(), // importDir |
| 175 | + test.fqbn, // FQBN |
| 176 | + test.port, // port |
| 177 | + test.programmer, // programmer |
| 178 | + true, // verbose |
| 179 | + true, // verify |
| 180 | + test.burnBootloader, // burnBootloader |
| 181 | + outStream, |
| 182 | + errStream, |
| 183 | + ) |
| 184 | + require.NoError(t, err) |
| 185 | + out := strings.Split(outStream.String(), "\n") |
| 186 | + // With verbose enabled, the upload will output 3 lines: |
| 187 | + // - the command line that the cli is going to run |
| 188 | + // - the output of the command |
| 189 | + // - an empty line |
| 190 | + // we are interested in the second line |
| 191 | + require.Len(t, out, 3) |
| 192 | + require.Equal(t, strings.ReplaceAll(test.expected, "$$VERBOSE-VERIFY$$", "verbose verify"), out[1]) |
| 193 | + }) |
| 194 | + } |
| 195 | +} |
0 commit comments