@@ -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 ())
309307 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 ))
308+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
309+ require .NoError (t , err )
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 ) {
@@ -338,30 +382,31 @@ func TestProfileLibSpecificProfile(t *testing.T) {
338382 _ , _ , err := cli .Run ("core" , "update-index" )
339383 require .NoError (t , err )
340384
341- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
385+ sk := cli .SketchbookDir ().Join ("Simple" )
386+ _ , _ , err = cli .Run ("sketch" , "new" , sk .String ())
342387 require .NoError (t , err )
343388
344389 _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
345390 require .NoError (t , err )
346391
347- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
392+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
348393 require .NoError (t , err )
349394
350395 // Add a second profile
351- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
396+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
352397 require .NoError (t , err )
353398
354399 // Add library to a specific profile
355- _ , _ , err = cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "-m" , "my_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ). String () )
400+ _ , _ , err = cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "-m" , "my_profile" , "--dest-dir" , sk . String (), "--no-deps" )
356401 require .NoError (t , err )
357- fileContent , err := cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFile ()
402+ fileContent , err := sk . Join ("sketch.yaml" ).ReadFile ()
358403 require .NoError (t , err )
359404 require .Contains (t , string (fileContent ), " my_profile:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.5.0)\n " )
360405
361406 // Remove library from a specific profile
362- _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "-m" , "my_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ) .String ())
407+ _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "-m" , "my_profile" , "--dest-dir" , sk .String ())
363408 require .NoError (t , err )
364- fileContent , err = cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFile ()
409+ fileContent , err = sk . Join ("sketch.yaml" ).ReadFile ()
365410 require .NoError (t , err )
366411 require .NotContains (t , string (fileContent ), "- Modulino (0.5.0)" )
367412}
@@ -374,33 +419,34 @@ func TestProfileSetDefault(t *testing.T) {
374419 _ , _ , err := cli .Run ("core" , "update-index" )
375420 require .NoError (t , err )
376421
377- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
422+ sk := cli .SketchbookDir ().Join ("Simple" )
423+ _ , _ , err = cli .Run ("sketch" , "new" , sk .String ())
378424 require .NoError (t , err )
379425
380426 _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
381427 require .NoError (t , err )
382428
383- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
429+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
384430 require .NoError (t , err )
385431
386432 // Add a second profile
387- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
433+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
388434 require .NoError (t , err )
389- fileContent , err := cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
435+ fileContent , err := sk . Join ("sketch.yaml" ).ReadFileAsLines ()
390436 require .NoError (t , err )
391437 require .Contains (t , fileContent , "default_profile: Uno" )
392438 require .NotContains (t , fileContent , "default_profile: my_profile" )
393439
394440 // Change default profile
395- _ , _ , err = cli .Run ("profile" , "set-default" , "my_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ) .String ())
441+ _ , _ , err = cli .Run ("profile" , "set-default" , "my_profile" , "--dest-dir" , sk .String ())
396442 require .NoError (t , err )
397- fileContent , err = cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
443+ fileContent , err = sk . Join ("sketch.yaml" ).ReadFileAsLines ()
398444 require .NoError (t , err )
399445 require .NotContains (t , fileContent , "default_profile: Uno" )
400446 require .Contains (t , fileContent , "default_profile: my_profile" )
401447
402448 // Changing to an inexistent profile returns an error
403- _ , stderr , err := cli .Run ("profile" , "set-default" , "inexistent_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ) .String ())
449+ _ , stderr , err := cli .Run ("profile" , "set-default" , "inexistent_profile" , "--dest-dir" , sk .String ())
404450 require .Error (t , err )
405451 require .Equal (t , "Cannot set inexistent_profile as default profile: Profile 'inexistent_profile' not found\n " , string (stderr ))
406452}
0 commit comments