@@ -67,116 +67,154 @@ func TestResolveFQBN(t *testing.T) {
6767 pme , release := pm .NewExplorer ()
6868 defer release ()
6969
70- fqbn , err := cores .ParseFQBN ("arduino:avr:uno" )
71- require .Nil (t , err )
72- require .NotNil (t , fqbn )
73- pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
74- require .Nil (t , err )
75- require .Equal (t , pkg , platformRelease .Platform .Package )
76- require .NotNil (t , platformRelease )
77- require .NotNil (t , platformRelease .Platform )
78- require .Equal (t , platformRelease .Platform .String (), "arduino:avr" )
79- require .NotNil (t , board )
80- require .Equal (t , board .Name (), "Arduino Uno" )
81- require .NotNil (t , props )
82- require .Equal (t , platformRelease , buildPlatformRelease )
70+ {
71+ testNormalization := func (in , expected string ) {
72+ fqbn , err := cores .ParseFQBN (in )
73+ require .Nil (t , err )
74+ require .NotNil (t , fqbn )
75+ normalized , err := pme .NormalizeFQBN (fqbn )
76+ if expected == "ERROR" {
77+ require .Error (t , err )
78+ require .Nil (t , normalized )
79+ } else {
80+ require .NoError (t , err )
81+ require .NotNil (t , normalized )
82+ require .Equal (t , expected , normalized .String ())
83+ }
84+ }
85+ testNormalization ("arduino:avr:mega" , "arduino:avr:mega" )
86+ testNormalization ("arduino:avr:mega:cpu=atmega2560" , "arduino:avr:mega" )
87+ testNormalization ("arduino:avr:mega:cpu=atmega1280" , "arduino:avr:mega:cpu=atmega1280" )
88+ testNormalization ("esp8266:esp8266:generic:baud=57600,wipe=sdk" , "esp8266:esp8266:generic:baud=57600,wipe=sdk" )
89+ testNormalization ("esp8266:esp8266:generic:baud=115200,wipe=sdk" , "esp8266:esp8266:generic:wipe=sdk" )
90+ testNormalization ("arduino:avr:mega:cpu=nonexistent" , "ERROR" )
91+ testNormalization ("arduino:avr:mega:nonexistent=blah" , "ERROR" )
92+ }
8393
84- fqbn , err = cores .ParseFQBN ("arduino:avr:mega" )
85- require .Nil (t , err )
86- require .NotNil (t , fqbn )
87- pkg , platformRelease , board , props , buildPlatformRelease , err = pme .ResolveFQBN (fqbn )
88- require .Nil (t , err )
89- require .Equal (t , pkg , platformRelease .Platform .Package )
90- require .NotNil (t , platformRelease )
91- require .NotNil (t , platformRelease .Platform )
92- require .Equal (t , platformRelease .Platform .String (), "arduino:avr" )
93- require .NotNil (t , board )
94- require .Equal (t , board .Name (), "Arduino Mega or Mega 2560" )
95- require .NotNil (t , props )
96- require .Equal (t , platformRelease , buildPlatformRelease )
94+ {
95+ fqbn , err := cores .ParseFQBN ("arduino:avr:uno" )
96+ require .Nil (t , err )
97+ require .NotNil (t , fqbn )
98+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
99+ require .Nil (t , err )
100+ require .Equal (t , pkg , platformRelease .Platform .Package )
101+ require .NotNil (t , platformRelease )
102+ require .NotNil (t , platformRelease .Platform )
103+ require .Equal (t , platformRelease .Platform .String (), "arduino:avr" )
104+ require .NotNil (t , board )
105+ require .Equal (t , board .Name (), "Arduino Uno" )
106+ require .NotNil (t , props )
107+ require .Equal (t , platformRelease , buildPlatformRelease )
108+ }
97109
98- // Test a board referenced from the main AVR arduino platform
99- fqbn , err = cores .ParseFQBN ("referenced:avr:uno" )
100- require .Nil (t , err )
101- require .NotNil (t , fqbn )
102- pkg , platformRelease , board , props , buildPlatformRelease , err = pme .ResolveFQBN (fqbn )
103- require .Nil (t , err )
104- require .Equal (t , pkg , platformRelease .Platform .Package )
105- require .NotNil (t , platformRelease )
106- require .NotNil (t , platformRelease .Platform )
107- require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
108- require .NotNil (t , board )
109- require .Equal (t , board .Name (), "Referenced Uno" )
110- require .NotNil (t , props )
111- require .NotNil (t , buildPlatformRelease )
112- require .NotNil (t , buildPlatformRelease .Platform )
113- require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
114-
115- // Test a board referenced from the Adafruit SAMD core (this tests
116- // deriving where the package and core name are different)
117- fqbn , err = cores .ParseFQBN ("referenced:samd:feather_m0" )
118- require .Nil (t , err )
119- require .NotNil (t , fqbn )
120- pkg , platformRelease , board , props , buildPlatformRelease , err = pme .ResolveFQBN (fqbn )
121- require .Nil (t , err )
122- require .Equal (t , pkg , platformRelease .Platform .Package )
123- require .NotNil (t , platformRelease )
124- require .NotNil (t , platformRelease .Platform )
125- require .Equal (t , platformRelease .Platform .String (), "referenced:samd" )
126- require .NotNil (t , board )
127- require .Equal (t , board .Name (), "Referenced Feather M0" )
128- require .NotNil (t , props )
129- require .NotNil (t , buildPlatformRelease )
130- require .NotNil (t , buildPlatformRelease .Platform )
131- require .Equal (t , buildPlatformRelease .Platform .String (), "adafruit:samd" )
132-
133- // Test a board referenced from a non-existent package
134- fqbn , err = cores .ParseFQBN ("referenced:avr:dummy_invalid_package" )
135- require .Nil (t , err )
136- require .NotNil (t , fqbn )
137- pkg , platformRelease , board , props , buildPlatformRelease , err = pme .ResolveFQBN (fqbn )
138- require .NotNil (t , err )
139- require .Equal (t , pkg , platformRelease .Platform .Package )
140- require .NotNil (t , platformRelease )
141- require .NotNil (t , platformRelease .Platform )
142- require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
143- require .NotNil (t , board )
144- require .Equal (t , board .Name (), "Referenced dummy with invalid package" )
145- require .Nil (t , props )
146- require .Nil (t , buildPlatformRelease )
110+ {
111+ fqbn , err := cores .ParseFQBN ("arduino:avr:mega" )
112+ require .Nil (t , err )
113+ require .NotNil (t , fqbn )
114+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
115+ require .Nil (t , err )
116+ require .Equal (t , pkg , platformRelease .Platform .Package )
117+ require .NotNil (t , platformRelease )
118+ require .NotNil (t , platformRelease .Platform )
119+ require .Equal (t , platformRelease .Platform .String (), "arduino:avr" )
120+ require .NotNil (t , board )
121+ require .Equal (t , board .Name (), "Arduino Mega or Mega 2560" )
122+ require .NotNil (t , props )
123+ require .Equal (t , platformRelease , buildPlatformRelease )
124+ }
147125
148- // Test a board referenced from a non-existent platform/architecture
149- fqbn , err = cores .ParseFQBN ("referenced:avr:dummy_invalid_platform" )
150- require .Nil (t , err )
151- require .NotNil (t , fqbn )
152- pkg , platformRelease , board , props , buildPlatformRelease , err = pme .ResolveFQBN (fqbn )
153- require .NotNil (t , err )
154- require .Equal (t , pkg , platformRelease .Platform .Package )
155- require .NotNil (t , platformRelease )
156- require .NotNil (t , platformRelease .Platform )
157- require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
158- require .NotNil (t , board )
159- require .Equal (t , board .Name (), "Referenced dummy with invalid platform" )
160- require .Nil (t , props )
161- require .Nil (t , buildPlatformRelease )
126+ {
127+ // Test a board referenced from the main AVR arduino platform
128+ fqbn , err := cores .ParseFQBN ("referenced:avr:uno" )
129+ require .Nil (t , err )
130+ require .NotNil (t , fqbn )
131+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
132+ require .Nil (t , err )
133+ require .Equal (t , pkg , platformRelease .Platform .Package )
134+ require .NotNil (t , platformRelease )
135+ require .NotNil (t , platformRelease .Platform )
136+ require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
137+ require .NotNil (t , board )
138+ require .Equal (t , board .Name (), "Referenced Uno" )
139+ require .NotNil (t , props )
140+ require .NotNil (t , buildPlatformRelease )
141+ require .NotNil (t , buildPlatformRelease .Platform )
142+ require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
143+ }
162144
163- // Test a board referenced from a non-existent core
164- // Note that ResolveFQBN does not actually check this currently
165- fqbn , err = cores .ParseFQBN ("referenced:avr:dummy_invalid_core" )
166- require .Nil (t , err )
167- require .NotNil (t , fqbn )
168- pkg , platformRelease , board , props , buildPlatformRelease , err = pme .ResolveFQBN (fqbn )
169- require .Nil (t , err )
170- require .Equal (t , pkg , platformRelease .Platform .Package )
171- require .NotNil (t , platformRelease )
172- require .NotNil (t , platformRelease .Platform )
173- require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
174- require .NotNil (t , board )
175- require .Equal (t , board .Name (), "Referenced dummy with invalid core" )
176- require .NotNil (t , props )
177- require .NotNil (t , buildPlatformRelease )
178- require .NotNil (t , buildPlatformRelease .Platform )
179- require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
145+ {
146+ // Test a board referenced from the Adafruit SAMD core (this tests
147+ // deriving where the package and core name are different)
148+ fqbn , err := cores .ParseFQBN ("referenced:samd:feather_m0" )
149+ require .Nil (t , err )
150+ require .NotNil (t , fqbn )
151+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
152+ require .Nil (t , err )
153+ require .Equal (t , pkg , platformRelease .Platform .Package )
154+ require .NotNil (t , platformRelease )
155+ require .NotNil (t , platformRelease .Platform )
156+ require .Equal (t , platformRelease .Platform .String (), "referenced:samd" )
157+ require .NotNil (t , board )
158+ require .Equal (t , board .Name (), "Referenced Feather M0" )
159+ require .NotNil (t , props )
160+ require .NotNil (t , buildPlatformRelease )
161+ require .NotNil (t , buildPlatformRelease .Platform )
162+ require .Equal (t , buildPlatformRelease .Platform .String (), "adafruit:samd" )
163+ }
164+
165+ {
166+ // Test a board referenced from a non-existent package
167+ fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_package" )
168+ require .Nil (t , err )
169+ require .NotNil (t , fqbn )
170+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
171+ require .NotNil (t , err )
172+ require .Equal (t , pkg , platformRelease .Platform .Package )
173+ require .NotNil (t , platformRelease )
174+ require .NotNil (t , platformRelease .Platform )
175+ require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
176+ require .NotNil (t , board )
177+ require .Equal (t , board .Name (), "Referenced dummy with invalid package" )
178+ require .Nil (t , props )
179+ require .Nil (t , buildPlatformRelease )
180+ }
181+
182+ {
183+ // Test a board referenced from a non-existent platform/architecture
184+ fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_platform" )
185+ require .Nil (t , err )
186+ require .NotNil (t , fqbn )
187+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
188+ require .NotNil (t , err )
189+ require .Equal (t , pkg , platformRelease .Platform .Package )
190+ require .NotNil (t , platformRelease )
191+ require .NotNil (t , platformRelease .Platform )
192+ require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
193+ require .NotNil (t , board )
194+ require .Equal (t , board .Name (), "Referenced dummy with invalid platform" )
195+ require .Nil (t , props )
196+ require .Nil (t , buildPlatformRelease )
197+ }
198+
199+ {
200+ // Test a board referenced from a non-existent core
201+ // Note that ResolveFQBN does not actually check this currently
202+ fqbn , err := cores .ParseFQBN ("referenced:avr:dummy_invalid_core" )
203+ require .Nil (t , err )
204+ require .NotNil (t , fqbn )
205+ pkg , platformRelease , board , props , buildPlatformRelease , err := pme .ResolveFQBN (fqbn )
206+ require .Nil (t , err )
207+ require .Equal (t , pkg , platformRelease .Platform .Package )
208+ require .NotNil (t , platformRelease )
209+ require .NotNil (t , platformRelease .Platform )
210+ require .Equal (t , platformRelease .Platform .String (), "referenced:avr" )
211+ require .NotNil (t , board )
212+ require .Equal (t , board .Name (), "Referenced dummy with invalid core" )
213+ require .NotNil (t , props )
214+ require .NotNil (t , buildPlatformRelease )
215+ require .NotNil (t , buildPlatformRelease .Platform )
216+ require .Equal (t , buildPlatformRelease .Platform .String (), "arduino:avr" )
217+ }
180218}
181219
182220func TestBoardOptionsFunctions (t * testing.T ) {
0 commit comments