@@ -20,6 +20,7 @@ import (
20
20
"encoding/hex"
21
21
"fmt"
22
22
"os"
23
+ "path/filepath"
23
24
"runtime"
24
25
"sort"
25
26
"strconv"
@@ -518,6 +519,60 @@ func TestCoreListAllManuallyInstalledCore(t *testing.T) {
518
519
]}` )
519
520
}
520
521
522
+ func TestCoreListShowsLatestVersionWhenMultipleReleasesOfAManuallyInstalledCoreArePresent (t * testing.T ) {
523
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
524
+ defer env .CleanUp ()
525
+
526
+ _ , _ , err := cli .Run ("core" , "update-index" )
527
+ require .NoError (t , err )
528
+
529
+ // Verifies only cores in board manager are shown
530
+ stdout , _ , err := cli .Run ("core" , "list" , "--all" , "--format" , "json" )
531
+ require .NoError (t , err )
532
+ requirejson .Query (t , stdout , `.platforms | length > 0` , `true` )
533
+ length , err := strconv .Atoi (requirejson .Parse (t , stdout ).Query (".platforms | length" ).String ())
534
+ require .NoError (t , err )
535
+
536
+ // Manually installs a core in sketchbooks hardware folder
537
+ gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
538
+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
539
+ _ , err = git .PlainClone (filepath .Join (repoDir .String (), "1.8.3" ), false , & git.CloneOptions {
540
+ URL : gitUrl ,
541
+ ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
542
+ })
543
+ require .NoError (t , err )
544
+
545
+ tmp := paths .New (t .TempDir (), "1.8.4" )
546
+ _ , err = git .PlainClone (tmp .String (), false , & git.CloneOptions {
547
+ URL : gitUrl ,
548
+ ReferenceName : plumbing .NewTagReferenceName ("1.8.4" ),
549
+ })
550
+ require .NoError (t , err )
551
+
552
+ err = tmp .Rename (repoDir .Join ("1.8.4" ))
553
+ require .NoError (t , err )
554
+
555
+ // When manually installing 2 releases of the same core, the newest one takes precedence
556
+ stdout , _ , err = cli .Run ("core" , "list" , "--all" , "--format" , "json" )
557
+ require .NoError (t , err )
558
+ requirejson .Query (t , stdout , `.platforms | length` , fmt .Sprint (length + 1 ))
559
+ requirejson .Contains (t , stdout , `{"platforms":[
560
+ {
561
+ "id": "arduino-beta-development:avr",
562
+ "latest_version": "1.8.4",
563
+ "installed_version": "1.8.4",
564
+ "releases": {
565
+ "1.8.3": {
566
+ "name": "Arduino AVR Boards"
567
+ },
568
+ "1.8.3": {
569
+ "name": "Arduino AVR Boards"
570
+ }
571
+ }
572
+ }
573
+ ]}` )
574
+ }
575
+
521
576
func TestCoreListUpdatableAllFlags (t * testing.T ) {
522
577
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
523
578
defer env .CleanUp ()
0 commit comments