@@ -310,3 +310,369 @@ func TestUpgradeLibraryWithDependencies(t *testing.T) {
310
310
dependency := jsonOut .Query (`.dependencies[] | select(.name=="MKRWAN")` )
311
311
require .Equal (t , dependency .Query (".version_required" ), dependency .Query (".version_installed" ))
312
312
}
313
+
314
+ func TestList (t * testing.T ) {
315
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
316
+ defer env .CleanUp ()
317
+
318
+ // Init the environment explicitly
319
+ _ , _ , err := cli .Run ("core" , "update-index" )
320
+ require .NoError (t , err )
321
+
322
+ // When output is empty, nothing is printed out, no matter the output format
323
+ stdout , stderr , err := cli .Run ("lib" , "list" )
324
+ require .NoError (t , err )
325
+ require .Empty (t , stderr )
326
+ require .Contains (t , string (stdout ), "No libraries installed." )
327
+ stdout , stderr , err = cli .Run ("lib" , "list" , "--format" , "json" )
328
+ require .NoError (t , err )
329
+ require .Empty (t , stderr )
330
+ requirejson .Empty (t , stdout )
331
+
332
+ // Install something we can list at a version older than latest
333
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
334
+ require .NoError (t , err )
335
+
336
+ // Look at the plain text output
337
+ stdout , stderr , err = cli .Run ("lib" , "list" )
338
+ require .NoError (t , err )
339
+ require .Empty (t , stderr )
340
+ lines := strings .Split (strings .TrimSpace (string (stdout )), "\n " )
341
+ require .Len (t , lines , 2 )
342
+ lines [1 ] = strings .Join (strings .Fields (lines [1 ]), " " )
343
+ toks := strings .SplitN (lines [1 ], " " , 5 )
344
+ // Verifies the expected number of field
345
+ require .Len (t , toks , 5 )
346
+ // be sure line contain the current version AND the available version
347
+ require .NotEmpty (t , toks [1 ])
348
+ require .NotEmpty (t , toks [2 ])
349
+ // Verifies library sentence
350
+ require .Contains (t , toks [4 ], "An efficient and elegant JSON library..." )
351
+
352
+ // Look at the JSON output
353
+ stdout , stderr , err = cli .Run ("lib" , "list" , "--format" , "json" )
354
+ require .NoError (t , err )
355
+ require .Empty (t , stderr )
356
+ requirejson .Len (t , stdout , 1 )
357
+ // be sure data contains the available version
358
+ requirejson .Query (t , stdout , `.[0] | .release | .version != ""` , "true" )
359
+
360
+ // Install something we can list without provides_includes field given in library.properties
361
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
362
+ require .NoError (t , err )
363
+ // Look at the JSON output
364
+ stdout , stderr , err = cli .Run ("lib" , "list" , "Arduino_APDS9960" , "--format" , "json" )
365
+ require .NoError (t , err )
366
+ require .Empty (t , stderr )
367
+ requirejson .Len (t , stdout , 1 )
368
+ // be sure data contains the correct provides_includes field
369
+ requirejson .Query (t , stdout , ".[0] | .library | .provides_includes | .[0]" , `"Arduino_APDS9960.h"` )
370
+ }
371
+
372
+ func TestListExitCode (t * testing.T ) {
373
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
374
+ defer env .CleanUp ()
375
+
376
+ // Init the environment explicitly
377
+ _ , _ , err := cli .Run ("core" , "update-index" )
378
+ require .NoError (t , err )
379
+
380
+ _ , _ , err = cli .Run ("core" , "list" )
381
+ require .NoError (t , err )
382
+
383
+ // Verifies lib list doesn't fail when platform is not specified
384
+ _ , stderr , err := cli .Run ("lib" , "list" )
385
+ require .NoError (t , err )
386
+ require .Empty (t , stderr )
387
+
388
+ // Verify lib list command fails because specified platform is not installed
389
+ _ , stderr , err = cli .Run ("lib" , "list" , "-b" , "arduino:samd:mkr1000" )
390
+ require .Error (t , err )
391
+ require .Contains (t , string (stderr ), "Error listing Libraries: Unknown FQBN: platform arduino:samd is not installed" )
392
+
393
+ _ , _ , err = cli .Run ("lib" , "install" , "AllThingsTalk LoRaWAN SDK" )
394
+ require .NoError (t , err )
395
+
396
+ // Verifies lib list command keeps failing
397
+ _ , stderr , err = cli .Run ("lib" , "list" , "-b" , "arduino:samd:mkr1000" )
398
+ require .Error (t , err )
399
+ require .Contains (t , string (stderr ), "Error listing Libraries: Unknown FQBN: platform arduino:samd is not installed" )
400
+
401
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:samd" )
402
+ require .NoError (t , err )
403
+
404
+ // Verifies lib list command now works since platform has been installed
405
+ _ , stderr , err = cli .Run ("lib" , "list" , "-b" , "arduino:samd:mkr1000" )
406
+ require .NoError (t , err )
407
+ require .Empty (t , stderr )
408
+ }
409
+
410
+ func TestListWithFqbn (t * testing.T ) {
411
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
412
+ defer env .CleanUp ()
413
+
414
+ // Init the environment explicitly
415
+ _ , _ , err := cli .Run ("core" , "update-index" )
416
+ require .NoError (t , err )
417
+
418
+ // Install core
419
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
420
+ require .NoError (t , err )
421
+
422
+ // Look at the plain text output
423
+ _ , _ , err = cli .Run ("lib" , "install" , "ArduinoJson" )
424
+ require .NoError (t , err )
425
+ _ , _ , err = cli .Run ("lib" , "install" , "wm8978-esp32" )
426
+ require .NoError (t , err )
427
+
428
+ // Look at the plain text output
429
+ stdout , stderr , err := cli .Run ("lib" , "list" , "-b" , "arduino:avr:uno" )
430
+ require .NoError (t , err )
431
+ require .Empty (t , stderr )
432
+ lines := strings .Split (strings .TrimSpace (string (stdout )), "\n " )
433
+ require .Len (t , lines , 2 )
434
+
435
+ // Verifies library is compatible
436
+ lines [1 ] = strings .Join (strings .Fields (lines [1 ]), " " )
437
+ toks := strings .SplitN (lines [1 ], " " , 5 )
438
+ require .Len (t , toks , 5 )
439
+ require .Equal (t , "ArduinoJson" , toks [0 ])
440
+
441
+ // Look at the JSON output
442
+ stdout , stderr , err = cli .Run ("lib" , "list" , "-b" , "arduino:avr:uno" , "--format" , "json" )
443
+ require .NoError (t , err )
444
+ require .Empty (t , stderr )
445
+ requirejson .Len (t , stdout , 1 )
446
+
447
+ // Verifies library is compatible
448
+ requirejson .Query (t , stdout , `.[0] | .library | .name` , `"ArduinoJson"` )
449
+ requirejson .Query (t , stdout , `.[0] | .library | .compatible_with | ."arduino:avr:uno"` , `true` )
450
+ }
451
+
452
+ func TestListProvidesIncludesFallback (t * testing.T ) {
453
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
454
+ defer env .CleanUp ()
455
+
456
+ // Verifies "provides_includes" field is returned even if libraries don't declare
457
+ // the "includes" property in their "library.properties" file
458
+ _ , _ , err := cli .Run ("update" )
459
+ require .NoError (t , err )
460
+
461
+ // Install core
462
+ _ ,
_ ,
err = cli .
Run (
"core" ,
"install" ,
"arduino:[email protected] " )
463
+ require .NoError (t , err )
464
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
465
+ require .NoError (t , err )
466
+
467
+ // List all libraries, even the ones installed with the above core
468
+ stdout , stderr , err := cli .Run ("lib" , "list" , "--all" , "--fqbn" , "arduino:avr:uno" , "--format" , "json" )
469
+ require .NoError (t , err )
470
+ require .Empty (t , stderr )
471
+
472
+ requirejson .Len (t , stdout , 6 )
473
+
474
+ requirejson .Query (t , stdout , "[.[] | .library | { (.name): .provides_includes }] | add" ,
475
+ `{
476
+ "SPI": [
477
+ "SPI.h"
478
+ ],
479
+ "SoftwareSerial": [
480
+ "SoftwareSerial.h"
481
+ ],
482
+ "Wire": [
483
+ "Wire.h"
484
+ ],
485
+ "ArduinoJson": [
486
+ "ArduinoJson.h",
487
+ "ArduinoJson.hpp"
488
+ ],
489
+ "EEPROM": [
490
+ "EEPROM.h"
491
+ ],
492
+ "HID": [
493
+ "HID.h"
494
+ ]
495
+ }` )
496
+ }
497
+
498
+ func TestLibDownload (t * testing.T ) {
499
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
500
+ defer env .CleanUp ()
501
+
502
+ // Download a specific lib version
503
+ _ ,
_ ,
err := cli .
Run (
"lib" ,
"download" ,
"[email protected] " )
504
+ require .NoError (t , err )
505
+ require .FileExists (t , cli .DownloadDir ().Join ("libraries" , "AudioZero-1.0.0.zip" ).String ())
506
+
507
+ // Wrong lib version
508
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"download" ,
"[email protected] " )
509
+ require .Error (t , err )
510
+
511
+ // Wrong lib
512
+ _ , _ , err = cli .Run ("lib" , "download" , "AudioZ" )
513
+ require .Error (t , err )
514
+ }
515
+
516
+ func TestInstall (t * testing.T ) {
517
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
518
+ defer env .CleanUp ()
519
+
520
+ libs := []string {"Arduino_BQ24195" , "CMMC MQTT Connector" , "WiFiNINA" }
521
+ // Should be safe to run install multiple times
522
+ _ , _ , err := cli .Run ("lib" , "install" , libs [0 ], libs [1 ], libs [2 ])
523
+ require .NoError (t , err )
524
+ _ , _ , err = cli .Run ("lib" , "install" , libs [0 ], libs [1 ], libs [2 ])
525
+ require .NoError (t , err )
526
+
527
+ // Test failing-install of library with wrong dependency
528
+ // (https://github.com/arduino/arduino-cli/issues/534)
529
+ _ ,
stderr ,
err := cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
530
+ require .Error (t , err )
531
+ require .Contains (t , string (stderr ), "No valid dependencies solution found: dependency 'MD_MAX72xx' is not available" )
532
+ }
533
+
534
+ func TestInstallLibraryWithDependencies (t * testing.T ) {
535
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
536
+ defer env .CleanUp ()
537
+
538
+ _ , _ , err := cli .Run ("update" )
539
+ require .NoError (t , err )
540
+
541
+ // Verifies libraries are not installed
542
+ stdout , _ , err := cli .Run ("lib" , "list" , "--format" , "json" )
543
+ require .NoError (t , err )
544
+ requirejson .Empty (t , stdout )
545
+
546
+ // Install library
547
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
548
+ require .NoError (t , err )
549
+
550
+ // Verifies library's dependencies are correctly installed
551
+ stdout , _ , err = cli .Run ("lib" , "list" , "--format" , "json" )
552
+ require .NoError (t , err )
553
+ requirejson .Query (t , stdout , `[ .[] | .library | .name ] | sort` , `["MD_MAX72XX","MD_Parola"]` )
554
+
555
+ // Try upgrading with --no-overwrite (should fail) and without --no-overwrite (should succeed)
556
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " ,
"--no-overwrite" )
557
+ require .Error (t , err )
558
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
559
+ require .NoError (t , err )
560
+
561
+ // Test --no-overwrite with transitive dependencies
562
+ _ , _ , err = cli .Run ("lib" , "install" , "SD" )
563
+ require .NoError (t , err )
564
+ _ , _ , err = cli .Run ("lib" , "install" , "Arduino_Builtin" , "--no-overwrite" )
565
+ require .NoError (t , err )
566
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " )
567
+ require .NoError (t , err )
568
+ _ , _ , err = cli .Run ("lib" , "install" , "Arduino_Builtin" , "--no-overwrite" )
569
+ require .Error (t , err )
570
+ }
571
+
572
+ func TestInstallNoDeps (t * testing.T ) {
573
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
574
+ defer env .CleanUp ()
575
+
576
+ _ , _ , err := cli .Run ("update" )
577
+ require .NoError (t , err )
578
+
579
+ // Verifies libraries are not installed
580
+ stdout , _ , err := cli .Run ("lib" , "list" , "--format" , "json" )
581
+ require .NoError (t , err )
582
+ requirejson .Empty (t , stdout )
583
+
584
+ // Install library skipping dependencies installation
585
+ _ ,
_ ,
err = cli .
Run (
"lib" ,
"install" ,
"[email protected] " ,
"--no-deps" )
586
+ require .NoError (t , err )
587
+
588
+ // Verifies library's dependencies are not installed
589
+ stdout , _ , err = cli .Run ("lib" , "list" , "--format" , "json" )
590
+ require .NoError (t , err )
591
+ requirejson .Query (t , stdout , `.[] | .library | .name` , `"MD_Parola"` )
592
+ }
593
+
594
+ func TestInstallWithGitUrl (t * testing.T ) {
595
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
596
+ defer env .CleanUp ()
597
+
598
+ // Initialize configs to enable --git-url flag
599
+ envVar := cli .GetDefaultEnv ()
600
+ envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
601
+ _ , _ , err := cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
602
+ require .NoError (t , err )
603
+
604
+ libInstallDir := cli .SketchbookDir ().Join ("libraries" , "WiFi101" )
605
+ // Verifies library is not already installed
606
+ require .NoDirExists (t , libInstallDir .String ())
607
+
608
+ gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
609
+
610
+ // Test git-url library install
611
+ stdout , _ , err := cli .Run ("lib" , "install" , "--git-url" , gitUrl )
612
+ require .NoError (t , err )
613
+ require .Contains (t , string (stdout ), "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." )
614
+
615
+ // Verifies library is installed in expected path
616
+ require .DirExists (t , libInstallDir .String ())
617
+
618
+ // Reinstall library
619
+ _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl )
620
+ require .NoError (t , err )
621
+
622
+ // Verifies library remains installed
623
+ require .DirExists (t , libInstallDir .String ())
624
+ }
625
+
626
+ func TestInstallWithGitUrlFragmentAsBranch (t * testing.T ) {
627
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
628
+ defer env .CleanUp ()
629
+
630
+ // Initialize configs to enable --git-url flag
631
+ envVar := cli .GetDefaultEnv ()
632
+ envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
633
+ _ , _ , err := cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
634
+ require .NoError (t , err )
635
+
636
+ libInstallDir := cli .SketchbookDir ().Join ("libraries" , "WiFi101" )
637
+ // Verifies library is not already installed
638
+ require .NoDirExists (t , libInstallDir .String ())
639
+
640
+ gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
641
+
642
+ // Test that a bad ref fails
643
+ _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#x-ref-does-not-exist" )
644
+ require .Error (t , err )
645
+
646
+ // Verifies library is installed in expected path
647
+ _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#0.16.0" )
648
+ require .NoError (t , err )
649
+ require .DirExists (t , libInstallDir .String ())
650
+
651
+ // Reinstall library at an existing ref
652
+ _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#master" )
653
+ require .NoError (t , err )
654
+
655
+ // Verifies library remains installed
656
+ require .DirExists (t , libInstallDir .String ())
657
+ }
658
+
659
+ func TestUpdateIndex (t * testing.T ) {
660
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
661
+ defer env .CleanUp ()
662
+
663
+ stdout , _ , err := cli .Run ("lib" , "update-index" )
664
+ require .NoError (t , err )
665
+ require .Contains (t , string (stdout ), "Downloading index: library_index.tar.bz2 downloaded" )
666
+ }
667
+
668
+ func TestUninstall (t * testing.T ) {
669
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
670
+ defer env .CleanUp ()
671
+
672
+ libs := []string {"Arduino_BQ24195" , "WiFiNINA" }
673
+ _ , _ , err := cli .Run ("lib" , "install" , libs [0 ], libs [1 ])
674
+ require .NoError (t , err )
675
+
676
+ _ , _ , err = cli .Run ("lib" , "uninstall" , libs [0 ], libs [1 ])
677
+ require .NoError (t , err )
678
+ }
0 commit comments