Skip to content

Commit 443717f

Browse files
committed
Added tests for upload command (parsing only)
1 parent 29c1182 commit 443717f

File tree

7 files changed

+121
-0
lines changed

7 files changed

+121
-0
lines changed

commands/commands_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,90 @@ func makeTempSketchbookDir(t *testing.T) func() {
166166
}
167167
}
168168

169+
func setSketchbookDir(t *testing.T, tmp *paths.Path) func() {
170+
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp.String())
171+
currSketchbookDir = tmp
172+
173+
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
174+
return func() {
175+
os.Unsetenv("ARDUINO_SKETCHBOOK_DIR")
176+
currSketchbookDir = nil
177+
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
178+
}
179+
}
180+
169181
// END -- Utility functions
170182

183+
func TestUploadCommands(t *testing.T) {
184+
defer makeTempDataDir(t)()
185+
defer useSharedDownloadDir(t)()
186+
defer setSketchbookDir(t, paths.New("testdata", "sketchbook_with_custom_hardware"))()
187+
188+
updateCoreIndex(t)
189+
190+
exitCode, _ := executeWithArgs(t, "core", "install", "arduino:avr")
191+
require.Zero(t, exitCode, "exit code")
192+
193+
// -i flag
194+
exitCode, d := executeWithArgs(t, "upload", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
195+
require.Zero(t, exitCode, "exit code")
196+
require.Contains(t, string(d), "QUIET")
197+
require.Contains(t, string(d), "NOVERIFY")
198+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
199+
200+
// -i flag with implicit extension
201+
exitCode, d = executeWithArgs(t, "upload", "-i", currSketchbookDir.Join("test").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
202+
require.Zero(t, exitCode, "exit code")
203+
require.Contains(t, string(d), "QUIET")
204+
require.Contains(t, string(d), "NOVERIFY")
205+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
206+
207+
// -i with absolute path
208+
fullPath, err := currSketchbookDir.Join("test.hex").Abs()
209+
require.NoError(t, err, "absolute path of test.hex")
210+
exitCode, d = executeWithArgs(t, "upload", "-i", fullPath.String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
211+
require.Zero(t, exitCode, "exit code")
212+
require.Contains(t, string(d), "QUIET")
213+
require.Contains(t, string(d), "NOVERIFY")
214+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
215+
216+
// -v verbose
217+
exitCode, d = executeWithArgs(t, "upload", "-v", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
218+
require.Zero(t, exitCode, "exit code")
219+
require.Contains(t, string(d), "VERBOSE")
220+
require.Contains(t, string(d), "NOVERIFY")
221+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
222+
223+
// -t verify
224+
exitCode, d = executeWithArgs(t, "upload", "-t", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
225+
require.Zero(t, exitCode, "exit code")
226+
require.Contains(t, string(d), "QUIET")
227+
require.Contains(t, string(d), "VERIFY")
228+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
229+
230+
// -v -t verbose verify
231+
exitCode, d = executeWithArgs(t, "upload", "-v", "-t", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
232+
require.Zero(t, exitCode, "exit code")
233+
require.Contains(t, string(d), "VERBOSE")
234+
require.Contains(t, string(d), "VERIFY")
235+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
236+
237+
// non-existent file
238+
exitCode, d = executeWithArgs(t, "upload", "-i", currSketchbookDir.Join("test123.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
239+
require.NotZero(t, exitCode, "exit code")
240+
241+
// sketch
242+
exitCode, d = executeWithArgs(t, "upload", currSketchbookDir.Join("TestSketch").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
243+
require.Zero(t, exitCode, "exit code")
244+
require.Contains(t, string(d), "QUIET")
245+
require.Contains(t, string(d), "NOVERIFY")
246+
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex")
247+
248+
// sketch without build
249+
exitCode, d = executeWithArgs(t, "upload", currSketchbookDir.Join("TestSketch2").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
250+
require.NotZero(t, exitCode, "exit code")
251+
}
252+
171253
func TestLibSearch(t *testing.T) {
172254
defer makeTempDataDir(t)()
173255
defer makeTempSketchbookDir(t)()

commands/testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.ino

Whitespace-only changes.

commands/testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex

Whitespace-only changes.

commands/testdata/sketchbook_with_custom_hardware/TestSketch2/TestSketch2.ino

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
testboard.name=Test Board
2+
3+
testboard.vid.0=0x2341
4+
testboard.pid.0=0x8888
5+
6+
testboard.upload.tool=avrdude-none
7+
testboard.upload.protocol=arduino
8+
testboard.upload.maximum_size=32256
9+
testboard.upload.maximum_data_size=2048
10+
testboard.upload.speed=115200
11+
12+
testboard.bootloader.tool=avrdude
13+
testboard.bootloader.low_fuses=0xFF
14+
testboard.bootloader.high_fuses=0xDE
15+
testboard.bootloader.extended_fuses=0xFD
16+
testboard.bootloader.unlock_bits=0x3F
17+
testboard.bootloader.lock_bits=0x0F
18+
testboard.bootloader.file=optiboot/optiboot_atmega328.hex
19+
20+
testboard.build.mcu=atmega328p
21+
testboard.build.f_cpu=16000000L
22+
testboard.build.board=AVR_UNO
23+
testboard.build.core=arduino:arduino
24+
testboard.build.variant=standard
25+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
name=Test AVR Boards
3+
version=1.0.0
4+
5+
recipe.output.tmp_file={build.project_name}.hex
6+
7+
# Fake AVR programmer tool for testing
8+
# ------------------------------------
9+
tools.avrdude-none.upload.params.verbose=VERBOSE
10+
tools.avrdude-none.upload.params.quiet=QUIET
11+
tools.avrdude-none.upload.params.verify=VERIFY
12+
tools.avrdude-none.upload.params.noverify=NOVERIFY
13+
tools.avrdude-none.upload.pattern=echo {upload.verbose} {upload.verify} "{build.path}/{build.project_name}.hex"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a fake .hex file for testing purposes

0 commit comments

Comments
 (0)