@@ -67,7 +67,7 @@ func TestResolveFQBN(t *testing.T) {
6767 pme , release := pm .NewExplorer ()
6868 defer release ()
6969
70- {
70+ t . Run ( "NormalizeFQBN" , func ( t * testing. T ) {
7171 testNormalization := func (in , expected string ) {
7272 fqbn , err := cores .ParseFQBN (in )
7373 require .Nil (t , err )
@@ -89,9 +89,9 @@ func TestResolveFQBN(t *testing.T) {
8989 testNormalization ("esp8266:esp8266:generic:baud=115200,wipe=sdk" , "esp8266:esp8266:generic:wipe=sdk" )
9090 testNormalization ("arduino:avr:mega:cpu=nonexistent" , "ERROR" )
9191 testNormalization ("arduino:avr:mega:nonexistent=blah" , "ERROR" )
92- }
92+ })
9393
94- {
94+ t . Run ( "BoardAndBuildPropertiesArduinoUno" , func ( t * testing. T ) {
9595 fqbn , err := cores .ParseFQBN ("arduino:avr:uno" )
9696 require .Nil (t , err )
9797 require .NotNil (t , fqbn )
@@ -105,9 +105,14 @@ func TestResolveFQBN(t *testing.T) {
105105 require .Equal (t , board .Name (), "Arduino Uno" )
106106 require .NotNil (t , props )
107107 require .Equal (t , platformRelease , buildPlatformRelease )
108- }
109108
110- {
109+ require .Equal (t , "arduino" , pkg .Name )
110+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
111+ require .Equal (t , "uno" , board .BoardID )
112+ require .Equal (t , "atmega328p" , props .Get ("build.mcu" ))
113+ })
114+
115+ t .Run ("BoardAndBuildPropertiesArduinoMega" , func (t * testing.T ) {
111116 fqbn , err := cores .ParseFQBN ("arduino:avr:mega" )
112117 require .Nil (t , err )
113118 require .NotNil (t , fqbn )
@@ -121,9 +126,46 @@ func TestResolveFQBN(t *testing.T) {
121126 require .Equal (t , board .Name (), "Arduino Mega or Mega 2560" )
122127 require .NotNil (t , props )
123128 require .Equal (t , platformRelease , buildPlatformRelease )
124- }
129+ })
125130
126- {
131+ t .Run ("BoardAndBuildPropertiesArduinoMegaWithNonDefaultCpuOption" , func (t * testing.T ) {
132+ fqbn , err := cores .ParseFQBN ("arduino:avr:mega:cpu=atmega1280" )
133+ require .Nil (t , err )
134+ require .NotNil (t , fqbn )
135+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
136+ require .Nil (t , err )
137+ require .Equal (t , pkg , platformRelease .Platform .Package )
138+ require .NotNil (t , platformRelease )
139+ require .NotNil (t , platformRelease .Platform )
140+ require .Equal (t , platformRelease , buildPlatformRelease )
141+
142+ require .Equal (t , "arduino" , pkg .Name )
143+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
144+ require .Equal (t , "mega" , board .BoardID )
145+ require .Equal (t , "atmega1280" , props .Get ("build.mcu" ))
146+ require .Equal (t , "AVR_MEGA" , props .Get ("build.board" ))
147+ })
148+
149+ t .Run ("BoardAndBuildPropertiesArduinoMegaWithDefaultCpuOption" , func (t * testing.T ) {
150+ fqbn , err := cores .ParseFQBN ("arduino:avr:mega:cpu=atmega2560" )
151+ require .Nil (t , err )
152+ require .NotNil (t , fqbn )
153+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
154+ require .Nil (t , err )
155+ require .Equal (t , pkg , platformRelease .Platform .Package )
156+ require .NotNil (t , platformRelease )
157+ require .NotNil (t , platformRelease .Platform )
158+ require .Equal (t , platformRelease , buildPlatformRelease )
159+
160+ require .Equal (t , "arduino" , pkg .Name )
161+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
162+ require .Equal (t , "mega" , board .BoardID )
163+ require .Equal (t , "atmega2560" , props .Get ("build.mcu" ))
164+ require .Equal (t , "AVR_MEGA2560" , props .Get ("build.board" ))
165+
166+ })
167+
168+ t .Run ("BoardAndBuildPropertiesForReferencedArduinoUno" , func (t * testing.T ) {
127169 // Test a board referenced from the main AVR arduino platform
128170 fqbn , err := cores .ParseFQBN ("referenced:avr:uno" )
129171 require .Nil (t , err )
@@ -140,9 +182,56 @@ func TestResolveFQBN(t *testing.T) {
140182 require .NotNil (t , buildPlatformRelease )
141183 require .NotNil (t , buildPlatformRelease .Platform )
142184 require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
143- }
185+ })
144186
145- {
187+ t .Run ("BoardAndBuildPropertiesForArduinoDue" , func (t * testing.T ) {
188+ fqbn , err := cores .ParseFQBN ("arduino:sam:arduino_due_x" )
189+ require .Nil (t , err )
190+ require .NotNil (t , fqbn )
191+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
192+ require .Nil (t , err )
193+ require .Equal (t , pkg , platformRelease .Platform .Package )
194+ require .Equal (t , platformRelease , buildPlatformRelease )
195+
196+ require .Equal (t , "arduino" , pkg .Name )
197+ require .Equal (t , "sam" , platformRelease .Platform .Architecture )
198+ require .Equal (t , "arduino_due_x" , board .BoardID )
199+ require .Equal (t , "cortex-m3" , props .Get ("build.mcu" ))
200+ })
201+
202+ t .Run ("BoardAndBuildPropertiesForCustomArduinoYun" , func (t * testing.T ) {
203+ fqbn , err := cores .ParseFQBN ("my_avr_platform:avr:custom_yun" )
204+ require .Nil (t , err )
205+ require .NotNil (t , fqbn )
206+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
207+ require .Nil (t , err )
208+ require .Equal (t , pkg , platformRelease .Platform .Package )
209+ require .NotEqual (t , platformRelease , buildPlatformRelease )
210+
211+ require .Equal (t , "my_avr_platform" , pkg .Name )
212+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
213+ require .Equal (t , "custom_yun" , board .BoardID )
214+ require .Equal (t , "atmega32u4" , props .Get ("build.mcu" ))
215+ require .Equal (t , "AVR_YUN" , props .Get ("build.board" ))
216+ })
217+
218+ t .Run ("BoardAndBuildPropertiesForWatterotCore" , func (t * testing.T ) {
219+ fqbn , err := cores .ParseFQBN ("watterott:avr:attiny841:core=spencekonde,info=info" )
220+ require .Nil (t , err )
221+ require .NotNil (t , fqbn )
222+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
223+ require .Nil (t , err )
224+ require .Equal (t , pkg , platformRelease .Platform .Package )
225+ require .Equal (t , platformRelease , buildPlatformRelease )
226+
227+ require .Equal (t , "watterott" , pkg .Name )
228+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
229+ require .Equal (t , "attiny841" , board .BoardID )
230+ require .Equal (t , "tiny841" , props .Get ("build.core" ))
231+ require .Equal (t , "tiny14" , props .Get ("build.variant" ))
232+ })
233+
234+ t .Run ("BoardAndBuildPropertiesForReferencedFeatherM0" , func (t * testing.T ) {
146235 // Test a board referenced from the Adafruit SAMD core (this tests
147236 // deriving where the package and core name are different)
148237 fqbn , err := cores .ParseFQBN ("referenced:samd:feather_m0" )
@@ -160,9 +249,9 @@ func TestResolveFQBN(t *testing.T) {
160249 require .NotNil (t , buildPlatformRelease )
161250 require .NotNil (t , buildPlatformRelease .Platform )
162251 require .Equal (t , buildPlatformRelease .Platform .String (), "adafruit:samd" )
163- }
252+ })
164253
165- {
254+ t . Run ( "BoardAndBuildPropertiesForNonExistentPackage" , func ( t * testing. T ) {
166255 // Test a board referenced from a non-existent package
167256 fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_package" )
168257 require .Nil (t , err )
@@ -177,9 +266,9 @@ func TestResolveFQBN(t *testing.T) {
177266 require .Equal (t , board .Name (), "Referenced dummy with invalid package" )
178267 require .Nil (t , props )
179268 require .Nil (t , buildPlatformRelease )
180- }
269+ })
181270
182- {
271+ t . Run ( "BoardAndBuildPropertiesForNonExistentArchitecture" , func ( t * testing. T ) {
183272 // Test a board referenced from a non-existent platform/architecture
184273 fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_platform" )
185274 require .Nil (t , err )
@@ -194,9 +283,9 @@ func TestResolveFQBN(t *testing.T) {
194283 require .Equal (t , board .Name (), "Referenced dummy with invalid platform" )
195284 require .Nil (t , props )
196285 require .Nil (t , buildPlatformRelease )
197- }
286+ })
198287
199- {
288+ t . Run ( "BoardAndBuildPropertiesForNonExistentCore" , func ( t * testing. T ) {
200289 // Test a board referenced from a non-existent core
201290 // Note that ResolveFQBN does not actually check this currently
202291 fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_core" )
@@ -214,7 +303,41 @@ func TestResolveFQBN(t *testing.T) {
214303 require .NotNil (t , buildPlatformRelease )
215304 require .NotNil (t , buildPlatformRelease .Platform )
216305 require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
217- }
306+ })
307+
308+ t .Run ("AddBuildBoardPropertyIfMissing" , func (t * testing.T ) {
309+ fqbn , err := cores .ParseFQBN ("my_avr_platform:avr:mymega" )
310+ require .Nil (t , err )
311+ require .NotNil (t , fqbn )
312+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
313+ require .Nil (t , err )
314+ require .Equal (t , pkg , platformRelease .Platform .Package )
315+ require .Equal (t , platformRelease , buildPlatformRelease )
316+
317+ require .Equal (t , "my_avr_platform" , pkg .Name )
318+ require .NotNil (t , platformRelease )
319+ require .NotNil (t , platformRelease .Platform )
320+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
321+ require .Equal (t , "mymega" , board .BoardID )
322+ require .Equal (t , "atmega2560" , props .Get ("build.mcu" ))
323+ require .Equal (t , "AVR_MYMEGA" , props .Get ("build.board" ))
324+ })
325+
326+ t .Run ("AddBuildBoardPropertyIfNotMissing" , func (t * testing.T ) {
327+ fqbn , err := cores .ParseFQBN ("my_avr_platform:avr:mymega:cpu=atmega1280" )
328+ require .Nil (t , err )
329+ require .NotNil (t , fqbn )
330+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
331+ require .Nil (t , err )
332+ require .Equal (t , pkg , platformRelease .Platform .Package )
333+ require .Equal (t , platformRelease , buildPlatformRelease )
334+
335+ require .Equal (t , "my_avr_platform" , pkg .Name )
336+ require .Equal (t , "avr" , platformRelease .Platform .Architecture )
337+ require .Equal (t , "mymega" , board .BoardID )
338+ require .Equal (t , "atmega1280" , props .Get ("build.mcu" ))
339+ require .Equal (t , "MYMEGA1280" , props .Get ("build.board" ))
340+ })
218341}
219342
220343func TestBoardOptionsFunctions (t * testing.T ) {
0 commit comments