@@ -272,15 +272,9 @@ func TestProfileLib(t *testing.T) {
272272 _ , _ , err := cli .Run ("core" , "update-index" )
273273 require .NoError (t , err )
274274
275- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
276- require .NoError (t , err )
277-
278275 _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
279276 require .NoError (t , err )
280277
281- _ , _ , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
282- require .NoError (t , err )
283-
284278 integrationtest.CLISubtests {
285279 {"AddLibToDefaultProfile" , addLibToDefaultProfile },
286280 {"ChangeLibVersionDefaultProfile" , changeLibVersionDefaultProfile },
@@ -291,43 +285,93 @@ func TestProfileLib(t *testing.T) {
291285}
292286
293287func addLibToDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
294- _ , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
288+ sk := cli .SketchbookDir ().Join ("addLibToDefaultProfile" )
289+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
295290 require .NoError (t , err )
296- fileContent , err : = cli .SketchbookDir (). Join ( "Simple " , "sketch.yaml" ). ReadFile ( )
291+ _ , _ , err = cli .Run ( "profile " , "init" , sk . String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
297292 require .NoError (t , err )
298- require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.5.0)\n \n default_profile: Uno\n " , string (fileContent ))
299- }
300293
301- func changeLibVersionDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
302- fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
294+ out , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , sk .String (), "--json" )
303295 require .NoError (t , err )
304- require . Equal (t , "profiles: \n Uno: \n fqbn: arduino:avr:uno \n platforms: \n - platform: arduino:avr (1.8.6) \n libraries: \n - Modulino ( 0.5.0) \n \n default_profile: Uno \n " , string ( fileContent ) )
296+ requirejson . Parse (t , out ). Query ( ".added_libraries" ). MustContain ( `[{"name":" Modulino", "version":" 0.5.0"}]` )
305297
306- _ , _ , err = cli . Run ( "profile" , "lib" , "add" , "Modulino@0.4.0" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ). String () )
298+ fileContent , err := sk . Join ( "sketch.yaml" ). ReadFile ( )
307299 require .NoError (t , err )
308- fileContent , err = cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
300+ require .Contains (t , string (fileContent ), " - Modulino (0.5.0)\n " )
301+ require .Contains (t , string (fileContent ), " - Arduino_LSM6DSOX (" ) // dependency added as well
302+ }
303+
304+ func changeLibVersionDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
305+ sk := cli .SketchbookDir ().Join ("changeLibVersionDefaultProfile" )
306+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
307+ require .NoError (t , err )
308+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
309309 require .NoError (t , err )
310- require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.4.0)\n \n default_profile: Uno\n " , string (fileContent ))
310+
311+ {
312+ out , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , sk .String (), "--json" )
313+ outjson := requirejson .Parse (t , out )
314+ outjson .Query (".added_libraries" ).MustContain (`[{"name":"Modulino", "version":"0.5.0"},{"name":"Arduino_LSM6DSOX"}]` )
315+ outjson .Query (".skipped_libraries" ).LengthMustEqualTo (0 )
316+
317+ fileContent , err := sk .Join ("sketch.yaml" ).ReadFile ()
318+ require .NoError (t , err )
319+ require .Contains (t , string (fileContent ), " - Modulino (0.5.0)\n " )
320+ require .Contains (t , string (fileContent ), " - Arduino_LSM6DSOX (" ) // dependency added as well
321+ }
322+
323+ {
324+ out , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.4.0" , "--dest-dir" , sk .String (), "--json" )
325+ require .NoError (t , err )
326+ outjson := requirejson .Parse (t , out )
327+ outjson .Query (".added_libraries" ).MustContain (`[{"name":"Modulino", "version":"0.4.0"}]` )
328+ outjson .Query (".skipped_libraries" ).MustContain (`[{"name":"Arduino_LSM6DSOX"}]` )
329+
330+ fileContent , err := sk .Join ("sketch.yaml" ).ReadFile ()
331+ require .NoError (t , err )
332+ require .Contains (t , string (fileContent ), " - Modulino (0.4.0)\n " )
333+ }
311334}
312335
313336func removeLibFromDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
314- _ , _ , err := cli .Run ("profile" , "lib" , "remove" , "Modulino" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
337+ sk := cli .SketchbookDir ().Join ("removeLibFromDefaultProfile" )
338+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
315339 require .NoError (t , err )
316- fileContent , err : = cli .SketchbookDir (). Join ( "Simple " , "sketch.yaml" ). ReadFile ( )
340+ _ , _ , err = cli .Run ( "profile " , "init" , sk . String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
317341 require .NoError (t , err )
318- require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n \n default_profile: Uno\n " , string (fileContent ))
342+
343+ _ , _ , err = cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , sk .String (), "--json" )
344+ require .NoError (t , err )
345+
346+ _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "--dest-dir" , sk .String ())
347+ require .NoError (t , err )
348+ fileContent , err := sk .Join ("sketch.yaml" ).ReadFile ()
349+ require .NoError (t , err )
350+ require .NotContains (t , string (fileContent ), " - Modulino" )
319351}
320352
321353func addInexistentLibToDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
322- _ , stderr , err := cli .Run ("profile" , "lib" , "add" , "foobar" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
354+ sk := cli .SketchbookDir ().Join ("addInexistentLibToDefaultProfile" )
355+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
356+ require .NoError (t , err )
357+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
358+ require .NoError (t , err )
359+
360+ _ , stderr , err := cli .Run ("profile" , "lib" , "add" , "foobar" , "--dest-dir" , sk .String ())
323361 require .Error (t , err )
324362 require .Equal (t , "Error adding foobar to the profile : Library 'foobar@latest' not found\n " , string (stderr ))
325363}
326364
327365func removeLibNotInDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
328- _ , stderr , err := cli .Run ("profile" , "lib" , "remove" , "Arduino_JSON" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
366+ sk := cli .SketchbookDir ().Join ("removeLibNotInDefaultProfile" )
367+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
368+ require .NoError (t , err )
369+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
370+ require .NoError (t , err )
371+
372+ _ , stderr , err := cli .Run ("profile" , "lib" , "remove" , "Arduino_JSON" , "--dest-dir" , sk .String ())
329373 require .Error (t , err )
330- require .Equal (t , "Error removing Arduino_JSON from the profile : Library 'Arduino_JSON' not found\n " , string (stderr ))
374+ require .Equal (t , "Error removing library Arduino_JSON from the profile: Library 'Arduino_JSON' not found\n " , string (stderr ))
331375}
332376
333377func TestProfileLibSpecificProfile (t * testing.T ) {
0 commit comments