@@ -640,3 +640,76 @@ func TestCoreSearchSortedResults(t *testing.T) {
640
640
"[.[] | .name |=ascii_downcase | .name]" ).String ()
641
641
require .True (t , strings .HasSuffix (platform , strings .TrimLeft (notSortedDeprecated , "[" )))
642
642
}
643
+
644
+ func TestCoreListSortedResults (t * testing.T ) {
645
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
646
+ defer env .CleanUp ()
647
+
648
+ // Set up the server to serve our custom index file
649
+ testIndex := paths .New (".." , "testdata" , "test_index.json" )
650
+ url := env .HTTPServeFile (8000 , testIndex )
651
+
652
+ // update custom index
653
+ _ , _ , err := cli .Run ("core" , "update-index" , "--additional-urls=" + url .String ())
654
+ require .NoError (t , err )
655
+
656
+ // install some core for testing
657
+ _ , _ , err = cli .Run ("core" , "install" , "test:x86" , "Retrokits-RK002:arm" , "Package:x86" , "--additional-urls=" + url .String ())
658
+ require .NoError (t , err )
659
+
660
+ // list all with additional url specified
661
+ stdout , _ , err := cli .Run ("core" , "list" , "--additional-urls=" + url .String ())
662
+ require .NoError (t , err )
663
+
664
+ out := strings .Split (strings .TrimSpace (string (stdout )), "\n " )
665
+ var lines , deprecated , notDeprecated [][]string
666
+ for i , v := range out {
667
+ if i > 0 {
668
+ v = strings .Join (strings .Fields (v ), " " )
669
+ lines = append (lines , strings .SplitN (v , " " , 4 ))
670
+ }
671
+ }
672
+ require .Len (t , lines , 3 )
673
+ for _ , v := range lines {
674
+ if strings .HasPrefix (v [3 ], "[DEPRECATED]" ) {
675
+ deprecated = append (deprecated , v )
676
+ } else {
677
+ notDeprecated = append (notDeprecated , v )
678
+ }
679
+ }
680
+
681
+ // verify that results are already sorted correctly
682
+ require .True (t , sort .SliceIsSorted (deprecated , func (i , j int ) bool {
683
+ return strings .ToLower (deprecated [i ][3 ]) < strings .ToLower (deprecated [j ][3 ])
684
+ }))
685
+ require .True (t , sort .SliceIsSorted (notDeprecated , func (i , j int ) bool {
686
+ return strings .ToLower (notDeprecated [i ][3 ]) < strings .ToLower (notDeprecated [j ][3 ])
687
+ }))
688
+
689
+ // verify that deprecated platforms are the last ones
690
+ require .Equal (t , lines , append (notDeprecated , deprecated ... ))
691
+
692
+ // test same behaviour with json output
693
+ stdout , _ , err = cli .Run ("core" , "list" , "--additional-urls=" + url .String (), "--format=json" )
694
+ require .NoError (t , err )
695
+ requirejson .Len (t , stdout , 3 )
696
+
697
+ // verify that results are already sorted correctly
698
+ sortedDeprecated := requirejson .Parse (t , stdout ).Query (
699
+ "[ .[] | select(.deprecated == true) | .name |=ascii_downcase | .name ] | sort" ).String ()
700
+ notSortedDeprecated := requirejson .Parse (t , stdout ).Query (
701
+ "[.[] | select(.deprecated == true) | .name |=ascii_downcase | .name]" ).String ()
702
+ require .Equal (t , sortedDeprecated , notSortedDeprecated )
703
+
704
+ sortedNotDeprecated := requirejson .Parse (t , stdout ).Query (
705
+ "[ .[] | select(.deprecated != true) | .name |=ascii_downcase | .name ] | sort" ).String ()
706
+ notSortedNotDeprecated := requirejson .Parse (t , stdout ).Query (
707
+ "[.[] | select(.deprecated != true) | .name |=ascii_downcase | .name]" ).String ()
708
+ require .Equal (t , sortedNotDeprecated , notSortedNotDeprecated )
709
+
710
+ // verify that deprecated platforms are the last ones
711
+ platform := requirejson .Parse (t , stdout ).Query (
712
+ "[.[] | .name |=ascii_downcase | .name]" ).String ()
713
+ require .True (t , strings .HasSuffix (platform , strings .TrimLeft (notSortedDeprecated , "[" )))
714
+
715
+ }
0 commit comments