@@ -67,7 +67,7 @@ func TestResolveFQBN(t *testing.T) {
67
67
pme , release := pm .NewExplorer ()
68
68
defer release ()
69
69
70
- {
70
+ t . Run ( "NormalizeFQBN" , func ( t * testing. T ) {
71
71
testNormalization := func (in , expected string ) {
72
72
fqbn , err := cores .ParseFQBN (in )
73
73
require .Nil (t , err )
@@ -89,9 +89,9 @@ func TestResolveFQBN(t *testing.T) {
89
89
testNormalization ("esp8266:esp8266:generic:baud=115200,wipe=sdk" , "esp8266:esp8266:generic:wipe=sdk" )
90
90
testNormalization ("arduino:avr:mega:cpu=nonexistent" , "ERROR" )
91
91
testNormalization ("arduino:avr:mega:nonexistent=blah" , "ERROR" )
92
- }
92
+ })
93
93
94
- {
94
+ t . Run ( "BoardAndBuildPropertiesArduinoUno" , func ( t * testing. T ) {
95
95
fqbn , err := cores .ParseFQBN ("arduino:avr:uno" )
96
96
require .Nil (t , err )
97
97
require .NotNil (t , fqbn )
@@ -105,9 +105,14 @@ func TestResolveFQBN(t *testing.T) {
105
105
require .Equal (t , board .Name (), "Arduino Uno" )
106
106
require .NotNil (t , props )
107
107
require .Equal (t , platformRelease , buildPlatformRelease )
108
- }
109
108
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 ) {
111
116
fqbn , err := cores .ParseFQBN ("arduino:avr:mega" )
112
117
require .Nil (t , err )
113
118
require .NotNil (t , fqbn )
@@ -121,9 +126,46 @@ func TestResolveFQBN(t *testing.T) {
121
126
require .Equal (t , board .Name (), "Arduino Mega or Mega 2560" )
122
127
require .NotNil (t , props )
123
128
require .Equal (t , platformRelease , buildPlatformRelease )
124
- }
129
+ })
125
130
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 ) {
127
169
// Test a board referenced from the main AVR arduino platform
128
170
fqbn , err := cores .ParseFQBN ("referenced:avr:uno" )
129
171
require .Nil (t , err )
@@ -140,9 +182,56 @@ func TestResolveFQBN(t *testing.T) {
140
182
require .NotNil (t , buildPlatformRelease )
141
183
require .NotNil (t , buildPlatformRelease .Platform )
142
184
require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
143
- }
185
+ })
144
186
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 ) {
146
235
// Test a board referenced from the Adafruit SAMD core (this tests
147
236
// deriving where the package and core name are different)
148
237
fqbn , err := cores .ParseFQBN ("referenced:samd:feather_m0" )
@@ -160,9 +249,9 @@ func TestResolveFQBN(t *testing.T) {
160
249
require .NotNil (t , buildPlatformRelease )
161
250
require .NotNil (t , buildPlatformRelease .Platform )
162
251
require .Equal (t , buildPlatformRelease .Platform .String (), "adafruit:samd" )
163
- }
252
+ })
164
253
165
- {
254
+ t . Run ( "BoardAndBuildPropertiesForNonExistentPackage" , func ( t * testing. T ) {
166
255
// Test a board referenced from a non-existent package
167
256
fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_package" )
168
257
require .Nil (t , err )
@@ -177,9 +266,9 @@ func TestResolveFQBN(t *testing.T) {
177
266
require .Equal (t , board .Name (), "Referenced dummy with invalid package" )
178
267
require .Nil (t , props )
179
268
require .Nil (t , buildPlatformRelease )
180
- }
269
+ })
181
270
182
- {
271
+ t . Run ( "BoardAndBuildPropertiesForNonExistentArchitecture" , func ( t * testing. T ) {
183
272
// Test a board referenced from a non-existent platform/architecture
184
273
fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_platform" )
185
274
require .Nil (t , err )
@@ -194,9 +283,9 @@ func TestResolveFQBN(t *testing.T) {
194
283
require .Equal (t , board .Name (), "Referenced dummy with invalid platform" )
195
284
require .Nil (t , props )
196
285
require .Nil (t , buildPlatformRelease )
197
- }
286
+ })
198
287
199
- {
288
+ t . Run ( "BoardAndBuildPropertiesForNonExistentCore" , func ( t * testing. T ) {
200
289
// Test a board referenced from a non-existent core
201
290
// Note that ResolveFQBN does not actually check this currently
202
291
fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_core" )
@@ -214,7 +303,41 @@ func TestResolveFQBN(t *testing.T) {
214
303
require .NotNil (t , buildPlatformRelease )
215
304
require .NotNil (t , buildPlatformRelease .Platform )
216
305
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
+ })
218
341
}
219
342
220
343
func TestBoardOptionsFunctions (t * testing.T ) {
0 commit comments