@@ -309,3 +309,175 @@ default_profile: test
309309` )
310310}
311311}
312+
313+ func TestProfileLibRemoveWithDeps (t * testing.T ) {
314+ env ,cli := integrationtest .CreateEnvForDaemon (t )
315+ t .Cleanup (env .CleanUp )
316+
317+ _ ,_ ,err := cli .Run ("core" ,"update-index" )
318+ require .NoError (t ,err )
319+ _ ,_ ,err = cli .Run ("core" ,"install" ,"arduino:avr" )
320+ require .NoError (t ,err )
321+
322+ tmp ,err := paths .MkTempDir ("" ,"" )
323+ require .NoError (t ,err )
324+ t .Cleanup (func () {tmp .RemoveAll () })
325+ sk := tmp .Join ("sketch" )
326+
327+ // Create a new sketch
328+ _ ,_ ,err = cli .Run ("sketch" ,"new" ,sk .String ())
329+ require .NoError (t ,err )
330+
331+ grpcInst := cli .Create ()
332+ require .NoError (t ,grpcInst .Init ("" ,"" ,func (ir * commands.InitResponse ) {
333+ fmt .Printf ("INIT> %v\n " ,ir .GetMessage ())
334+ }))
335+
336+ // Create a new profile
337+ resp ,err := grpcInst .ProfileCreate (t .Context (),"test" ,sk .String (),"arduino:avr:uno" ,true )
338+ require .NoError (t ,err )
339+ projectFile := paths .New (resp .GetProjectFilePath ())
340+
341+ expect := func (expected string ) {
342+ p ,_ := projectFile .ReadFile ()
343+ require .Equal (t ,strings .TrimSpace (expected ),strings .TrimSpace (string (p )))
344+ }
345+ expect (`
346+ profiles:
347+ test:
348+ fqbn: arduino:avr:uno
349+ platforms:
350+ - platform: arduino:avr (1.8.6)
351+
352+ default_profile: test
353+ ` )
354+
355+ // Add a library to the profile
356+ {
357+ addresp ,err := grpcInst .ProfileLibAdd (t .Context (),sk .String (),"test" ,indexLib ("Arduino_RouterBridge" ,"0.2.2" ),true ,false )
358+ require .NoError (t ,err )
359+ require .Equal (t ,indexLibArray (
360+ indexLib ("Arduino_RPClite" ,"0.2.0" ,true ),
361+ indexLib ("Arduino_RouterBridge" ,"0.2.2" ),
362+ indexLib ("ArxContainer" ,"0.7.0" ,true ),
363+ indexLib ("ArxTypeTraits" ,"0.3.2" ,true ),
364+ indexLib ("DebugLog" ,"0.8.4" ,true ),
365+ indexLib ("MsgPack" ,"0.4.2" ,true ),
366+ ),addresp .GetAddedLibraries ())
367+ expect (`
368+ profiles:
369+ test:
370+ fqbn: arduino:avr:uno
371+ platforms:
372+ - platform: arduino:avr (1.8.6)
373+ libraries:
374+ - dependency: Arduino_RPClite (0.2.0)
375+ - Arduino_RouterBridge (0.2.2)
376+ - dependency: ArxContainer (0.7.0)
377+ - dependency: ArxTypeTraits (0.3.2)
378+ - dependency: DebugLog (0.8.4)
379+ - dependency: MsgPack (0.4.2)
380+
381+ default_profile: test
382+ ` )
383+ }
384+
385+ // Remove the library (without indicating the version) and the dependencies
386+ {
387+ remresp ,err := grpcInst .ProfileLibRemove (t .Context (),sk .String (),"test" ,indexLib ("Arduino_RouterBridge" ,"" ),true )
388+ require .NoError (t ,err )
389+ require .Equal (t ,indexLibArray (
390+ indexLib ("Arduino_RouterBridge" ,"0.2.2" ),
391+ indexLib ("Arduino_RPClite" ,"0.2.0" ,true ),
392+ indexLib ("ArxContainer" ,"0.7.0" ,true ),
393+ indexLib ("ArxTypeTraits" ,"0.3.2" ,true ),
394+ indexLib ("DebugLog" ,"0.8.4" ,true ),
395+ indexLib ("MsgPack" ,"0.4.2" ,true ),
396+ ),remresp .GetRemovedLibraries ())
397+ expect (`
398+ profiles:
399+ test:
400+ fqbn: arduino:avr:uno
401+ platforms:
402+ - platform: arduino:avr (1.8.6)
403+
404+ default_profile: test
405+ ` )
406+ }
407+
408+ // Re-add the library to the profile
409+ {
410+ addresp ,err := grpcInst .ProfileLibAdd (t .Context (),sk .String (),"test" ,indexLib ("Arduino_RouterBridge" ,"0.2.2" ),true ,false )
411+ require .NoError (t ,err )
412+ require .Equal (t ,indexLibArray (
413+ indexLib ("Arduino_RPClite" ,"0.2.0" ,true ),
414+ indexLib ("Arduino_RouterBridge" ,"0.2.2" ),
415+ indexLib ("ArxContainer" ,"0.7.0" ,true ),
416+ indexLib ("ArxTypeTraits" ,"0.3.2" ,true ),
417+ indexLib ("DebugLog" ,"0.8.4" ,true ),
418+ indexLib ("MsgPack" ,"0.4.2" ,true ),
419+ ),addresp .GetAddedLibraries ())
420+ expect (`
421+ profiles:
422+ test:
423+ fqbn: arduino:avr:uno
424+ platforms:
425+ - platform: arduino:avr (1.8.6)
426+ libraries:
427+ - dependency: Arduino_RPClite (0.2.0)
428+ - Arduino_RouterBridge (0.2.2)
429+ - dependency: ArxContainer (0.7.0)
430+ - dependency: ArxTypeTraits (0.3.2)
431+ - dependency: DebugLog (0.8.4)
432+ - dependency: MsgPack (0.4.2)
433+
434+ default_profile: test
435+ ` )
436+ }
437+
438+ // Remove one dep library (without indicating the version)
439+ {
440+ _ ,err := grpcInst .ProfileLibRemove (t .Context (),sk .String (),"test" ,indexLib ("Arduino_RPClite" ,"" ),true )
441+ require .NoError (t ,err )
442+ // require.Equal(t, indexLibArray(
443+ // indexLib("Arduino_RPClite", "0.2.0", true),
444+ // ), remresp.GetRemovedLibraries())
445+ expect (`
446+ profiles:
447+ test:
448+ fqbn: arduino:avr:uno
449+ platforms:
450+ - platform: arduino:avr (1.8.6)
451+ libraries:
452+ - Arduino_RouterBridge (0.2.2)
453+ - dependency: ArxContainer (0.7.0)
454+ - dependency: ArxTypeTraits (0.3.2)
455+ - dependency: DebugLog (0.8.4)
456+ - dependency: MsgPack (0.4.2)
457+
458+ default_profile: test
459+ ` )
460+ }
461+
462+ // Remove the library (without indicating the version) and all the dependencies
463+ {
464+ remresp ,err := grpcInst .ProfileLibRemove (t .Context (),sk .String (),"test" ,indexLib ("Arduino_RouterBridge" ,"" ),true )
465+ require .NoError (t ,err )
466+ require .Equal (t ,indexLibArray (
467+ indexLib ("Arduino_RouterBridge" ,"0.2.2" ),
468+ indexLib ("ArxContainer" ,"0.7.0" ,true ),
469+ indexLib ("ArxTypeTraits" ,"0.3.2" ,true ),
470+ indexLib ("DebugLog" ,"0.8.4" ,true ),
471+ indexLib ("MsgPack" ,"0.4.2" ,true ),
472+ ),remresp .GetRemovedLibraries ())
473+ expect (`
474+ profiles:
475+ test:
476+ fqbn: arduino:avr:uno
477+ platforms:
478+ - platform: arduino:avr (1.8.6)
479+
480+ default_profile: test
481+ ` )
482+ }
483+ }