@@ -34,6 +34,7 @@ import (
34
34
"fmt"
35
35
"io/ioutil"
36
36
"os"
37
+ "strings"
37
38
"testing"
38
39
39
40
"github.com/arduino/go-paths-helper"
@@ -281,6 +282,38 @@ func updateCoreIndex(t *testing.T) {
281
282
require .Equal (t , 0 , exitCode , "exit code" )
282
283
}
283
284
285
+ func detectLatestAVRCore (t * testing.T ) string {
286
+ jsonFile := paths .New (os .Getenv ("ARDUINO_DATA_DIR" )).Join ("package_index.json" )
287
+ type index struct {
288
+ Packages []struct {
289
+ Name string
290
+ Platforms []struct {
291
+ Architecture string
292
+ Version string
293
+ }
294
+ }
295
+ }
296
+ var jsonIndex index
297
+ jsonData , err := jsonFile .ReadFile ()
298
+ require .NoError (t , err , "reading package_index.json" )
299
+ err = json .Unmarshal (jsonData , & jsonIndex )
300
+ require .NoError (t , err , "parsing package_index.json" )
301
+ latest := ""
302
+ for _ , p := range jsonIndex .Packages {
303
+ if p .Name == "arduino" {
304
+ for _ , pl := range p .Platforms {
305
+ if pl .Architecture == "avr" && pl .Version > latest {
306
+ latest = pl .Version
307
+ }
308
+ }
309
+ break
310
+ }
311
+ }
312
+ require .NotEmpty (t , latest , "latest avr core version" )
313
+ fmt .Println ("Latest AVR core version:" , latest )
314
+ return latest
315
+ }
316
+
284
317
func TestCoreDownload (t * testing.T ) {
285
318
defer makeTempDataDir (t )()
286
319
defer makeTempSketchbookDir (t )()
@@ -291,14 +324,22 @@ func TestCoreDownload(t *testing.T) {
291
324
defer os .RemoveAll (tmp )
292
325
293
326
updateCoreIndex (t )
294
-
327
+ AVR := "arduino:avr@" + detectLatestAVRCore (t )
328
+ return
329
+ // Download a specific core version
295
330
exitCode ,
d := executeWithArgs (
t ,
"core" ,
"download" ,
"arduino:[email protected] " )
296
331
require .Zero (t , exitCode , "exit code" )
297
332
require .
Contains (
t ,
string (
d ),
"arduino:[email protected] downloaded" )
298
333
require .
Contains (
t ,
string (
d ),
"arduino:[email protected] downloaded" )
299
334
require .
Contains (
t ,
string (
d ),
"arduino:[email protected] downloaded" )
300
335
require .
Contains (
t ,
string (
d ),
"arduino:[email protected] downloaded" )
301
336
337
+ // Download latest
338
+ exitCode , d = executeWithArgs (t , "core" , "download" , "arduino:avr" )
339
+ require .Zero (t , exitCode , "exit code" )
340
+ require .Contains (t , string (d ), AVR + " downloaded" )
341
+
342
+ // Wrong downloads
302
343
exitCode ,
d = executeWithArgs (
t ,
"core" ,
"download" ,
"arduino:[email protected] " )
303
344
require .NotZero (t , exitCode , "exit code" )
304
345
require .Contains (t , string (d ), "required version 1.2.3-notexisting not found for platform arduino:samd" )
@@ -310,4 +351,15 @@ func TestCoreDownload(t *testing.T) {
310
351
exitCode , d = executeWithArgs (t , "core" , "download" , "wrongparameter" )
311
352
require .NotZero (t , exitCode , "exit code" )
312
353
require .Contains (t , string (d ), "invalid item" )
354
+
355
+ // Empty cores list
356
+ exitCode , d = executeWithArgs (t , "core" , "download" , "wrongparameter" )
357
+ require .NotZero (t , exitCode , "exit code" )
358
+ require .Empty (t , strings .TrimSpace (string (d )))
359
+
360
+ // Install avr
361
+ exitCode , d = executeWithArgs (t , "core" , "install" , "arduino:avr" )
362
+ require .Zero (t , exitCode , "exit code" )
363
+ require .
Contains (
t ,
string (
d ),
"arduino:[email protected] downloaded" )
364
+
313
365
}
0 commit comments