@@ -287,6 +287,8 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
287287 loadIndex ("https://dl.espressif.com/dl/package_esp32_index.json" )
288288 loadIndex ("http://arduino.esp8266.com/stable/package_esp8266com_index.json" )
289289 loadIndex ("https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" )
290+ loadIndex ("https://test.com/package_test_index.json" )
291+
290292 // We ignore the errors returned since they might not be necessarily blocking
291293 // but just warnings for the user, like in the case a board is not loaded
292294 // because of malformed menus
@@ -310,8 +312,13 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
310312 })
311313 require .NotNil (t , esptool0413 )
312314
315+ testPlatform := pme .FindPlatformRelease (& packagemanager.PlatformReference {
316+ Package : "test" ,
317+ PlatformArchitecture : "avr" ,
318+ PlatformVersion : semver .MustParse ("1.1.0" )})
319+
313320 testConflictingToolsInDifferentPackages := func () {
314- tools , err := pme .FindToolsRequiredForBoard (esp32 )
321+ tools , err := pme .FindToolsRequiredForBuild (esp32 . PlatformRelease , nil )
315322 require .NoError (t , err )
316323 require .Contains (t , tools , esptool231 )
317324 require .NotContains (t , tools , esptool0413 )
@@ -331,10 +338,44 @@ func TestFindToolsRequiredForBoard(t *testing.T) {
331338 testConflictingToolsInDifferentPackages ()
332339 testConflictingToolsInDifferentPackages ()
333340
341+ {
342+ // Test buildPlatform dependencies
343+ arduinoBossac180 := pme .FindToolDependency (& cores.ToolDependency {
344+ ToolPackager : "arduino" ,
345+ ToolName : "bossac" ,
346+ ToolVersion : semver .ParseRelaxed ("1.8.0-48-gb176eee" ),
347+ })
348+ require .NotNil (t , arduinoBossac180 )
349+ testBossac175 := pme .FindToolDependency (& cores.ToolDependency {
350+ ToolPackager : "test" ,
351+ ToolName : "bossac" ,
352+ ToolVersion : semver .ParseRelaxed ("1.7.5" ),
353+ })
354+ require .NotNil (t , testBossac175 )
355+
356+ tools , err := pme .FindToolsRequiredForBuild (esp32 .PlatformRelease , nil )
357+ require .NoError (t , err )
358+ require .Contains (t , tools , esptool231 )
359+ require .NotContains (t , tools , esptool0413 )
360+ // When building without testPlatform dependency, arduino:bossac should be selected
361+ // since it has the higher version
362+ require .NotContains (t , tools , testBossac175 )
363+ require .Contains (t , tools , arduinoBossac180 )
364+
365+ tools , err = pme .FindToolsRequiredForBuild (esp32 .PlatformRelease , testPlatform )
366+ require .NoError (t , err )
367+ require .Contains (t , tools , esptool231 )
368+ require .NotContains (t , tools , esptool0413 )
369+ // When building with testPlatform dependency, test:bossac should be selected
370+ // because it has dependency priority
371+ require .Contains (t , tools , testBossac175 )
372+ require .NotContains (t , tools , arduinoBossac180 )
373+ }
374+
334375 feather , err := pme .FindBoardWithFQBN ("adafruit:samd:adafruit_feather_m0_express" )
335376 require .NoError (t , err )
336377 require .NotNil (t , feather )
337- featherTools , err := pme .FindToolsRequiredForBoard (feather )
378+ featherTools , err := pme .FindToolsRequiredForBuild (feather . PlatformRelease , nil )
338379 require .NoError (t , err )
339380 require .NotNil (t , featherTools )
340381
0 commit comments