Commit 443717fa authored by Cristian Maglie's avatar Cristian Maglie Committed by Cristian Maglie

Added tests for upload command (parsing only)

parent 29c1182e
......@@ -166,8 +166,90 @@ func makeTempSketchbookDir(t *testing.T) func() {
}
}
func setSketchbookDir(t *testing.T, tmp *paths.Path) func() {
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp.String())
currSketchbookDir = tmp
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
return func() {
os.Unsetenv("ARDUINO_SKETCHBOOK_DIR")
currSketchbookDir = nil
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
}
}
// END -- Utility functions
func TestUploadCommands(t *testing.T) {
defer makeTempDataDir(t)()
defer useSharedDownloadDir(t)()
defer setSketchbookDir(t, paths.New("testdata", "sketchbook_with_custom_hardware"))()
updateCoreIndex(t)
exitCode, _ := executeWithArgs(t, "core", "install", "arduino:avr")
require.Zero(t, exitCode, "exit code")
// -i flag
exitCode, d := executeWithArgs(t, "upload", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
// -i flag with implicit extension
exitCode, d = executeWithArgs(t, "upload", "-i", currSketchbookDir.Join("test").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
// -i with absolute path
fullPath, err := currSketchbookDir.Join("test.hex").Abs()
require.NoError(t, err, "absolute path of test.hex")
exitCode, d = executeWithArgs(t, "upload", "-i", fullPath.String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
// -v verbose
exitCode, d = executeWithArgs(t, "upload", "-v", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "VERBOSE")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
// -t verify
exitCode, d = executeWithArgs(t, "upload", "-t", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "VERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
// -v -t verbose verify
exitCode, d = executeWithArgs(t, "upload", "-v", "-t", "-i", currSketchbookDir.Join("test.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "VERBOSE")
require.Contains(t, string(d), "VERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/test.hex")
// non-existent file
exitCode, d = executeWithArgs(t, "upload", "-i", currSketchbookDir.Join("test123.hex").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.NotZero(t, exitCode, "exit code")
// sketch
exitCode, d = executeWithArgs(t, "upload", currSketchbookDir.Join("TestSketch").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "QUIET")
require.Contains(t, string(d), "NOVERIFY")
require.Contains(t, string(d), "testdata/sketchbook_with_custom_hardware/TestSketch/TestSketch.test.avr.testboard.hex")
// sketch without build
exitCode, d = executeWithArgs(t, "upload", currSketchbookDir.Join("TestSketch2").String(), "-b", "test:avr:testboard", "-p", "/dev/ttyACM0")
require.NotZero(t, exitCode, "exit code")
}
func TestLibSearch(t *testing.T) {
defer makeTempDataDir(t)()
defer makeTempSketchbookDir(t)()
......
testboard.name=Test Board
testboard.vid.0=0x2341
testboard.pid.0=0x8888
testboard.upload.tool=avrdude-none
testboard.upload.protocol=arduino
testboard.upload.maximum_size=32256
testboard.upload.maximum_data_size=2048
testboard.upload.speed=115200
testboard.bootloader.tool=avrdude
testboard.bootloader.low_fuses=0xFF
testboard.bootloader.high_fuses=0xDE
testboard.bootloader.extended_fuses=0xFD
testboard.bootloader.unlock_bits=0x3F
testboard.bootloader.lock_bits=0x0F
testboard.bootloader.file=optiboot/optiboot_atmega328.hex
testboard.build.mcu=atmega328p
testboard.build.f_cpu=16000000L
testboard.build.board=AVR_UNO
testboard.build.core=arduino:arduino
testboard.build.variant=standard
name=Test AVR Boards
version=1.0.0
recipe.output.tmp_file={build.project_name}.hex
# Fake AVR programmer tool for testing
# ------------------------------------
tools.avrdude-none.upload.params.verbose=VERBOSE
tools.avrdude-none.upload.params.quiet=QUIET
tools.avrdude-none.upload.params.verify=VERIFY
tools.avrdude-none.upload.params.noverify=NOVERIFY
tools.avrdude-none.upload.pattern=echo {upload.verbose} {upload.verify} "{build.path}/{build.project_name}.hex"
This is a fake .hex file for testing purposes
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment