Commit 5a095784 authored by Cristian Maglie's avatar Cristian Maglie

Added tests and ifx for board options available only under particular OS

See: https://github.com/arduino/arduino-cli/pull/67#issuecomment-429919298

quote:
There are some options without label (did not parsed well) for upload speed on different OS:

Option:     Upload Speed                             UploadSpeed
            115200                                  UploadSpeed=115200
            9600                                     UploadSpeed=9600
            57600                                    UploadSpeed=57600
            230400                                   UploadSpeed=230400
                                                     UploadSpeed=256000
            460800                                   UploadSpeed=460800
                                                     UploadSpeed=512000
            921600                                   UploadSpeed=921600

Cause boards.txt contains:

generic.menu.UploadSpeed.115200=115200
generic.menu.UploadSpeed.115200.upload.speed=115200
generic.menu.UploadSpeed.9600=9600
generic.menu.UploadSpeed.9600.upload.speed=9600
generic.menu.UploadSpeed.57600=57600
generic.menu.UploadSpeed.57600.upload.speed=57600
generic.menu.UploadSpeed.230400.linux=230400
generic.menu.UploadSpeed.230400.macosx=230400
generic.menu.UploadSpeed.230400.upload.speed=230400
generic.menu.UploadSpeed.256000.windows=256000
generic.menu.UploadSpeed.256000.upload.speed=256000
generic.menu.UploadSpeed.460800.linux=460800
generic.menu.UploadSpeed.460800.macosx=460800
generic.menu.UploadSpeed.460800.upload.speed=460800
generic.menu.UploadSpeed.512000.windows=512000
generic.menu.UploadSpeed.512000.upload.speed=512000
generic.menu.UploadSpeed.921600=921600
generic.menu.UploadSpeed.921600.upload.speed=921600
parent e770c8d9
......@@ -78,7 +78,9 @@ func (b *Board) GetConfigOptionValues(option string) *properties.Map {
res := properties.NewMap()
menu := b.Properties.SubTree("menu").SubTree(option)
for _, value := range menu.FirstLevelKeys() {
res.Set(value, menu.Get(value))
if label, ok := menu.GetOk(value); ok {
res.Set(value, label)
}
}
return res
}
......
......@@ -22,6 +22,7 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
"github.com/stretchr/testify/require"
)
......@@ -43,3 +44,44 @@ func TestFindBoardWithFQBN(t *testing.T) {
require.NotNil(t, board)
require.Equal(t, board.Name(), "Arduino/Genuino Mega or Mega 2560")
}
func TestBoardOptionsFunctions(t *testing.T) {
pm := packagemanager.NewPackageManager(
paths.New("testdata"),
paths.New("testdata"),
paths.New("testdata"),
paths.New("testdata"))
pm.LoadHardwareFromDirectory(paths.New("testdata"))
nano, err := pm.FindBoardWithFQBN("arduino:avr:nano")
require.Nil(t, err)
require.NotNil(t, nano)
require.Equal(t, nano.Name(), "Arduino Nano")
nanoOptions := nano.GetConfigOptions()
require.Equal(t, "Processor", nanoOptions.Get("cpu"))
require.Equal(t, 1, nanoOptions.Size())
nanoCPUValues := nano.GetConfigOptionValues("cpu")
expectedNanoCPUValues := properties.NewMap()
expectedNanoCPUValues.Set("atmega328", "ATmega328P")
expectedNanoCPUValues.Set("atmega328old", "ATmega328P (Old Bootloader)")
expectedNanoCPUValues.Set("atmega168", "ATmega168")
require.EqualValues(t, expectedNanoCPUValues, nanoCPUValues)
esp8266, err := pm.FindBoardWithFQBN("esp8266:esp8266:generic")
require.Nil(t, err)
require.NotNil(t, esp8266)
require.Equal(t, esp8266.Name(), "Generic ESP8266 Module")
esp8266Options := esp8266.GetConfigOptions()
require.Equal(t, 13, esp8266Options.Size())
require.Equal(t, "Builtin Led", esp8266Options.Get("led"))
require.Equal(t, "Upload Speed", esp8266Options.Get("UploadSpeed"))
esp8266UploadSpeedValues := esp8266.GetConfigOptionValues("UploadSpeed")
for k, v := range esp8266UploadSpeedValues.AsMap() {
// Some option values are missing for a particular OS: check that only the available options are listed
require.Equal(t, k, v)
}
}
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