@@ -534,3 +534,51 @@ func TestCoreInstallRemovesUnusedTools(t *testing.T) {
534534 // Verifies tool is uninstalled since it's not used by newer core version
535535 require .NoDirExists (t , toolPath .String ())
536536}
537+
538+ func TestCoreListWithInstalledJson (t * testing.T ) {
539+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
540+ defer env .CleanUp ()
541+
542+ _ , _ , err := cli .Run ("update" )
543+ require .NoError (t , err )
544+
545+ // Install core
546+ url := "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
547+ _ , _ , err = cli .Run ("core" , "update-index" , "--additional-urls=" + url )
548+ require .NoError (t , err )
549+ _ , _ , err = cli .Run ("core" , "install" , "adafruit:avr@1.4.13" , "--additional-urls=" + url )
550+ require .NoError (t , err )
551+
552+ // Verifies installed core is correctly found and name is set
553+ stdout , _ , err := cli .Run ("core" , "list" , "--format" , "json" )
554+ require .NoError (t , err )
555+ requirejson .Len (t , stdout , 1 )
556+ requirejson .Contains (t , stdout , `[
557+ {
558+ "id": "adafruit:avr",
559+ "name": "Adafruit AVR Boards"
560+ }
561+ ]` )
562+
563+ // Deletes installed.json file, this file stores information about the core,
564+ // that is used mostly when removing package indexes and their cores are still installed;
565+ // this way we don't lose much information about it.
566+ // It might happen that the user has old cores installed before the addition of
567+ // the installed.json file so we need to handle those cases.
568+ installedJson := cli .DataDir ().Join ("packages" , "adafruit" , "hardware" , "avr" , "1.4.13" , "installed.json" )
569+ require .NoError (t , installedJson .Remove ())
570+
571+ // Verifies installed core is still found and name is set
572+ stdout , _ , err = cli .Run ("core" , "list" , "--format" , "json" )
573+ require .NoError (t , err )
574+ requirejson .Len (t , stdout , 1 )
575+ // Name for this core changes since if there's installed.json file we read it from
576+ // platform.txt, turns out that this core has different names used in different files
577+ // thus the change.
578+ requirejson .Contains (t , stdout , `[
579+ {
580+ "id": "adafruit:avr",
581+ "name": "Adafruit Boards"
582+ }
583+ ]` )
584+ }
0 commit comments